覆疊元件
指令面板
在指令清單上方放置搜尋欄位的對話框。
本頁內容
指令面板由搜尋欄位和下方的指令清單組成,可從文件中的任何位置用快速鍵開啟。它使用對話框作為外框。在 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>按下按鈕即可開啟面板,焦點在預覽區內時也可按 ⌘K 或 Ctrl K。輸入文字來篩選,用方向鍵移動,再按 Enter 執行指令。
#結構
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>搜尋 token 的結果。符合的文字和結果一樣由搜尋寫入:行為只負責篩選清單裡現有的選項。
- 圖示說明結果的種類。 頁面使用文件圖示,頁面內的標題使用井字號。沒有專屬圖示的結果就從這兩者擇一,讓所有標題對齊同一條邊。
listbox-path說明結果的位置。 它是標題下方的一行小字,每一層各用一個listbox-crumb。這些層級不是連結,因為一個選項只有一個目標,所以它不是麵包屑導覽。listbox-excerpt是符合搜尋的段落,最多兩行。有了它,圖示會對齊標題,而不是置於整列的中央。- 符合的文字使用
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 | 頁尾的一則操作提示,先列按鍵,再說明其功能。 |