コマンドパレット
コマンド一覧の上に検索欄を一つ配置したダイアログ。
このページの内容
コマンドパレットは、検索欄とその下に並ぶコマンド一覧で構成され、ページ内のどこからでもショートカットで開けます。ダイアログをベースに、dialog と同じ要素に command を追加し、その中に command-search の行、リストボックス、必要に応じて command-footer を配置します。ネイティブの <dialog> を使うため、ボタンから command="show-modal" で開けます。背景を暗くするオーバーレイ、フォーカスをダイアログ内に留める処理、Esc で閉じる操作はブラウザーが提供します。
コマンドパレット
<button type="button" class="btn" commandfor="palette" command="show-modal"> Search commands <kbd class="kbd">⌘K</kbd></button><dialog id="palette" class="dialog command" closedby="any" aria-label="Command palette"> <label class="command-search"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" /> </svg> <input class="command-input" id="palette-input" type="search" role="combobox" aria-expanded="true" aria-controls="palette-list" aria-activedescendant="cmd-new" aria-autocomplete="list" aria-label="Search commands" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Type a command or search" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="palette-list" role="listbox" aria-label="Commands"> <div class="listbox-group" role="group" aria-labelledby="group-suggestions"> <div class="listbox-label" id="group-suggestions">Suggestions</div> <div class="listbox-option" role="option" id="cmd-new" aria-selected="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="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> New project <span class="listbox-end"><kbd class="kbd">⌘</kbd><kbd class="kbd">N</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-deploy"> <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="M7.5892 2.215A0.4996 0.4996 0 0 0 7.5 2.5L7.5006 10.0245A0.5 0.5 0 0 0 8.4946 10.0734L8.5 10L8.4986 2.4621A0.5007 0.5007 0 0 0 8.4108 2.215A0.7044 0.7044 0 0 0 7.5892 2.215Z" fill="currentColor" stroke="none" fill-rule="evenodd" /><path d="M5 5.5L7.8586 2.6414A0.2 0.2 0 0 1 8.1414 2.6414L11 5.5" /><path d="M2.5 10.5L2.5 12.5A1 1 0 0 0 3.5 13.5L12.5 13.5A1 1 0 0 0 13.5 12.5L13.5 10.5" /> </svg> Deploy to production </div> <div class="listbox-option" role="option" id="cmd-invite"> <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="6.25" cy="4.5" r="2" /><path d="M2.25 13.75V12.5C2.25 10.7 3.85 9.5 5.35 9.5H7.15C8.65 9.5 10.25 10.7 10.25 12.5V13.75" /><path d="M11 6.3333L14.3333 6.3333" /><path d="M12.6667 4.6667L12.6667 8" /> </svg> Invite a member </div> </div> <div class="listbox-group" role="group" aria-labelledby="group-go"> <div class="listbox-label" id="group-go">Go to</div> <div class="listbox-option" role="option" id="cmd-settings"> <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="M2.5 4.5L4.5 4.5" /><circle cx="6" cy="4.5" r="1.5" /><path d="M7.5 4.5L13.5 4.5" /><path d="M2.5 11.5L8.5 11.5" /><circle cx="10" cy="11.5" r="1.5" /><path d="M11.5 11.5L13.5 11.5" /> </svg> Settings <span class="listbox-end"><kbd class="kbd">G</kbd><kbd class="kbd">S</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-billing"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <rect x="1.6667" y="3.3333" width="12.6667" height="9.3333" rx="1" /><path d="M1.6667 6.6667L14.3333 6.6667" /><path d="M4 10L6.6667 10" /> </svg> Billing </div> </div> <div class="listbox-empty">No commands match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to run</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer></dialog><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-react/native/20/soft/search'import PlusIcon from '@master/icons-react/native/16/soft/plus'import UploadIcon from '@master/icons-react/native/16/soft/upload'import UserPlusIcon from '@master/icons-react/native/16/soft/user-plus'import SlidersIcon from '@master/icons-react/native/16/soft/sliders'import CreditCardIcon from '@master/icons-react/native/16/soft/credit-card'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <button type="button" className="btn" {...{ commandfor: 'palette', command: 'show-modal' }}> Search commands <kbd className="kbd">⌘K</kbd> </button> <dialog id="palette" className="dialog command" closedby="any" aria-label="Command palette"> <label className="command-search"> <SearchIcon className="icon" /> <input className="command-input" id="palette-input" type="search" role="combobox" aria-expanded="true" aria-controls="palette-list" aria-activedescendant="cmd-new" aria-autocomplete="list" aria-label="Search commands" autoComplete="off" spellCheck="false" enterKeyHint="go" placeholder="Type a command or search" autoFocus /> <kbd className="kbd">Esc</kbd> </label> <div className="listbox command-list" id="palette-list" role="listbox" aria-label="Commands"> <div className="listbox-group" role="group" aria-labelledby="group-suggestions"> <div className="listbox-label" id="group-suggestions">Suggestions</div> <div className="listbox-option" role="option" id="cmd-new" aria-selected="true"> <PlusIcon className="icon" /> New project <span className="listbox-end"> <kbd className="kbd">⌘</kbd><kbd className="kbd">N</kbd> </span> </div> <div className="listbox-option" role="option" id="cmd-deploy"> <UploadIcon className="icon" /> Deploy to production </div> <div className="listbox-option" role="option" id="cmd-invite"> <UserPlusIcon className="icon" /> Invite a member </div> </div> <div className="listbox-group" role="group" aria-labelledby="group-go"> <div className="listbox-label" id="group-go">Go to</div> <div className="listbox-option" role="option" id="cmd-settings"> <SlidersIcon className="icon" /> Settings <span className="listbox-end"> <kbd className="kbd">G</kbd><kbd className="kbd">S</kbd> </span> </div> <div className="listbox-option" role="option" id="cmd-billing"> <CreditCardIcon className="icon" /> Billing </div> </div> <div className="listbox-empty">No commands match.</div> </div> <footer className="command-footer"> <span className="command-hint"> <kbd className="kbd">↑</kbd><kbd className="kbd">↓</kbd> to move </span> <span className="command-hint"><kbd className="kbd">↵</kbd> to run</span> <span className="command-hint"><kbd className="kbd">Esc</kbd> to close</span> </footer> </dialog> </div> )}<script> import { attach } from '@master/ui/behaviors' import SearchIcon from '@master/icons-svelte/native/20/soft/search' import PlusIcon from '@master/icons-svelte/native/16/soft/plus' import UploadIcon from '@master/icons-svelte/native/16/soft/upload' import UserPlusIcon from '@master/icons-svelte/native/16/soft/user-plus' import SlidersIcon from '@master/icons-svelte/native/16/soft/sliders' import CreditCardIcon from '@master/icons-svelte/native/16/soft/credit-card'</script><div {@attach attach}> <button type="button" class="btn" commandfor="palette" command="show-modal"> Search commands <kbd class="kbd">⌘K</kbd> </button> <dialog id="palette" class="dialog command" closedby="any" aria-label="Command palette"> <label class="command-search"> <SearchIcon class="icon" /> <input class="command-input" id="palette-input" type="search" role="combobox" aria-expanded="true" aria-controls="palette-list" aria-activedescendant="cmd-new" aria-autocomplete="list" aria-label="Search commands" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Type a command or search" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="palette-list" role="listbox" aria-label="Commands"> <div class="listbox-group" role="group" aria-labelledby="group-suggestions"> <div class="listbox-label" id="group-suggestions">Suggestions</div> <div class="listbox-option" role="option" id="cmd-new" aria-selected="true"> <PlusIcon class="icon" /> New project <span class="listbox-end"><kbd class="kbd">⌘</kbd><kbd class="kbd">N</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-deploy"> <UploadIcon class="icon" /> Deploy to production </div> <div class="listbox-option" role="option" id="cmd-invite"> <UserPlusIcon class="icon" /> Invite a member </div> </div> <div class="listbox-group" role="group" aria-labelledby="group-go"> <div class="listbox-label" id="group-go">Go to</div> <div class="listbox-option" role="option" id="cmd-settings"> <SlidersIcon class="icon" /> Settings <span class="listbox-end"><kbd class="kbd">G</kbd><kbd class="kbd">S</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-billing"> <CreditCardIcon class="icon" /> Billing </div> </div> <div class="listbox-empty">No commands match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to run</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer> </dialog></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-vue/native/20/soft/search'import PlusIcon from '@master/icons-vue/native/16/soft/plus'import UploadIcon from '@master/icons-vue/native/16/soft/upload'import UserPlusIcon from '@master/icons-vue/native/16/soft/user-plus'import SlidersIcon from '@master/icons-vue/native/16/soft/sliders'import CreditCardIcon from '@master/icons-vue/native/16/soft/credit-card'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <button type="button" class="btn" commandfor="palette" command="show-modal"> Search commands <kbd class="kbd">⌘K</kbd> </button> <dialog id="palette" class="dialog command" closedby="any" aria-label="Command palette"> <label class="command-search"> <SearchIcon class="icon" /> <input class="command-input" id="palette-input" type="search" role="combobox" aria-expanded="true" aria-controls="palette-list" aria-activedescendant="cmd-new" aria-autocomplete="list" aria-label="Search commands" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Type a command or search" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="palette-list" role="listbox" aria-label="Commands"> <div class="listbox-group" role="group" aria-labelledby="group-suggestions"> <div class="listbox-label" id="group-suggestions">Suggestions</div> <div class="listbox-option" role="option" id="cmd-new" aria-selected="true"> <PlusIcon class="icon" /> New project <span class="listbox-end"><kbd class="kbd">⌘</kbd><kbd class="kbd">N</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-deploy"> <UploadIcon class="icon" /> Deploy to production </div> <div class="listbox-option" role="option" id="cmd-invite"> <UserPlusIcon class="icon" /> Invite a member </div> </div> <div class="listbox-group" role="group" aria-labelledby="group-go"> <div class="listbox-label" id="group-go">Go to</div> <div class="listbox-option" role="option" id="cmd-settings"> <SlidersIcon class="icon" /> Settings <span class="listbox-end"><kbd class="kbd">G</kbd><kbd class="kbd">S</kbd></span> </div> <div class="listbox-option" role="option" id="cmd-billing"> <CreditCardIcon class="icon" /> Billing </div> </div> <div class="listbox-empty">No commands match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to run</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer> </dialog> </div></template>#構成要素
command-searchは<label>なので、行のどこをクリックしても入力欄にフォーカスが移ります。icon、command-input、必要に応じてヒントを配置します。command-inputはダイアログの背景をそのまま使い、細い罫線で検索結果と区切ります。command-listはリストボックスに指定します。ダイアログの残りの高さを使い、その内側でスクロールします。command-footerにはcommand-hintのグループを配置します。各グループでは、キーをkbdで示し、その後に操作内容を記載します。
パレットはビューポートの上部付近に開き、下方向に伸びます。リストの長さが変わっても、検索欄の位置は変わりません。
#ビヘイビア
ダイアログはスクリプトなしで開閉できます。command ビヘイビアは、パレット固有の操作を追加します。ダイアログを受け取り、ビヘイビアを解除する関数を返します。
import { command } from '@master/ui/behaviors/command.js'command(document.querySelector('.command'))document.getElementById('cmd-new').addEventListener('click', () => { // Create the project.})- ショートカット ドキュメント内のどこからでも、⌘K または Ctrl K でパレットを開閉できます。
- 絞り込み
command-inputに入力すると、一致しない選択肢にhiddenを設定し、最初に一致した選択肢をアクティブにします。リストボックスは、一致するコマンドがなければ自動で空状態用の表示に切り替え、一致するコマンドが一つもないグループを非表示にします。 - アクティブな選択肢 アクティブな選択肢には
aria-selected="true"が付き、検索欄のaria-activedescendantがその選択肢を参照します。矢印キーで切り替えられます。パレットを開いた時点で選択肢が一つアクティブになるため、すぐに Enter で実行できます。 - コマンドの実行 Enter を押すと、アクティブな選択肢がクリックされます。ポインターでクリックしたときと同様に、リンクなら遷移し、選択肢に
clickリスナーがあれば実行されます。ポインターまたは Enter で選択肢をクリックすると、パレットが閉じます。ビヘイビアは独自のイベントを発行せず、clickが実行時のイベントになります。
| オプション | 設定内容 |
|---|---|
shortcut | Command または Control と組み合わせてパレットを開閉するキー。既定は 'k'、無効にする場合は false |
ビヘイビアを適用しなくても、ボタンでダイアログを開き、検索欄に文字を入力し、Esc で閉じることができます。絞り込みと矢印キーによるリスト内の移動には、ビヘイビアが必要です。
#検索結果
ドキュメントを検索するパレットは、名前だけでなく、結果の場所と一致した語句も表示します。これらはリストボックスのパーツなので、コンボボックスも同じ形で結果を並べられ、パレットにクラスを追加する必要はありません。
検索結果
<button type="button" class="btn" commandfor="search" command="show-modal"> Search documentation <kbd class="kbd">⌘K</kbd></button><dialog id="search" class="dialog command" closedby="any" aria-label="Search documentation"> <label class="command-search"> <svg class="icon" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="8.75" cy="8.75" r="5.75" /><path d="M12.8159 12.8159L17.5 17.5" /> </svg> <input class="command-input" type="search" role="combobox" aria-expanded="true" aria-controls="search-list" aria-activedescendant="hit-retune" aria-autocomplete="list" aria-label="Search documentation" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Search documentation" value="token" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="search-list" role="listbox" aria-label="Results"> <div class="listbox-group" role="group" aria-labelledby="search-count"> <div class="listbox-label" id="search-count">4 results</div> <div class="listbox-option" role="option" id="hit-retune" aria-selected="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="M2.5 5.75L13.5 5.75" /><path d="M2.5 10.25L13.5 10.25" /><path d="M6.5 2.5L4.5 13.5" /><path d="M11.5 2.5L9.5 13.5" /> </svg> <span class="listbox-body"> <span>Retune <mark class="mark">token</mark>s</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span><span class="listbox-crumb">Theming</span> </span> <span class="listbox-excerpt"> Override a <mark class="mark">token</mark> after the import. Every component that reads it follows. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theme"> <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.5 2L9.0858 2A1 1 0 0 1 9.7929 2.2929L12.2071 4.7071A1 1 0 0 1 12.5 5.4142L12.5 13A1 1 0 0 1 11.5 14L4.5 14A1 1 0 0 1 3.5 13L3.5 3A1 1 0 0 1 4.5 2Z" /><path d="M10 2.5V4.4A0.1 0.1 0 0 0 10.1 4.5H12L12.2409 4.7427A0.9993 0.9993 0 0 1 12.5 5.4142V5.5H10.1Q9.6444 5.5 9.3222 5.1778Q9 4.8556 9 4.4V2A1.1002 1.1002 0 0 1 9.3761 2.0431A1.0001 1.0001 0 0 1 9.7929 2.2929L10 2.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /> </svg> <span class="listbox-body"> <span>Default theme</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Moonstone and obsidian: the default materials, <mark class="mark">token</mark> roles and implementation values in Master UI. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theming"> <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.5 2L9.0858 2A1 1 0 0 1 9.7929 2.2929L12.2071 4.7071A1 1 0 0 1 12.5 5.4142L12.5 13A1 1 0 0 1 11.5 14L4.5 14A1 1 0 0 1 3.5 13L3.5 3A1 1 0 0 1 4.5 2Z" /><path d="M10 2.5V4.4A0.1 0.1 0 0 0 10.1 4.5H12L12.2409 4.7427A0.9993 0.9993 0 0 1 12.5 5.4142V5.5H10.1Q9.6444 5.5 9.3222 5.1778Q9 4.8556 9 4.4V2A1.1002 1.1002 0 0 1 9.3761 2.0431A1.0001 1.0001 0 0 1 9.7929 2.2929L10 2.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /> </svg> <span class="listbox-body"> <span>Theming</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Override <mark class="mark">token</mark>s, define material recipes and build a theme of your own, with Paper as a working example. </span> </span> </div> <div class="listbox-option" role="option" id="hit-customization"> <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.5 2L9.0858 2A1 1 0 0 1 9.7929 2.2929L12.2071 4.7071A1 1 0 0 1 12.5 5.4142L12.5 13A1 1 0 0 1 11.5 14L4.5 14A1 1 0 0 1 3.5 13L3.5 3A1 1 0 0 1 4.5 2Z" /><path d="M10 2.5V4.4A0.1 0.1 0 0 0 10.1 4.5H12L12.2409 4.7427A0.9993 0.9993 0 0 1 12.5 5.4142V5.5H10.1Q9.6444 5.5 9.3222 5.1778Q9 4.8556 9 4.4V2A1.1002 1.1002 0 0 1 9.3761 2.0431A1.0001 1.0001 0 0 1 9.7929 2.2929L10 2.5Z" fill="currentColor" stroke="none" fill-rule="evenodd" /> </svg> <span class="listbox-body"> <span>Customization</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Choose the right layer for a change: utilities, theme <mark class="mark">token</mark>s, component properties, a theme or owning the source. </span> </span> </div> </div> <div class="listbox-empty">No documents match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to open</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer></dialog><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-react/native/20/soft/search'import HashIcon from '@master/icons-react/native/16/soft/hash'import FileIcon from '@master/icons-react/native/16/soft/file'export function Example() { const root = useRef<HTMLDivElement>(null) useEffect(() => attach(root.current!), []) return ( <div ref={root}> <button type="button" className="btn" {...{ commandfor: 'search', command: 'show-modal' }}> Search documentation <kbd className="kbd">⌘K</kbd> </button> <dialog id="search" className="dialog command" closedby="any" aria-label="Search documentation"> <label className="command-search"> <SearchIcon className="icon" /> <input className="command-input" type="search" role="combobox" aria-expanded="true" aria-controls="search-list" aria-activedescendant="hit-retune" aria-autocomplete="list" aria-label="Search documentation" autoComplete="off" spellCheck="false" enterKeyHint="go" placeholder="Search documentation" defaultValue="token" autoFocus /> <kbd className="kbd">Esc</kbd> </label> <div className="listbox command-list" id="search-list" role="listbox" aria-label="Results"> <div className="listbox-group" role="group" aria-labelledby="search-count"> <div className="listbox-label" id="search-count">4 results</div> <div className="listbox-option" role="option" id="hit-retune" aria-selected="true"> <HashIcon className="icon" /> <span className="listbox-body"> <span>Retune <mark className="mark">token</mark>s</span> <span className="listbox-path"> <span className="listbox-crumb">Guide</span><span className="listbox-crumb">Customizing</span><span className="listbox-crumb">Theming</span> </span> <span className="listbox-excerpt"> Override a <mark className="mark">token</mark> after the import. Every component that reads it follows. </span> </span> </div> <div className="listbox-option" role="option" id="hit-theme"> <FileIcon className="icon" /> <span className="listbox-body"> <span>Default theme</span> <span className="listbox-path"> <span className="listbox-crumb">Guide</span><span className="listbox-crumb">Customizing</span> </span> <span className="listbox-excerpt"> Moonstone and obsidian: the default materials, <mark className="mark">token</mark> roles and implementation values in Master UI. </span> </span> </div> <div className="listbox-option" role="option" id="hit-theming"> <FileIcon className="icon" /> <span className="listbox-body"> <span>Theming</span> <span className="listbox-path"> <span className="listbox-crumb">Guide</span><span className="listbox-crumb">Customizing</span> </span> <span className="listbox-excerpt"> Override <mark className="mark">token</mark>s, define material recipes and build a theme of your own, with Paper as a working example. </span> </span> </div> <div className="listbox-option" role="option" id="hit-customization"> <FileIcon className="icon" /> <span className="listbox-body"> <span>Customization</span> <span className="listbox-path"> <span className="listbox-crumb">Guide</span><span className="listbox-crumb">Customizing</span> </span> <span className="listbox-excerpt"> Choose the right layer for a change: utilities, theme <mark className="mark">token</mark>s, component properties, a theme or owning the source. </span> </span> </div> </div> <div className="listbox-empty">No documents match.</div> </div> <footer className="command-footer"> <span className="command-hint"> <kbd className="kbd">↑</kbd><kbd className="kbd">↓</kbd> to move </span> <span className="command-hint"><kbd className="kbd">↵</kbd> to open</span> <span className="command-hint"><kbd className="kbd">Esc</kbd> to close</span> </footer> </dialog> </div> )}<script> import { attach } from '@master/ui/behaviors' import SearchIcon from '@master/icons-svelte/native/20/soft/search' import HashIcon from '@master/icons-svelte/native/16/soft/hash' import FileIcon from '@master/icons-svelte/native/16/soft/file'</script><div {@attach attach}> <button type="button" class="btn" commandfor="search" command="show-modal"> Search documentation <kbd class="kbd">⌘K</kbd> </button> <dialog id="search" class="dialog command" closedby="any" aria-label="Search documentation"> <label class="command-search"> <SearchIcon class="icon" /> <input class="command-input" type="search" role="combobox" aria-expanded="true" aria-controls="search-list" aria-activedescendant="hit-retune" aria-autocomplete="list" aria-label="Search documentation" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Search documentation" value="token" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="search-list" role="listbox" aria-label="Results"> <div class="listbox-group" role="group" aria-labelledby="search-count"> <div class="listbox-label" id="search-count">4 results</div> <div class="listbox-option" role="option" id="hit-retune" aria-selected="true"> <HashIcon class="icon" /> <span class="listbox-body"> <span>Retune <mark class="mark">token</mark>s</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span><span class="listbox-crumb">Theming</span> </span> <span class="listbox-excerpt"> Override a <mark class="mark">token</mark> after the import. Every component that reads it follows. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theme"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Default theme</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Moonstone and obsidian: the default materials, <mark class="mark">token</mark> roles and implementation values in Master UI. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theming"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Theming</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Override <mark class="mark">token</mark>s, define material recipes and build a theme of your own, with Paper as a working example. </span> </span> </div> <div class="listbox-option" role="option" id="hit-customization"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Customization</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Choose the right layer for a change: utilities, theme <mark class="mark">token</mark>s, component properties, a theme or owning the source. </span> </span> </div> </div> <div class="listbox-empty">No documents match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to open</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer> </dialog></div><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import SearchIcon from '@master/icons-vue/native/20/soft/search'import HashIcon from '@master/icons-vue/native/16/soft/hash'import FileIcon from '@master/icons-vue/native/16/soft/file'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <div ref="root"> <button type="button" class="btn" commandfor="search" command="show-modal"> Search documentation <kbd class="kbd">⌘K</kbd> </button> <dialog id="search" class="dialog command" closedby="any" aria-label="Search documentation"> <label class="command-search"> <SearchIcon class="icon" /> <input class="command-input" type="search" role="combobox" aria-expanded="true" aria-controls="search-list" aria-activedescendant="hit-retune" aria-autocomplete="list" aria-label="Search documentation" autocomplete="off" spellcheck="false" enterkeyhint="go" placeholder="Search documentation" value="token" autofocus> <kbd class="kbd">Esc</kbd> </label> <div class="listbox command-list" id="search-list" role="listbox" aria-label="Results"> <div class="listbox-group" role="group" aria-labelledby="search-count"> <div class="listbox-label" id="search-count">4 results</div> <div class="listbox-option" role="option" id="hit-retune" aria-selected="true"> <HashIcon class="icon" /> <span class="listbox-body"> <span>Retune <mark class="mark">token</mark>s</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span><span class="listbox-crumb">Theming</span> </span> <span class="listbox-excerpt"> Override a <mark class="mark">token</mark> after the import. Every component that reads it follows. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theme"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Default theme</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Moonstone and obsidian: the default materials, <mark class="mark">token</mark> roles and implementation values in Master UI. </span> </span> </div> <div class="listbox-option" role="option" id="hit-theming"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Theming</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Override <mark class="mark">token</mark>s, define material recipes and build a theme of your own, with Paper as a working example. </span> </span> </div> <div class="listbox-option" role="option" id="hit-customization"> <FileIcon class="icon" /> <span class="listbox-body"> <span>Customization</span> <span class="listbox-path"> <span class="listbox-crumb">Guide</span><span class="listbox-crumb">Customizing</span> </span> <span class="listbox-excerpt"> Choose the right layer for a change: utilities, theme <mark class="mark">token</mark>s, component properties, a theme or owning the source. </span> </span> </div> </div> <div class="listbox-empty">No documents match.</div> </div> <footer class="command-footer"> <span class="command-hint"><kbd class="kbd">↑</kbd><kbd class="kbd">↓</kbd> to move</span> <span class="command-hint"><kbd class="kbd">↵</kbd> to open</span> <span class="command-hint"><kbd class="kbd">Esc</kbd> to close</span> </footer> </dialog> </div></template>- アイコンは結果の種類を示します。 ページにはドキュメントのアイコンを、ページ内の見出しにはハッシュ記号を使います。固有のアイコンがない結果にはこの二つのどちらかを使い、タイトルの左端を揃えます。
listbox-pathは結果の場所を示します。 タイトルの下の小さな1行で、階層ごとにlistbox-crumbを置きます。選択肢のターゲットは一つなので、各階層はリンクではありません。つまりパンくずリストではありません。listbox-excerptは一致した箇所の抜粋で、最大2行です。抜粋があると、アイコンは行の中央ではなくタイトルの横に並びます。- 一致箇所には
markを使います。 選択肢の中ではタイトルの文字色になるため、淡い色の行の中でも見つけられます。入力された語句だけをマークし、行内のほかの部分はマークしません。
#キーボード操作
| キー | 操作 |
|---|---|
| Meta+K, Control+K | ビヘイビア使用時は、どこからでもパレットを開き、すでに開いていれば閉じる |
| Typing | ビヘイビア使用時は、一致しない選択肢を非表示にし、最初に一致した選択肢をアクティブにする |
| ArrowDown, ArrowUp | ビヘイビア使用時は、無効な選択肢を飛ばしてアクティブな選択肢を移動し、端を越えると反対側に回る |
| Home, End | ビヘイビア使用時は、最初または最後の選択肢に移動する |
| Enter | ビヘイビア使用時は、アクティブなコマンドを実行し、パレットを閉じる |
| Escape | ネイティブのダイアログと同様に、パレットを閉じて元の位置にフォーカスを戻す |
#アクセシビリティ
aria-labelでダイアログの名前を指定します。開いた直後に入力できるように、入力欄にautofocusを付けます。- 入力欄は、コンボボックスと同じようにリストボックスを制御するコンボボックスです。パレット内では、リストは常に展開されています。
- パレットはショートカットなので、すべてのコマンドを別の操作経路からも実行できるようにしてください。
#React、Svelte、Vue
command コンポーネントは、コマンドのリストからパレットを生成し、ビヘイビアを適用して、開閉をアプリケーションに通知します。npx master-ui add command でプロジェクトにコピーできます。コンポーネントの構成と使い方は React、Svelte、Vue を参照してください。
#クラス
| クラス | 説明 |
|---|---|
command | 同じ dialog 要素に dialog と併用します。パレットの内側はパディングなしで幅36remです。ビューポート上部付近に配置し、リストの長さが変わっても入力欄の位置を保ちます。 |
command-search | フィールドの行。label に適用し、行全体から入力欄にフォーカスできるようにします。アイコン、command-input、任意のヒントを含みます。 |
command-input | 装飾のない検索フィールドです。role="combobox" を指定し、aria-controls でリストを参照します。検索フィールド自体に背景はなく、ダイアログがサーフェスになります。 |
command-list | 結果のリストボックスに指定すると、残りの高さを占め、ダイアログ内でスクロール |
command-footer | リストの下にキー操作のヒントを並べる行 |
command-hint | フッターのヒント1件。キー、その操作内容の順に表示 |