ナビゲーション

v2.1.0
フォーム

エディター

リッチテキストエディターの枠組み。ツールバー、ドキュメント、それぞれの状態を扱います。

このページの内容

エディターは、リッチテキストフィールドの枠組みです。入力フィールドのウェル、その上部に平らに置いたツールバー、その下のドキュメントで構成します。編集そのもの、つまりドキュメントモデル、選択範囲、履歴、キー操作は、Tiptap や ProseMirror などのエンジンが担当します。エンジンは editor-document を編集可能にし、描画するブロックにエディターのクラスを書き込みます。リッチテキストでは、Tiptap をエディターに組み込む方法を紹介しています。

エディター

<div class="field w-full max-w(560) mx-auto">  <span id="notes-label">Release notes</span>  <div class="editor" style="--editor-rows: 5">    <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="true">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M4.6667 3H8.3333C12.3333 3 12.3333 7.6667 8.3333 7.6667H4.6667M4.6667 3V13H9C13.3333 13 13.3333 7.6667 9 7.6667" />        </svg>      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6.6667 3L12.6667 3" /><path d="M3.3333 13L9.3333 13" /><path d="M9.6667 3L6.3333 13" stroke-linecap="butt" />        </svg>      </button>      <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <circle cx="3" cy="4" r="0.5" fill="currentColor" stroke="none" /><path d="M6 4L13.5 4" /><circle cx="3" cy="8" r="0.5" fill="currentColor" stroke="none" /><path d="M6 8L13.5 8" /><circle cx="3" cy="12" r="0.5" fill="currentColor" stroke="none" /><path d="M6 12L13.5 12" />        </svg>      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M9 4.3333L10 3.3333C11.0125 2.3208 12.6541 2.3208 13.6667 3.3333C14.6792 4.3459 14.6792 5.9875 13.6667 7L11.6667 9C10.6541 10.0125 9.0125 10.0125 8 9" /><path d="M9 4.3333L10 3.3333C11.0125 2.3208 12.6541 2.3208 13.6667 3.3333C14.6792 4.3459 14.6792 5.9875 13.6667 7L11.6667 9C10.6541 10.0125 9.0125 10.0125 8 9" transform="rotate(180 8 8)" />        </svg>      </button>    </div>    <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="notes-label" contenteditable="true">      <h2 class="editor-heading">Version 0.4</h2>      <p class="editor-paragraph">        Category colors arrive: <strong>twenty-three palettes</strong>, each with a surface, a text, a line and a mark.      </p>    </div>  </div></div>
import BoldIcon from '@master/icons-react/native/16/soft/bold'import ItalicIcon from '@master/icons-react/native/16/soft/italic'import ListIcon from '@master/icons-react/native/16/soft/list'import LinkIcon from '@master/icons-react/native/16/soft/link'<div className="field w-full max-w(560) mx-auto">  <span id="notes-label">Release notes</span>  <div className="editor" style={{ '--editor-rows': '5' } as React.CSSProperties}>    <div className="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">      <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="true">        <BoldIcon className="icon" />      </button>      <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false">        <ItalicIcon className="icon" />      </button>      <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span>      <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false">        <ListIcon className="icon" />      </button>      <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false">        <LinkIcon className="icon" />      </button>    </div>    <div className="editor-document" role="textbox" aria-multiline="true" aria-labelledby="notes-label" contentEditable="true">      <h2 className="editor-heading">Version 0.4</h2>      <p className="editor-paragraph">        Category colors arrive: <strong>twenty-three palettes</strong>, each with a surface, a text, a line and a mark.      </p>    </div>  </div></div>
<script>  import BoldIcon from '@master/icons-svelte/native/16/soft/bold'  import ItalicIcon from '@master/icons-svelte/native/16/soft/italic'  import ListIcon from '@master/icons-svelte/native/16/soft/list'  import LinkIcon from '@master/icons-svelte/native/16/soft/link'</script><div class="field w-full max-w(560) mx-auto">  <span id="notes-label">Release notes</span>  <div class="editor" style="--editor-rows: 5">    <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="true">        <BoldIcon class="icon" />      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false">        <ItalicIcon class="icon" />      </button>      <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false">        <ListIcon class="icon" />      </button>      <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false">        <LinkIcon class="icon" />      </button>    </div>    <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="notes-label" contenteditable="true">      <h2 class="editor-heading">Version 0.4</h2>      <p class="editor-paragraph">        Category colors arrive: <strong>twenty-three palettes</strong>, each with a surface, a text, a line and a mark.      </p>    </div>  </div></div>
<script setup>import BoldIcon from '@master/icons-vue/native/16/soft/bold'import ItalicIcon from '@master/icons-vue/native/16/soft/italic'import ListIcon from '@master/icons-vue/native/16/soft/list'import LinkIcon from '@master/icons-vue/native/16/soft/link'</script><template>  <div class="field w-full max-w(560) mx-auto">    <span id="notes-label">Release notes</span>    <div class="editor" style="--editor-rows: 5">      <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="true">          <BoldIcon class="icon" />        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false">          <ItalicIcon class="icon" />        </button>        <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false">          <ListIcon class="icon" />        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false">          <LinkIcon class="icon" />        </button>      </div>      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="notes-label" contenteditable="true">        <h2 class="editor-heading">Version 0.4</h2>        <p class="editor-paragraph">          Category colors arrive: <strong>twenty-three palettes</strong>, each with a surface, a text, a line and a mark.        </p>      </div>    </div>  </div></template>

