@fluentui-contrib/react-keytips

中文文档
0.4.4发布于 2026/06/03MITTypeScriptESM + CJS近 30 天下载 8843

Installation

原始使用文档
文档目录6 节
  1. Installation
  2. Best practices
  3. Do
  4. Don't
  5. Usage
  6. Manual dispatching of keytip events

@fluentui-contrib/react-keytips

Installation

npm install @fluentui-contrib/react-keytips

or

yarn add @fluentui-contrib/react-keytips

A Keytip is a small popup displayed near a UI component, indicating a key sequence that can be used to navigate and trigger that component. Unlike keyboard shortcuts, Keytips guide users through a sequence of keys to traverse hierarchical levels of the UI.

From a technical perspective, a Keytip is a wrapper around the Tooltip component.

To enable Keytips, include the Keytips component at the root level of your application. Use the useKeytipRef hook to attach a Keytip to a specific target component.

Keytips appear when a user enters a specific set of keys. The entry sequence is Alt-Meta on Windows and Option-Control on macOS. Users can change default hotkey via startSequence property.

returnSequence should be used to navigate back to the previous level of keytips (Esc by default). Pressing Esc (or different hotkey passed to returnSequence) will turn off keytips mode and dismiss them only if it is a root level keytip (one that does not have a parent and is shown first).

Best practices

Do

  • Keytip sequences can be duplicated as long as none of their siblings have the same sequence.

Don't

  • Don't add more than 1 Keytips component per app.
  • Don't attach keytips to components that will make your page scroll. Keytip mode automatically exits on scroll.

Usage

import * as React from 'react';
import { Keytips, useKeytipRef } from '@fluentui-contrib/react-keytips';
import { Button } from '@fluentui/react-components';

export const App = () => {
  const onExecute = (_, ({ targetElement })) => {
    targetElement.click();
  };

  const keytipRefA = useKeytipRef({ keySequences: ['a'], content: 'A', onExecute });
  const keytipRefB = useKeytipRef({ keySequences: ['b'], content: 'B', onExecute });
  const keytipRefC = useKeytipRef({ keySequences: ['c'], content: 'C', onExecute });

  return (
    <>
      {/* Keytips must be added once under the root-most FluentProvider of the app */}
      <Keytips />
      <Button ref={keytipRefA}>Button A</Button>
      <Button ref={keytipRefB}>Button B</Button>
      <Button ref={keytipRefC}>Button C</Button>
    </>
  );
};

Manual dispatching of keytip events

In some cases, you may want to manually trigger keytip events. For example, you might need to programmatically enter or exit keytip mode based on action. The useKeytipsManager hook provides access to dispatch method, allowing you to send keytip events manually.

import * as React from 'react';
import { Button } from '@fluentui/react-components';
import { useKeytipsManager } from '@fluentui-contrib/react-keytips';

export const App = () => {
  const { enterKeytipMode } = useKeytipsManager();

  return (
    <>
      <Button onClick={enterKeytipMode}>Show Keytips</Button>
    </>
  );
};

Follow up on the [Storybook](https://microsoft.github.io/fluentui-contrib/react-keytips) for examples on how to use the components provided by this package.

版本与发布记录

@fluentui-contrib/react-keytips 共发布 18 个版本,首次发布于 2024/10/16;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.4.4latest2026/06/035 个月前
0.4.32026/03/038 个月前
0.4.22025/11/1811 个月前
0.4.12025/10/011.1 年前
0.4.02025/09/231.1 年前
0.3.32025/08/021.3 年前

关于 @fluentui-contrib/react-keytips 的常见问题

@fluentui-contrib/react-keytips 是什么?

Installation

如何安装 @fluentui-contrib/react-keytips?

在项目目录运行 npm install @fluentui-contrib/react-keytips,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0 <20.0.0)、react-dom(>=16.8.0 <20.0.0)、@types/react(>=16.8.0 <20.0.0)、@types/react-dom(>=16.8.0 <20.0.0)、@fluentui/react-components(>=9.70.0 <10.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fluentui-contrib/react-keytips 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fluentui-contrib/react-keytips 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fluentui-contrib/react-keytips 可以商用吗?

@fluentui-contrib/react-keytips 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fluentui-contrib/react-keytips 的下载量有多少?

根据 npm 官方下载统计,@fluentui-contrib/react-keytips 在 2026/10/15 – 2026/11/13 这 30 天内被下载 8,843 次,日均约 295 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fluentui-contrib/react-keytips 还在维护吗?

最新版本 0.4.4 发布于 2026/06/03(5 个月前);至今共发布 18 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/10/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。