# @accessible/button 中文文档

规范地址：https://npmcn.com/package/%40accessible/button/

版本：2\.0\.2
npm 元数据更新时间：2022-04-04T11:07:06.081Z
中文译文更新时间：2026-11-06T03:03:21.563Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40accessible/button
原文对照：https://npmcn.com/package/%40accessible/button/?lang=original
项目主页：https://github.com/accessible-ui/button#readme
源码仓库：https://github.com/accessible-ui/button

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：77.4 kB，22 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：react \>=16\.8
- 首次发布：2019-12-28T20:22:51.868Z
- 最新版本发布：2020-08-10T21:42:33.241Z
- 近 30 天下载量：5964（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 0 个）

## 中文简介

React的可访问按钮组件,提供真实元素和假元素之间的接口,例如.

## 安装

```sh
npm install @accessible/button
```

也可以使用：`pnpm add @accessible/button`、`yarn add @accessible/button`、`bun add @accessible/button`

## README

* * *

# 按钮

 [![Bundlephobia](https://img.shields.io/bundlephobia/minzip/@accessible/button?style=for-the-badge&labelColor=24292e)](https://bundlephobia.com/result?p=@accessible/button)[![Types](https://img.shields.io/npm/types/@accessible/button?style=for-the-badge&labelColor=24292e) ](https://www.npmjs.com/package/@accessible/button)[![Code coverage](https://img.shields.io/codecov/c/gh/accessible-ui/button?style=for-the-badge&labelColor=24292e) ](https://codecov.io/gh/accessible-ui/button)[![Build status](https://img.shields.io/travis/accessible-ui/button?style=for-the-badge&labelColor=24292e) ](https://travis-ci.org/accessible-ui/button)[![NPM Version](https://img.shields.io/npm/v/@accessible/button?style=for-the-badge&labelColor=24292e) ](https://www.npmjs.com/package/@accessible/button)[![MIT License](https://img.shields.io/npm/l/@accessible/button?style=for-the-badge&labelColor=24292e)](https://jaredlunde.mit-license.org/)

npm i @accessible/button

* * *

React 的可访问按钮组件, 提供真实之间的接口 `<button>` 元素和假元素,例如:. `<div role='button'>`。 。 。 . 为此,本部分附有: `onClick` 从子组件到键盘的处理器 用于 `space` 财务报告和审定财务报表 `enter`。还添加 `role='button'` 财务报告和审定财务报表 `tabIndex={0}` 属性,尽管 通过向儿童部分提供这些道具,可以推翻这种行为. `<Button><div tabIndex={-1}></Button>`。 。 。 .

## 这为什么存在?

在设计无障碍图书馆时,我们只是不知道我们的用户是否会做正确的事情 即使用 `<button>` 按钮,而不是一个 `<div>`, (中文(简体) ), `<span>`,或 `<a>`。本部分 提供互操作性 `<button>` 元素和那些软扣元素.

## 快速启动

[查看 CodeSandbox 上的例子](https://codesandbox.io/s/accessiblebutton-example-spjh2)

```jsx
import {Button, useA11yButton} from '@accessible/button'

const Component = () => (
  // Adds `space` and `enter` keydown handlers to the div,
  // also adds role='button' and tabIndex='0', both
  // of which can be overridden by providing those
  // props on your <div>
  <Button>
    <div onClick={console.log} />
  </Button>
  // <div role='button' tabindex='0'/>
)

const WithHook = () => {
  const ref = React.useRef(null)
  const a11yProps = useA11yButton(ref, (event) => {
    // This is your `onClick` handler
    console.log('Clicked', event)
  })
  return <button {...a11yProps} ref={ref} />
}
```

## API 密码

### 按钮

#### 道具

| Prop | 类型 | 默认 | 需要吗? | 说明 |
| --- | --- | --- | --- | --- |
| 儿童 | `React.ReactElement` | `undefined` | 对 | 您想要变成一个处理焦点和 `space`, (中文(简体) ), `enter` 键盘下的事件. |

### 使用 A11y 按钮( 目标, 在 Click)

用于在元素中添加a11y属性和按钮/role=按钮间接的回放钩.

```jsx
const Button = () => {
  const ref = React.useRef(null)
  const a11yProps = useA11yButton(ref, (event) => {
    // This is your `onClick` handler
    console.log('Clicked', event)
  })
  return <div {...a11yProps} ref={ref} />
}
```

#### 参数

| 参数 | 类型 | 需要吗? | 说明 |
| --- | --- | --- | --- |
| 目标 | `React.RefObject<T> | T | null` | 对 | 反应 ref 或 HTML 元素 |
| 儿童 | `React.ReactElement` | 对 | 您想要变成一个处理焦点和 `space`, (中文(简体) ), `enter` 键盘下的事件. |

#### 回返

```ts
{
    readonly role: "button";
    readonly tabIndex: 0;
}
```

## 自由主义

麻省理工学院

## 常见问题

### @accessible/button 是什么？

React的可访问按钮组件,提供真实元素和假元素之间的接口,例如\.

### 如何安装 @accessible/button？

在项目目录运行 npm install @accessible/button，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=16\.8）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @accessible/button 支持 TypeScript 吗？

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

### @accessible/button 支持 ESM 还是 CommonJS？

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

### @accessible/button 可以商用吗？

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

### @accessible/button 的下载量有多少？

根据 npm 官方下载统计，@accessible/button 在 2026/10/05 – 2026/11/03 这 30 天内被下载 5,964 次，日均约 199 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @accessible/button 还在维护吗？

最新版本 2\.0\.2 发布于 2020/08/11（6 年前）；至今共发布 10 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/12/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