エンジンがない場合、このプレビューのドキュメントはブラウザー標準の contenteditable です。文字は入力できますが、構造は扱えず、ツールバーも動作しません。

#枠組み

  • フィールドとして振る舞います。 ウェル、ホバー、フォーカス時のハロー、エラー時の危険色の縁、無効時のインク色は入力欄と同じなので、リッチテキストフィールドも周囲のフィールドと同じように見えます。フレームを浮き上がらせるのはドキュメントのフォーカスなので、ツールバー内を移動しても浮き上がりません。
  • ツールバーは帯です。 ツールバーに editor-toolbar を付けると、ウェルの上部に内側の余白 1 つ分だけ内側に平らに配置され、角丸がウェルの角丸の内側に収まり、下に細い罫線が引かれます。エディターの幅が狭いときは折り返します。ツールバーのビヘイビアにより、ツールバー全体が 1 つのタブストップになり、矢印キーで移動できます。
  • ドキュメントは内容に応じて伸びます。 空のときは --editor-rows 行(既定は 6 行)で、--editor-max-rows(既定は 18 行)まで伸び、それを超えるとフレームの中でスクロールします。

#ドキュメントの内容

スタイルシートは要素名で選択することはありません。エンジンが各ブロックにクラスを書き込み、スタイルが付くのはそれらのクラスだけで、しかもエディターの中に限られます。ページ全体のタイポグラフィではありません。

ドキュメントの内容

