# 有序列表 {#ordered-list}

Source: [为 React 编辑器添加有序列表 · Yurich](https://leeyujoo.com/yurich/zh-cn/features/ordered-list/)

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

Package version: `0.1.2`

为有顺序的步骤编号。

## 试一试 {#try-it}

选中两个段落并点击 **有序列表**。将生成包含两个 `<li>` 的 `<ol>`。

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

启用 `OrderedList` 并调用 `toggleOrderedList`。

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

export function OrderedListEditor() {
  const editor = useEditor({
    extensions: [OrderedList],
    initialValue: "<p>安装 Yurich</p><p>给加粗按钮找个位置</p>",
  });
  const active = useIsActive(editor, 'toggleOrderedList');

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

## 行为说明 {#behavior}

只有光标时切换当前项。取消中间一项的格式可能会拆分列表。

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