加粗
将选中文字加粗。
试一试
选中 “Yurich” 并点击 加粗。输出为 <strong>Yurich</strong>。再次点击可取消。
交互示例
示例结果
添加到编辑器
启用 Bold,将按钮连接到 toggleBold,并用 useIsActive 读取状态。
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>
);
}
行为说明
快捷键为 Mod+B。只有光标时不会改变内容。部分加粗的选区会整体变为粗体。