<div class="editor w-full max-w(560) mx-auto">  <div class="editor-document" role="textbox" aria-multiline="true" aria-label="Document" contenteditable="true">    <h2 class="editor-heading">A heading</h2>    <p class="editor-paragraph">      A paragraph with <a class="editor-link" href="#content">a link</a>, <em>emphasis</em> and <code class="code">inline code</code>.    </p>    <h3 class="editor-subheading">A subheading</h3>    <ul class="editor-list">      <li class="editor-item">        <p class="editor-paragraph">A list with bullets</p>      </li>      <li class="editor-item">        <p class="editor-paragraph">Its markers in the muted ink</p>      </li>    </ul>    <ol class="editor-list editor-list-numbered">      <li class="editor-item">        <p class="editor-paragraph">A list with numbers</p>      </li>      <li class="editor-item">        <p class="editor-paragraph">On an ordered list</p>      </li>    </ol>    <blockquote class="editor-quote">      <p class="editor-paragraph">A quotation, a step quieter.</p>    </blockquote>    <hr class="editor-rule">    <p class="editor-paragraph">And a paragraph after a rule.</p>  </div></div>
<div className="editor w-full max-w(560) mx-auto">  <div className="editor-document" role="textbox" aria-multiline="true" aria-label="Document" contentEditable="true">    <h2 className="editor-heading">A heading</h2>    <p className="editor-paragraph">      A paragraph with <a className="editor-link" href="#content">a link</a>, <em>emphasis</em> and <code className="code">inline code</code>.    </p>    <h3 className="editor-subheading">A subheading</h3>    <ul className="editor-list">      <li className="editor-item">        <p className="editor-paragraph">A list with bullets</p>      </li>      <li className="editor-item">        <p className="editor-paragraph">Its markers in the muted ink</p>      </li>    </ul>    <ol className="editor-list editor-list-numbered">      <li className="editor-item">        <p className="editor-paragraph">A list with numbers</p>      </li>      <li className="editor-item">        <p className="editor-paragraph">On an ordered list</p>      </li>    </ol>    <blockquote className="editor-quote">      <p className="editor-paragraph">A quotation, a step quieter.</p>    </blockquote>    <hr className="editor-rule" />    <p className="editor-paragraph">And a paragraph after a rule.</p>  </div></div>
<div class="editor w-full max-w(560) mx-auto">  <div class="editor-document" role="textbox" aria-multiline="true" aria-label="Document" contenteditable="true">    <h2 class="editor-heading">A heading</h2>    <p class="editor-paragraph">      A paragraph with <a class="editor-link" href="#content">a link</a>, <em>emphasis</em> and <code class="code">inline code</code>.    </p>    <h3 class="editor-subheading">A subheading</h3>    <ul class="editor-list">      <li class="editor-item">        <p class="editor-paragraph">A list with bullets</p>      </li>      <li class="editor-item">        <p class="editor-paragraph">Its markers in the muted ink</p>      </li>    </ul>    <ol class="editor-list editor-list-numbered">      <li class="editor-item">        <p class="editor-paragraph">A list with numbers</p>      </li>      <li class="editor-item">        <p class="editor-paragraph">On an ordered list</p>      </li>    </ol>    <blockquote class="editor-quote">      <p class="editor-paragraph">A quotation, a step quieter.</p>    </blockquote>    <hr class="editor-rule">    <p class="editor-paragraph">And a paragraph after a rule.</p>  </div></div>
<template>  <div class="editor w-full max-w(560) mx-auto">    <div class="editor-document" role="textbox" aria-multiline="true" aria-label="Document" contenteditable="true">      <h2 class="editor-heading">A heading</h2>      <p class="editor-paragraph">        A paragraph with <a class="editor-link" href="#content">a link</a>, <em>emphasis</em> and <code class="code">inline code</code>.      </p>      <h3 class="editor-subheading">A subheading</h3>      <ul class="editor-list">        <li class="editor-item">          <p class="editor-paragraph">A list with bullets</p>        </li>        <li class="editor-item">          <p class="editor-paragraph">Its markers in the muted ink</p>        </li>      </ul>      <ol class="editor-list editor-list-numbered">        <li class="editor-item">          <p class="editor-paragraph">A list with numbers</p>        </li>        <li class="editor-item">          <p class="editor-paragraph">On an ordered list</p>        </li>      </ol>      <blockquote class="editor-quote">        <p class="editor-paragraph">A quotation, a step quieter.</p>      </blockquote>      <hr class="editor-rule">      <p class="editor-paragraph">And a paragraph after a rule.</p>    </div>  </div></template>

#状態

各状態は、エンジンが要素に保持する属性か、ページがフレームに設定する属性で表します。ドキュメントにフォーカスがあるとフレームが浮き上がり、aria-invalid="true" の場合はフレームに危険色の縁が付きます。aria-readonly="true" はフレームを平らにし、キャレットを表示しません。フレームに aria-disabled="true" を付けると、無効時のインク色の平らなウェルになります。無効な内容のドキュメントには、フィールドの field-error を表示します。エディターを無効にするときはツールバーのコントロールも無効にし、エンジンにも編集不可であることを伝えます。

状態

