명령 팔레트
명령 목록 위에 검색 필드 하나를 배치한 대화 상자입니다.
이 페이지의 내용
명령 팔레트는 명령 목록 위에 검색 필드 하나를 둔 인터페이스로, 단축키로 어디서든 열 수 있습니다. 내부 구성이 다른 대화 상자입니다. 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는 결과의 위치입니다. 제목 아래의 작은 한 줄이며, 단계마다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 | 검색 결과의 listbox는 남은 높이를 채우고 대화 상자 안에서 스크롤됩니다. |
command-footer | 목록 아래에 한 줄로 표시되는 키 안내 |
command-hint | 푸터의 안내 항목 하나에 키를 먼저 표시하고 이어서 해당 키의 동작을 설명합니다. |