# 加粗 {#bold}

Source: [为 React 编辑器添加加粗按钮 · Yurich](https://leeyujoo.com/yurich/zh-cn/features/bold/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

将选中文字加粗。

## 试一试 {#try-it}

选中 “Yurich” 并点击 **加粗**。输出为 `<strong>Yurich</strong>`。再次点击可取消。

## 添加到编辑器 {#setup}

启用 `Bold`，将按钮连接到 `toggleBold`，并用 `useIsActive` 读取状态。

```tsx
import { EditorContent, EditorProvider, Bold, useEditor, useIsActive } from 'yurich';

export function BoldEditor() {
  const editor = useEditor({
    extensions: [Bold],
    initialValue: "<p>给 Yurich 一点强调。</p>",
  });
  const active = useIsActive(editor, 'toggleBold');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleBold')}
      >
        加粗
      </button>
      <EditorContent ariaLabel="编辑器" />
    </EditorProvider>
  );
}
```

## 行为说明 {#behavior}

快捷键为 `Mod+B`。只有光标时不会改变内容。部分加粗的选区会整体变为粗体。

[功能](https://leeyujoo.com/yurich/zh-cn/features/)