<div class="grid gap-lg w-full max-w(560) mx-auto">  <div class="field">    <span id="state-invalid">Summary</span>    <div class="editor" style="--editor-rows: 2">      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-invalid" aria-describedby="state-invalid-error" aria-invalid="true" contenteditable="true"></div>    </div>    <p class="field-error" id="state-invalid-error">      Write at least a sentence before you publish.    </p>  </div>  <div class="field">    <span id="state-readonly">Published notes</span>    <div class="editor" style="--editor-rows: 2">      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-readonly" aria-readonly="true" contenteditable="false" tabindex="0">        <p class="editor-paragraph">          Version 0.3 shipped tags, editable values and sortable lists.        </p>      </div>    </div>  </div>  <div class="field">    <span id="state-disabled">Draft</span>    <div class="editor" style="--editor-rows: 2" aria-disabled="true">      <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="false" disabled>          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M4.6667 3H8.3333C12.3333 3 12.3333 7.6667 8.3333 7.6667H4.6667M4.6667 3V13H9C13.3333 13 13.3333 7.6667 9 7.6667" />          </svg>        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false" disabled>          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M6.6667 3L12.6667 3" /><path d="M3.3333 13L9.3333 13" /><path d="M9.6667 3L6.3333 13" stroke-linecap="butt" />          </svg>        </button>        <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false" disabled>          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <circle cx="3" cy="4" r="0.5" fill="currentColor" stroke="none" /><path d="M6 4L13.5 4" /><circle cx="3" cy="8" r="0.5" fill="currentColor" stroke="none" /><path d="M6 8L13.5 8" /><circle cx="3" cy="12" r="0.5" fill="currentColor" stroke="none" /><path d="M6 12L13.5 12" />          </svg>        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false" disabled>          <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">            <path d="M9 4.3333L10 3.3333C11.0125 2.3208 12.6541 2.3208 13.6667 3.3333C14.6792 4.3459 14.6792 5.9875 13.6667 7L11.6667 9C10.6541 10.0125 9.0125 10.0125 8 9" /><path d="M9 4.3333L10 3.3333C11.0125 2.3208 12.6541 2.3208 13.6667 3.3333C14.6792 4.3459 14.6792 5.9875 13.6667 7L11.6667 9C10.6541 10.0125 9.0125 10.0125 8 9" transform="rotate(180 8 8)" />          </svg>        </button>      </div>      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-disabled" aria-disabled="true" contenteditable="false">        <p class="editor-paragraph">Locked while the release is reviewed.</p>      </div>    </div>  </div></div>
import BoldIcon from '@master/icons-react/native/16/soft/bold'import ItalicIcon from '@master/icons-react/native/16/soft/italic'import ListIcon from '@master/icons-react/native/16/soft/list'import LinkIcon from '@master/icons-react/native/16/soft/link'<div className="grid gap-lg w-full max-w(560) mx-auto">  <div className="field">    <span id="state-invalid">Summary</span>    <div className="editor" style={{ '--editor-rows': '2' } as React.CSSProperties}>      <div className="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-invalid" aria-describedby="state-invalid-error" aria-invalid="true" contentEditable="true"></div>    </div>    <p className="field-error" id="state-invalid-error">      Write at least a sentence before you publish.    </p>  </div>  <div className="field">    <span id="state-readonly">Published notes</span>    <div className="editor" style={{ '--editor-rows': '2' } as React.CSSProperties}>      <div className="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-readonly" aria-readonly="true" contentEditable="false" tabIndex={0}>        <p className="editor-paragraph">          Version 0.3 shipped tags, editable values and sortable lists.        </p>      </div>    </div>  </div>  <div className="field">    <span id="state-disabled">Draft</span>    <div className="editor" style={{ '--editor-rows': '2' } as React.CSSProperties} aria-disabled="true">      <div className="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">        <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="false" disabled>          <BoldIcon className="icon" />        </button>        <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false" disabled>          <ItalicIcon className="icon" />        </button>        <span className="toolbar-separator" role="separator" aria-orientation="vertical"></span>        <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false" disabled>          <ListIcon className="icon" />        </button>        <button type="button" className="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false" disabled>          <LinkIcon className="icon" />        </button>      </div>      <div className="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-disabled" aria-disabled="true" contentEditable="false">        <p className="editor-paragraph">Locked while the release is reviewed.</p>      </div>    </div>  </div></div>
<script>  import BoldIcon from '@master/icons-svelte/native/16/soft/bold'  import ItalicIcon from '@master/icons-svelte/native/16/soft/italic'  import ListIcon from '@master/icons-svelte/native/16/soft/list'  import LinkIcon from '@master/icons-svelte/native/16/soft/link'</script><div class="grid gap-lg w-full max-w(560) mx-auto">  <div class="field">    <span id="state-invalid">Summary</span>    <div class="editor" style="--editor-rows: 2">      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-invalid" aria-describedby="state-invalid-error" aria-invalid="true" contenteditable="true"></div>    </div>    <p class="field-error" id="state-invalid-error">      Write at least a sentence before you publish.    </p>  </div>  <div class="field">    <span id="state-readonly">Published notes</span>    <div class="editor" style="--editor-rows: 2">      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-readonly" aria-readonly="true" contenteditable="false" tabindex="0">        <p class="editor-paragraph">          Version 0.3 shipped tags, editable values and sortable lists.        </p>      </div>    </div>  </div>  <div class="field">    <span id="state-disabled">Draft</span>    <div class="editor" style="--editor-rows: 2" aria-disabled="true">      <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="false" disabled>          <BoldIcon class="icon" />        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false" disabled>          <ItalicIcon class="icon" />        </button>        <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false" disabled>          <ListIcon class="icon" />        </button>        <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false" disabled>          <LinkIcon class="icon" />        </button>      </div>      <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-disabled" aria-disabled="true" contenteditable="false">        <p class="editor-paragraph">Locked while the release is reviewed.</p>      </div>    </div>  </div></div>
<script setup>import BoldIcon from '@master/icons-vue/native/16/soft/bold'import ItalicIcon from '@master/icons-vue/native/16/soft/italic'import ListIcon from '@master/icons-vue/native/16/soft/list'import LinkIcon from '@master/icons-vue/native/16/soft/link'</script><template>  <div class="grid gap-lg w-full max-w(560) mx-auto">    <div class="field">      <span id="state-invalid">Summary</span>      <div class="editor" style="--editor-rows: 2">        <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-invalid" aria-describedby="state-invalid-error" aria-invalid="true" contenteditable="true"></div>      </div>      <p class="field-error" id="state-invalid-error">        Write at least a sentence before you publish.      </p>    </div>    <div class="field">      <span id="state-readonly">Published notes</span>      <div class="editor" style="--editor-rows: 2">        <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-readonly" aria-readonly="true" contenteditable="false" tabindex="0">          <p class="editor-paragraph">            Version 0.3 shipped tags, editable values and sortable lists.          </p>        </div>      </div>    </div>    <div class="field">      <span id="state-disabled">Draft</span>      <div class="editor" style="--editor-rows: 2" aria-disabled="true">        <div class="toolbar editor-toolbar" role="toolbar" aria-label="Formatting">          <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bold" aria-pressed="false" disabled>            <BoldIcon class="icon" />          </button>          <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Italic" aria-pressed="false" disabled>            <ItalicIcon class="icon" />          </button>          <span class="toolbar-separator" role="separator" aria-orientation="vertical"></span>          <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Bulleted list" aria-pressed="false" disabled>            <ListIcon class="icon" />          </button>          <button type="button" class="btn btn-quiet btn-sm btn-square" aria-label="Link" aria-pressed="false" disabled>            <LinkIcon class="icon" />          </button>        </div>        <div class="editor-document" role="textbox" aria-multiline="true" aria-labelledby="state-disabled" aria-disabled="true" contenteditable="false">          <p class="editor-paragraph">Locked while the release is reviewed.</p>        </div>      </div>    </div>  </div></template>

#アクセシビリティ

  • ドキュメントは aria-multiline="true" を指定した role="textbox" です。aria-labelledby でフィールドのラベルを名前として参照し、aria-describedby でヒントとエラーを説明として参照します。<label for> はフォームコントロール以外の要素に名前を付けられません。
  • ツールバーは名前を付けた 1 つのタブストップで、aria-controls でドキュメントを参照します。アイコンボタンにはすべて名前を付け、切り替えボタンには aria-pressed を指定し、エンジンが処理するショートカットを aria-keyshortcuts に指定します。
  • ツールバーのコマンドを実行した後は、読み手が書いていたドキュメントにフォーカスを戻します。
  • ドキュメントに独自のキーハンドラーを追加しないでください。単語を変換中の入力メソッドは Enter キーや矢印キーを使い、エンジンはそれがいつ起きているかを把握しています。
  • 強制カラーモードでは、フレームの輪郭はフィールドの色で描画され、フォーカス中はハイライト色になります。

#クラス

クラス説明
editorツールバーの帯とドキュメントを収める、くぼんだフィールドのフレームです。ドキュメントにフォーカスが当たると浮き上がります。
editor-toolbar枠組みの上部のツールバーに付けます。内側の余白 1 つ分だけ内側に平らに配置され、下に細い罫線が引かれます。エディターの幅が狭いときは折り返します
editor-documentエンジンが編集可能にする要素。--editor-rows 行から --editor-max-rows 行まで伸び、それを超えるとスクロールします。aria-labelledby で名前を付け、フィールドのヒントで説明します
editor-paragraphドキュメントの段落
editor-headingドキュメントの見出し。h2、またはエンジンが書き出すレベルの要素に付けます
editor-subheadingeditor-heading より 1 段下の見出し
editor-list箇条書きのリスト。マーカーは控えめなインク色で、項目内のリストは白丸になります
editor-list-numberedol に付け、箇条書きの代わりに番号を付けますeditor-list と併用します
editor-itemリストの項目
editor-quoteblockquote に付ける引用。先頭に罫線が付き、文字は一段控えめになります
editor-linkドキュメント内のリンク。線のインク色で下線が付きます
editor-ruleドキュメントの区切りに入れる水平線

#カスタムプロパティ

プロパティ既定値説明
--editor-rows6ドキュメントが空のときに表示する行数
--editor-max-rows18スクロールが始まるまでに伸びる行数

#ソース

@master/ui/components/editor.css
/* * Editor: the frame of a rich text editor. The editing itself (the document, the selection, the history, the * keys) belongs to an engine such as Tiptap or ProseMirror; this is what every such editor shares in Master UI. * * It is a field: the well of an input, with the input's hover, focus halo, invalid edge and disabled ink, but * the focus is the document's, not the frame's. A toolbar (editor-toolbar on a toolbar) stands in the top of the * well as a band of quiet controls, parted from the document by a hairline, its corner nested in the well's. The * document (editor-document, the element the engine makes editable) grows from --editor-rows lines to * --editor-max-rows, then scrolls. * * What the document holds is styled through classes the engine is told to write on its nodes, never by element: * editor-paragraph, editor-heading, editor-subheading, editor-list (editor-list-numbered), editor-quote, * editor-link and editor-rule; inline code is a code and a block of code a code-block. Nothing here reaches * outside the editor, so it is not a typography for a page. */@layer components.ui {  .editor {    --editor-rows: 6;    --editor-max-rows: 18;    --editor-padding-x: .875rem;    --editor-padding-y: .625rem;    --editor-radius: var(--radius-control-lg);    --editor-inset: 4px;    --editor-line: 1.6;    display: flex;    flex-direction: column;    min-width: 0;    border-radius: calc(var(--editor-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-inset);    color: var(--color-text-strong);    box-shadow: var(--shadow-pressed);    font: 400 .875rem/var(--editor-line) var(--font-family-sans);    font-feature-settings: inherit;    text-align: start;    transition-property: box-shadow, background-color;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    @media (hover: hover) {      &:hover:not(:has(.editor-document:focus), [aria-disabled="true"], :has(.editor-document[aria-readonly="true"])) {        background: var(--color-surface-inset-hover);      }    }    /*     * Read only: the words can be read and copied, not changed, so the well rests flat and the caret is gone.     * It comes before focus, so a reader who tabs into it still sees where the keys are, as on a read-only input.     */    &:has(.editor-document[aria-readonly="true"]) {      background: transparent;      box-shadow: var(--shadow-flat);      .editor-document {        caret-color: transparent;      }      /* Nothing is edited here, so a link is followed: it takes the hand, not the text cursor. */      .editor-link {        cursor: pointer;      }    }    /* The document has focus: the frame rises to a raised face with the field's halo, as an input does. */    &:has(.editor-document:focus) {      background: var(--color-surface-raised);      box-shadow: inset 0 0 0 .5px var(--color-line-mark), 0 0 0 .5px var(--color-line-mark), 0 0 0 3.5px var(--color-focus-halo);    }    /* An error keeps its edge while focused, and the halo takes the danger tone. */    &:has(.editor-document[aria-invalid="true"]) {      box-shadow: var(--shadow-pressed), inset 0 0 0 .5px var(--color-danger), 0 0 0 .5px color-mix(in oklab, var(--color-danger) 45%, transparent);      &:has(.editor-document:focus) {        box-shadow: inset 0 0 0 .5px var(--color-danger), 0 0 0 .5px var(--color-danger), 0 0 0 3.5px color-mix(in oklab, var(--color-danger) 15%, transparent);      }    }    /* Disabled: the frame keeps its well, as a disabled input does, takes disabled ink, and nothing in it answers the pointer. */    &[aria-disabled="true"] {      color: var(--color-text-disabled);      cursor: not-allowed;      .editor-document {        pointer-events: none;      }    }    @media (forced-colors: active) {      outline: 1px solid FieldText;      outline-offset: -1px;      &:has(.editor-document:focus) {        outline: 2px solid Highlight;        outline-offset: -2px;      }      &:has(.editor-document[aria-invalid="true"]) {        outline-color: Mark;      }      &[aria-disabled="true"] {        outline-color: GrayText;        color: GrayText;      }    }  }  /*   * The toolbar band: a toolbar laid flat in the top of the well, one inset in, so its corner nests in the   * well's. A hairline parts it from the document. It wraps on a narrow editor rather than scrolling away.   */  .editor-toolbar {    display: flex;    flex-wrap: wrap;    max-width: none;    margin: 0;    padding: var(--editor-inset);    border-radius: calc(var(--editor-radius) * var(--corner-scale)) calc(var(--editor-radius) * var(--corner-scale)) 0 0;    background: transparent;    box-shadow: 0 1px 0 var(--color-line-hair);    .editor[aria-disabled="true"] & {      opacity: .5;    }    /* The hairline is a shadow, which forced colors drop: a border draws it, and the margin gives its pixel back. */    @media (forced-colors: active) {      outline: none;      margin-block-end: -1px;      border-block-end: 1px solid GrayText;    }  }  /*   * The document: the element the engine makes editable. It grows with what it holds, from --editor-rows lines to   * --editor-max-rows, then scrolls. Its own focus ring is the frame's halo.   */  .editor-document {    flex: 1 1 auto;    min-height: calc(var(--editor-rows) * var(--editor-line) * 1em + 2 * var(--editor-padding-y));    max-height: calc(var(--editor-max-rows) * var(--editor-line) * 1em + 2 * var(--editor-padding-y));    padding: var(--editor-padding-y) var(--editor-padding-x);    overflow: auto;    overflow-wrap: anywhere;    outline: none;    caret-color: var(--color-text-strong);    scrollbar-width: thin;    scrollbar-color: var(--color-line-strong) transparent;    /* Scrolled to its end, the document does not hand the scroll on to the page. */    overscroll-behavior: contain;  }  .editor-paragraph {    margin: 0 0 .75em;  }  .editor-heading, .editor-subheading {    margin: 1.25em 0 .5em;    color: var(--color-text-strong);    font-weight: 600;    letter-spacing: -.01em;    text-wrap: balance;  }  .editor-heading {    font-size: 1.375em;    line-height: 1.3;  }  .editor-subheading {    font-size: 1.125em;    line-height: 1.4;  }  /* A list: bullets, or numbers with editor-list-numbered, in the muted ink so the words lead. */  .editor-list {    margin: 0 0 .75em;    padding-inline-start: 1.5em;    list-style: disc;    &::marker {      color: var(--color-text-muted);    }    &.editor-list-numbered {      list-style: decimal;    }    /* A list inside a list: bullets turn to circles; a numbered one keeps its numbers. */    .editor-list {      margin-block: .25em 0;      &:not(.editor-list-numbered) {        list-style: circle;      }    }  }  .editor-item {    padding-inline-start: .25em;    &::marker {      color: var(--color-text-muted);      font-variant-numeric: tabular-nums;    }    .editor-paragraph {      margin-block-end: .25em;    }  }  /* A quotation: a rule of ink at its start, its words a step quieter. */  .editor-quote {    margin: 0 0 .75em;    padding-inline-start: 1em;    color: var(--color-text-body);    box-shadow: inset 2px 0 0 var(--color-line-strong);    &:dir(rtl) {      box-shadow: inset -2px 0 0 var(--color-line-strong);    }    .editor-paragraph:last-child {      margin-block-end: 0;    }    /* The rule is a shadow, which forced colors drop: a border draws it, taken out of the indent so the words stay put. */    @media (forced-colors: active) {      padding-inline-start: calc(1em - 2px);      border-inline-start: 2px solid CanvasText;      box-shadow: none;    }  }  .editor-link {    color: inherit;    text-decoration-line: underline;    text-decoration-color: var(--color-line-mark);    text-decoration-thickness: 1px;    text-underline-offset: .2em;    cursor: text;    @media (forced-colors: active) {      color: LinkText;    }  }  /* The first and the last block keep no margin of their own, so the padding is the only space at either end. */  :is(.editor-heading, .editor-subheading, .editor-rule):first-child {    margin-block-start: 0;  }  :is(.editor-paragraph, .editor-heading, .editor-subheading, .editor-list, .editor-quote, .editor-rule):last-child {    margin-block-end: 0;  }  .editor-rule {    height: 1px;    margin: 1.25em 0;    border: 0;    background: var(--color-line-divider);    /* Forced colors repaint the background as the canvas; a system color keeps the rule. */    @media (forced-colors: active) {      background: CanvasText;    }  }}