탐색

v2.1.0
폼

목록 상자

콤보 상자나 명령 팔레트가 여는 선택용 옵션 목록입니다.

이 페이지의 내용

목록 상자는 값을 고를 수 있는 옵션 목록입니다. 콤보 상자나 명령 팔레트가 이 목록을 열며, 페이지에 독립적으로 배치할 수도 있습니다. 스타일시트는 ARIA 속성에 따라 각 상태를 표시합니다. 스크립트는 키 입력을 처리하고 활성 옵션과 선택된 옵션에 맞춰 속성을 갱신합니다. 페이지에 독립적으로 배치된 목록 상자는 listbox 동작으로 제어하며, 콤보 상자와 명령 팔레트는 각각 자체 입력 필드에서 목록을 제어합니다.

목록 상자

<div class="sheet sheet-flat max-w(320) mx-auto">  <div class="listbox" role="listbox" aria-label="Framework" tabindex="0" aria-activedescendant="fw-astro">    <div class="listbox-option" role="option" id="fw-astro" aria-selected="true" aria-checked="true">      Astro    </div>    <div class="listbox-option" role="option" id="fw-next" aria-checked="false">Next.js</div>    <div class="listbox-option" role="option" id="fw-svelte" aria-checked="false">SvelteKit</div>    <div class="listbox-option" role="option" id="fw-nuxt" aria-checked="false" aria-disabled="true">      Nuxt    </div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="sheet sheet-flat max-w(320) mx-auto">      <div className="listbox" role="listbox" aria-label="Framework" tabIndex={0} aria-activedescendant="fw-astro">        <div className="listbox-option" role="option" id="fw-astro" aria-selected="true" aria-checked="true">          Astro        </div>        <div className="listbox-option" role="option" id="fw-next" aria-checked="false">Next.js</div>        <div className="listbox-option" role="option" id="fw-svelte" aria-checked="false">          SvelteKit        </div>        <div className="listbox-option" role="option" id="fw-nuxt" aria-checked="false" aria-disabled="true">          Nuxt        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="sheet sheet-flat max-w(320) mx-auto" {@attach attach}>  <div class="listbox" role="listbox" aria-label="Framework" tabindex="0" aria-activedescendant="fw-astro">    <div class="listbox-option" role="option" id="fw-astro" aria-selected="true" aria-checked="true">      Astro    </div>    <div class="listbox-option" role="option" id="fw-next" aria-checked="false">Next.js</div>    <div class="listbox-option" role="option" id="fw-svelte" aria-checked="false">SvelteKit</div>    <div class="listbox-option" role="option" id="fw-nuxt" aria-checked="false" aria-disabled="true">      Nuxt    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="sheet sheet-flat max-w(320) mx-auto">    <div class="listbox" role="listbox" aria-label="Framework" tabindex="0" aria-activedescendant="fw-astro">      <div class="listbox-option" role="option" id="fw-astro" aria-selected="true" aria-checked="true">        Astro      </div>      <div class="listbox-option" role="option" id="fw-next" aria-checked="false">Next.js</div>      <div class="listbox-option" role="option" id="fw-svelte" aria-checked="false">SvelteKit</div>      <div class="listbox-option" role="option" id="fw-nuxt" aria-checked="false" aria-disabled="true">        Nuxt      </div>    </div>  </div></template>
옵션을 클릭하거나, 목록에 포커스를 둔 뒤 방향키로 이동하고 Enter 또는 Space 키로 선택하세요.

#두 상태와 두 속성

목록 상자는 키보드로 이동한 위치와 실제로 선택한 값을 구분합니다.

  • 활성 상태는 aria-selected="true"로 표시합니다. 방향키로 이동한 위치의 옵션이며, Enter 키를 누르면 이 옵션이 선택됩니다. 활성 옵션에는 칩과 같은 색조가 적용됩니다. 포인터가 올라간 행에도 같은 색조가 전환 효과 없이 즉시 적용됩니다.
  • 선택 상태는 aria-checked="true"로 표시하며, 해당 옵션의 값이 설정되었음을 뜻합니다. 행 끝에는 체크 표시가 붙습니다. aria-checked가 있는 옵션은 선택 여부와 관계없이 체크 표시 공간을 확보하므로 레이블이 움직이지 않습니다.

포커스는 일반적으로 목록이나 텍스트 필드에 머물며, aria-activedescendant는 활성 옵션을 가리킵니다. 옵션에 직접 포커스가 가면 잉크 색상의 윤곽선도 표시됩니다.

#옵션의 추가 요소

행 앞쪽 아이콘에는 icon을 적용하세요. listbox-body는 제목을 listbox-description 위에 배치하고, listbox-end는 행 끝에 단축키나 힌트를 표시합니다. listbox-group은 옵션과 해당 listbox-label을 하나의 그룹으로 묶고, listbox-separator는 그룹 사이에 구분선을 표시합니다.

옵션의 추가 요소

<div class="sheet sheet-flat max-w(360) mx-auto">  <div class="listbox" role="listbox" aria-label="Commands">    <div class="listbox-group" role="group" aria-labelledby="rich-suggestions">      <div class="listbox-label" id="rich-suggestions">Suggestions</div>      <div class="listbox-option" role="option" 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">        <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="7" cy="7" r="4.5" /><path d="M10.182 10.182L14 14" />        </svg>        <span class="listbox-body">          <span>Search deployments</span>          <span class="listbox-description">By branch, commit or author</span>        </span>      </div>    </div>    <hr class="listbox-separator">    <div class="listbox-group" role="group" aria-labelledby="rich-team">      <div class="listbox-label" id="rich-team">Team</div>      <div class="listbox-option" role="option">        <span class="avatar avatar-xs">          <img class="avatar-image" src="/demo/portrait-1.svg" alt>        </span> Ada Lovelace      </div>      <div class="listbox-option" role="option">        <span class="avatar avatar-xs">          <img class="avatar-image" src="/demo/portrait-2.svg" alt>        </span> Alan Turing      </div>    </div>  </div></div>
import PlusIcon from '@master/icons-react/native/16/soft/plus'import SearchIcon from '@master/icons-react/native/16/soft/search'<div className="sheet sheet-flat max-w(360) mx-auto">  <div className="listbox" role="listbox" aria-label="Commands">    <div className="listbox-group" role="group" aria-labelledby="rich-suggestions">      <div className="listbox-label" id="rich-suggestions">Suggestions</div>      <div className="listbox-option" role="option" 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">        <SearchIcon className="icon" />        <span className="listbox-body">          <span>Search deployments</span>          <span className="listbox-description">By branch, commit or author</span>        </span>      </div>    </div>    <hr className="listbox-separator" />    <div className="listbox-group" role="group" aria-labelledby="rich-team">      <div className="listbox-label" id="rich-team">Team</div>      <div className="listbox-option" role="option">        <span className="avatar avatar-xs">          <img className="avatar-image" src="/demo/portrait-1.svg" alt="" />        </span> Ada Lovelace      </div>      <div className="listbox-option" role="option">        <span className="avatar avatar-xs">          <img className="avatar-image" src="/demo/portrait-2.svg" alt="" />        </span> Alan Turing      </div>    </div>  </div></div>
<script>  import PlusIcon from '@master/icons-svelte/native/16/soft/plus'  import SearchIcon from '@master/icons-svelte/native/16/soft/search'</script><div class="sheet sheet-flat max-w(360) mx-auto">  <div class="listbox" role="listbox" aria-label="Commands">    <div class="listbox-group" role="group" aria-labelledby="rich-suggestions">      <div class="listbox-label" id="rich-suggestions">Suggestions</div>      <div class="listbox-option" role="option" 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">        <SearchIcon class="icon" />        <span class="listbox-body">          <span>Search deployments</span>          <span class="listbox-description">By branch, commit or author</span>        </span>      </div>    </div>    <hr class="listbox-separator">    <div class="listbox-group" role="group" aria-labelledby="rich-team">      <div class="listbox-label" id="rich-team">Team</div>      <div class="listbox-option" role="option">        <span class="avatar avatar-xs">          <img class="avatar-image" src="/demo/portrait-1.svg" alt>        </span> Ada Lovelace      </div>      <div class="listbox-option" role="option">        <span class="avatar avatar-xs">          <img class="avatar-image" src="/demo/portrait-2.svg" alt>        </span> Alan Turing      </div>    </div>  </div></div>
<script setup>import PlusIcon from '@master/icons-vue/native/16/soft/plus'import SearchIcon from '@master/icons-vue/native/16/soft/search'</script><template>  <div class="sheet sheet-flat max-w(360) mx-auto">    <div class="listbox" role="listbox" aria-label="Commands">      <div class="listbox-group" role="group" aria-labelledby="rich-suggestions">        <div class="listbox-label" id="rich-suggestions">Suggestions</div>        <div class="listbox-option" role="option" 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">          <SearchIcon class="icon" />          <span class="listbox-body">            <span>Search deployments</span>            <span class="listbox-description">By branch, commit or author</span>          </span>        </div>      </div>      <hr class="listbox-separator">      <div class="listbox-group" role="group" aria-labelledby="rich-team">        <div class="listbox-label" id="rich-team">Team</div>        <div class="listbox-option" role="option">          <span class="avatar avatar-xs">            <img class="avatar-image" src="/demo/portrait-1.svg" alt>          </span> Ada Lovelace        </div>        <div class="listbox-option" role="option">          <span class="avatar avatar-xs">            <img class="avatar-image" src="/demo/portrait-2.svg" alt>          </span> Alan Turing        </div>      </div>    </div>  </div></template>

#검색 결과

검색 결과는 위치와 일치한 내용을 알려 줍니다. listbox-path는 제목 아래의 작은 한 줄이며 단계마다 listbox-crumb을 둡니다. listbox-excerpt는 일치한 구절이며 최대 두 줄입니다. 입력한 단어는 mark로 감쌉니다. 옵션 안에서는 제목의 글자색과 굵기를 사용하므로 흐린 색의 줄에서도 찾을 수 있습니다.

검색 결과

<div class="sheet sheet-flat max-w(420) mx-auto">  <div class="listbox" role="listbox" aria-label="Results">    <div class="listbox-option" role="option" 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">      <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">      <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>    </div>  </div></div>
import HashIcon from '@master/icons-react/native/16/soft/hash'import FileIcon from '@master/icons-react/native/16/soft/file'<div className="sheet sheet-flat max-w(420) mx-auto">  <div className="listbox" role="listbox" aria-label="Results">    <div className="listbox-option" role="option" 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">      <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">      <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>    </div>  </div></div>
<script>  import HashIcon from '@master/icons-svelte/native/16/soft/hash'  import FileIcon from '@master/icons-svelte/native/16/soft/file'</script><div class="sheet sheet-flat max-w(420) mx-auto">  <div class="listbox" role="listbox" aria-label="Results">    <div class="listbox-option" role="option" 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">      <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">      <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>    </div>  </div></div>
<script setup>import HashIcon from '@master/icons-vue/native/16/soft/hash'import FileIcon from '@master/icons-vue/native/16/soft/file'</script><template>  <div class="sheet sheet-flat max-w(420) mx-auto">    <div class="listbox" role="listbox" aria-label="Results">      <div class="listbox-option" role="option" 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">        <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">        <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>      </div>    </div>  </div></template>
  • 아이콘은 아래에 경로, 설명, 발췌문 중 무엇이 있든 제목 줄에 맞춰집니다. 제목에 경로나 설명을 붙인 것은 하나의 행이므로 listbox-end는 두 줄의 가운데에 맞춰집니다. 발췌문이 있으면 글자가 한 행보다 높아지므로 listbox-end도 제목 옆에 놓입니다.
  • 경로의 각 단계는 텍스트입니다. 옵션의 대상은 하나이므로 브레드크럼의 링크가 아닙니다.
  • 아이콘이 있는 결과가 하나라도 있으면 모든 결과에 아이콘을 넣습니다. 페이지에는 문서 아이콘을, 페이지 안의 제목에는 해시 기호를 사용하면 고유한 아이콘이 없는 결과도 처리할 수 있습니다.

#필터링

스크립트는 조건에 맞지 않는 옵션에 hidden 속성을 설정해 목록을 필터링합니다. 그러면 :has()에 의해 추가 스크립트 없이 다음 두 동작이 이루어집니다.

  • 모든 옵션이 숨겨지면 listbox-empty가 표시되고, 옵션이 하나라도 다시 표시되면 숨겨집니다.
  • listbox-group은 그룹 제목과 옵션을 감싸는 role="group" 요소입니다. 그룹의 모든 옵션이 숨겨져 있는 동안에는 이 요소도 숨겨지므로 그룹 제목만 남는 일이 없습니다.

일치하는 옵션 없음

<div class="sheet sheet-flat max-w(320) mx-auto">  <div class="listbox" role="listbox" aria-label="Regions">    <div class="listbox-option" role="option" hidden>Tokyo</div>    <div class="listbox-option" role="option" hidden>Frankfurt</div>    <div class="listbox-empty">No regions match "zz".</div>  </div></div>
<div className="sheet sheet-flat max-w(320) mx-auto">  <div className="listbox" role="listbox" aria-label="Regions">    <div className="listbox-option" role="option" hidden>Tokyo</div>    <div className="listbox-option" role="option" hidden>Frankfurt</div>    <div className="listbox-empty">No regions match "zz".</div>  </div></div>
<div class="sheet sheet-flat max-w(320) mx-auto">  <div class="listbox" role="listbox" aria-label="Regions">    <div class="listbox-option" role="option" hidden>Tokyo</div>    <div class="listbox-option" role="option" hidden>Frankfurt</div>    <div class="listbox-empty">No regions match "zz".</div>  </div></div>
<template>  <div class="sheet sheet-flat max-w(320) mx-auto">    <div class="listbox" role="listbox" aria-label="Regions">      <div class="listbox-option" role="option" hidden>Tokyo</div>      <div class="listbox-option" role="option" hidden>Frankfurt</div>      <div class="listbox-empty">No regions match "zz".</div>    </div>  </div></template>

#동작

listbox는 페이지에 독립적으로 배치되어 직접 포커스를 받는 목록 상자를 제어합니다. 따라서 목록 상자에는 tabindex="0" 설정이 필요합니다. role="listbox"가 지정된 요소를 인수로 받으며, 설정 옵션 없이 동작을 연결하고 연결을 해제하는 함수를 반환합니다.

app.js
import { listbox } from '@master/ui/behaviors/listbox.js'const list = document.querySelector('.listbox')listbox(list)list.addEventListener('change', () => {  const chosen = list.querySelectorAll('[aria-checked="true"]')})
  • 활성 옵션. 키 입력이나 클릭으로 aria-selected="true"를 한 옵션으로 옮기고, 목록 상자의 aria-activedescendant가 그 옵션을 가리키도록 갱신한 뒤 해당 옵션이 보이도록 스크롤합니다. 포커스는 목록 상자에 계속 머뭅니다. id가 없는 옵션에는 이를 부여합니다. 목록 상자가 포커스를 받을 때 활성 옵션이 없으면 선택된 옵션을 활성화하고, 선택된 옵션도 없으면 첫 번째 옵션을 활성화합니다.
  • 선택. Enter 또는 Space 키를 누르거나 옵션을 클릭하면 해당 옵션에는 aria-checked="true"를, 나머지 옵션에는 false를 설정합니다.
  • 이벤트. 선택이 바뀔 때마다 목록 상자는 input 이벤트에 이어 change 이벤트를 발생시킵니다. 선택된 값을 읽으려면 aria-checked="true"가 설정된 옵션을 확인하세요.
  • 건너뛰는 옵션. 숨겨진 옵션과 aria-disabled="true"가 설정된 옵션은 활성화하거나 선택할 수 없습니다.

목록 상자에 aria-multiselectable="true"가 있으면 각 옵션을 개별적으로 선택하거나 선택 해제할 수 있으며, 다른 옵션의 상태는 그대로 유지됩니다. 파일 목록에서처럼 키를 사용해 연속된 옵션을 한꺼번에 선택할 수도 있습니다. 마지막으로 선택한 옵션이 기준점이 되며, Shift 키를 누른 채 방향키나 Space 키를 누르거나 클릭하면 기준점부터 키나 포인터가 가리키는 옵션까지 모든 옵션이 선택됩니다. Control 또는 Command 키와 A 키를 함께 누르면 모든 옵션이 선택되고, 이미 모두 선택되어 있으면 모두 선택 해제됩니다.

여러 값 선택

<div class="sheet sheet-flat max-w(320) mx-auto">  <div class="listbox" role="listbox" aria-label="Notify me about" aria-multiselectable="true" tabindex="0">    <div class="listbox-option" role="option" id="notify-deploys" aria-checked="true">      Deployments    </div>    <div class="listbox-option" role="option" id="notify-comments" aria-checked="false">      Comments    </div>    <div class="listbox-option" role="option" id="notify-billing" aria-checked="true">Billing</div>    <div class="listbox-option" role="option" id="notify-mentions" aria-checked="false">      Mentions    </div>    <div class="listbox-option" role="option" id="notify-digest" aria-checked="false" aria-disabled="true">      Weekly digest    </div>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="sheet sheet-flat max-w(320) mx-auto">      <div className="listbox" role="listbox" aria-label="Notify me about" aria-multiselectable="true" tabIndex={0}>        <div className="listbox-option" role="option" id="notify-deploys" aria-checked="true">          Deployments        </div>        <div className="listbox-option" role="option" id="notify-comments" aria-checked="false">          Comments        </div>        <div className="listbox-option" role="option" id="notify-billing" aria-checked="true">          Billing        </div>        <div className="listbox-option" role="option" id="notify-mentions" aria-checked="false">          Mentions        </div>        <div className="listbox-option" role="option" id="notify-digest" aria-checked="false" aria-disabled="true">          Weekly digest        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'</script><div class="sheet sheet-flat max-w(320) mx-auto" {@attach attach}>  <div class="listbox" role="listbox" aria-label="Notify me about" aria-multiselectable="true" tabindex="0">    <div class="listbox-option" role="option" id="notify-deploys" aria-checked="true">      Deployments    </div>    <div class="listbox-option" role="option" id="notify-comments" aria-checked="false">      Comments    </div>    <div class="listbox-option" role="option" id="notify-billing" aria-checked="true">Billing</div>    <div class="listbox-option" role="option" id="notify-mentions" aria-checked="false">      Mentions    </div>    <div class="listbox-option" role="option" id="notify-digest" aria-checked="false" aria-disabled="true">      Weekly digest    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="sheet sheet-flat max-w(320) mx-auto">    <div class="listbox" role="listbox" aria-label="Notify me about" aria-multiselectable="true" tabindex="0">      <div class="listbox-option" role="option" id="notify-deploys" aria-checked="true">        Deployments      </div>      <div class="listbox-option" role="option" id="notify-comments" aria-checked="false">        Comments      </div>      <div class="listbox-option" role="option" id="notify-billing" aria-checked="true">        Billing      </div>      <div class="listbox-option" role="option" id="notify-mentions" aria-checked="false">        Mentions      </div>      <div class="listbox-option" role="option" id="notify-digest" aria-checked="false" aria-disabled="true">        Weekly digest      </div>    </div>  </div></template>
목록에 포커스를 둔 다음 Shift 키를 누른 채 ArrowDown 키를 눌러 연속된 옵션을 선택해 보세요.

텍스트 필드가 목록 상자를 제어하는 경우에는 해당 필드의 동작이 목록을 제어합니다. listbox는 role="combobox" 필드의 aria-controls가 가리키는 목록 상자에 관여하지 않으며, attach()는 콤보 상자나 명령 팔레트 안의 목록 상자를 건너뜁니다. 스크립트가 없으면 목록 상자는 속성에 지정된 상태로 표시되며 상태가 바뀌지 않습니다.

#플로팅 목록 상자

popover 속성을 설정하면 목록 상자가 모서리 반경 12px의 플로팅 시트으로 표시되며, 각 행의 모서리 반경은 8px입니다. 기준 요소에 맞춰 배치되고 뷰포트 가장자리에서는 반대편으로 배치되며, 열리고 닫힐 때 메뉴와 같은 애니메이션을 사용합니다. 텍스트 필드가 목록 상자를 제어할 때는 입력 중에 닫히지 않도록 popover="manual"로 설정하세요. 콤보 상자에서 이 동작을 확인할 수 있습니다.

#목록 상자, 메뉴, 셀렉트

  • 셀렉트는 목록에서 값 하나를 선택하는 기본 HTML 컨트롤입니다. 옵션이 일반 텍스트로만 구성되어 있을 때 사용하세요. 스크립트가 필요 없습니다.
  • 메뉴는 기본 HTML 버튼과 링크로 실행 항목을 제공합니다.
  • 목록 상자는 스크립트로 필터링하거나 그룹화하거나 불러오는 값이나 결과를 표시합니다. 콤보 상자, 명령 팔레트, 다중 선택 컨트롤에서 사용합니다.

#키보드

다음은 목록 상자에 포커스가 있을 때 listbox 동작이 처리하는 키입니다. 방향키로는 첫 번째 옵션과 마지막 옵션을 넘어 이동할 수 없습니다. 콤보 상자와 명령 팔레트에서는 입력 필드가 각 패턴에 맞게 키 입력을 처리합니다.

키동작
ArrowDown, ArrowUp비활성화된 옵션을 건너뛰어 활성 옵션을 바꾸고, 해당 옵션이 보이도록 스크롤합니다.
Home, End첫 번째 또는 마지막 옵션으로 이동합니다.
Enter, Space활성 옵션을 선택합니다. aria-multiselectable="true"가 지정된 목록에서는 해당 옵션의 체크 상태를 전환합니다.
Shift+ArrowDown, Shift+ArrowUp다중 선택 목록에서 이동하면서, 마지막으로 선택한 옵션부터 새 활성 옵션까지 모든 옵션을 체크합니다.
Shift+Space, Shift+click다중 선택 목록에서 마지막으로 선택한 옵션부터 이 옵션까지 모든 옵션을 체크합니다.
Control+Shift+Home, Control+Shift+End다중 선택 목록에서 첫 번째 또는 마지막 옵션까지 모든 옵션을 체크합니다. Mac에서는 Command를 사용합니다.
Control+A다중 선택 목록에서 모든 옵션을 체크합니다. 모두 체크되어 있으면 모두 해제합니다. Mac에서는 Command를 사용합니다.
Typing입력한 글자로 시작하는 다음 옵션으로 이동합니다.

#접근성

  • 컨테이너에 role="listbox"와 레이블을 지정하고, 각 옵션에 role="option"을 지정하세요. listbox-group에는 role="group"을 지정하고, aria-labelledby가 그룹 제목을 가리키도록 설정하세요.
  • 이 동작은 aria-selected 및 aria-activedescendant 속성을 함께 갱신하고 활성 옵션이 보이도록 스크롤합니다. 각 옵션에는 스크롤 여백이 있어 목록 가장자리에 바짝 붙지 않습니다.
  • 비활성화된 옵션에는 aria-disabled="true"가 설정되며, 키보드로 이동할 때 건너뜁니다.

#React, Svelte, Vue

listbox 컴포넌트는 데이터로 옵션을 렌더링하고, 동작을 연결하며, 선택된 값을 입력으로 받고 외부로 전달합니다. group이 있는 옵션은 해당 캡션 아래에 작성됩니다. 컴포넌트는 role="group"이 있고 listbox-label로 레이블이 지정된 listbox-group을 작성하며, 같은 그룹의 옵션을 한데 모아 각 그룹이 데이터에 처음 나타나는 순서대로 표시합니다. npx master-ui add listbox로 프로젝트에 복사하세요. React, Svelte, Vue에서 컴포넌트의 구성과 사용법을 확인할 수 있습니다.

ui/listbox.tsx
'use client'import { useId, useState, type ComponentProps } from 'react'import { listbox } from '@master/ui/behaviors/listbox.js'import { useBehavior } from './use-behavior'export interface ListboxOption {  /** What choosing the option gives `onValueChange`. */  value: string  label: string  description?: string  /** The caption of the group the option belongs to. Options of one group are written together, under it. */  group?: string  disabled?: boolean}export interface ListboxProps extends Omit<ComponentProps<'div'>, 'defaultValue' | 'children' | 'role' | 'ref'> {  options: ListboxOption[]  /** The value of the chosen option, null for none; a list of them when `multiple`. */  value?: string | string[] | null  defaultValue?: string | string[] | null  onValueChange?: (value: string | string[] | null) => void  /** Any number of options may be chosen. */  multiple?: boolean}/** A listbox that stands in the page. Name it with `aria-label` or `aria-labelledby`. */export function Listbox({ options, value, defaultValue, onValueChange, multiple, className, ...root }: ListboxProps) {  const id = useId()  const ref = useBehavior(listbox, undefined, { value, defaultValue, onValueChange })  const [first] = useState(() => [value ?? defaultValue ?? []].flat())  const groups = [...new Set(options.map(option => option.group))]  const row = (option: ListboxOption) => (    <div className="listbox-option" role="option" key={option.value} data-value={option.value} aria-checked={first.includes(option.value)} aria-disabled={option.disabled || undefined}>      {option.description        ? <span className="listbox-body"><span>{option.label}</span><span className="listbox-description">{option.description}</span></span>        : option.label}    </div>  )  return (    <div className={className ? `listbox ${className}` : 'listbox'} role="listbox" tabIndex={0} aria-multiselectable={multiple || undefined} ref={ref} {...root}>      {groups.map((group, index) => group === undefined        ? options.filter(option => option.group === undefined).map(row)        : (            <div className="listbox-group" role="group" aria-labelledby={`${id}group${index}`} key={group}>              <div className="listbox-label" id={`${id}group${index}`}>{group}</div>              {options.filter(option => option.group === group).map(row)}            </div>          ))}    </div>  )}
ui/Listbox.svelte
<script lang="ts" module>  import type { HTMLAttributes } from 'svelte/elements'  export interface ListboxOption {    /** What choosing the option gives `onValueChange`. */    value: string    label: string    description?: string    /** The caption of the group the option belongs to. Options of one group are written together, under it. */    group?: string    disabled?: boolean  }  export interface ListboxProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'children'> {    options: ListboxOption[]    /** The value of the chosen option, null for none; a list of them when `multiple`. Bind it, or leave it out. */    value?: string | string[] | null    onValueChange?: (value: string | string[] | null) => void    /** Any number of options may be chosen. */    multiple?: boolean  }</script><script lang="ts">  import { untrack } from 'svelte'  import { listbox } from '@master/ui/behaviors/listbox.js'  import { behavior } from './behavior.svelte.js'  let { options, value = $bindable(), onValueChange, multiple, class: className, ...root }: ListboxProps = $props()  const id = $props.id()  // The first value is drawn into the first render; after that the behavior marks what is chosen. A row written  // later, from new options, is drawn with the value as it is then, which is not read as state.  const chosen = { values: untrack(() => [value ?? []].flat()) }  const groups = $derived([...new Set(options.map(option => option.group))])  const attach = behavior(listbox, undefined, {    value: () => value,    change: (next) => { chosen.values = [next ?? []].flat(); value = next; onValueChange?.(next) },    settled: (held) => { chosen.values = [held ?? []].flat() },  })</script>{#snippet row(option: ListboxOption)}  <!-- The behavior writes `aria-selected` on the option the keys are on. -->  <!-- svelte-ignore a11y_role_has_required_aria_props -->  <div class="listbox-option" role="option" data-value={option.value} aria-checked={chosen.values.includes(option.value)} aria-disabled={option.disabled || undefined}>    {#if option.description}      <span class="listbox-body"><span>{option.label}</span><span class="listbox-description">{option.description}</span></span>    {:else}      {option.label}    {/if}  </div>{/snippet}<!--  @component  A listbox that stands in the page. Name it with `aria-label` or `aria-labelledby`.--><div class={['listbox', className]} role="listbox" tabindex={0} aria-multiselectable={multiple || undefined} {@attach attach} {...root}>  {#each groups as group, index (group)}    {#if group === undefined}      {#each options.filter(option => option.group === undefined) as option (option.value)}{@render row(option)}{/each}    {:else}      <div class="listbox-group" role="group" aria-labelledby="{id}group{index}">        <div class="listbox-label" id="{id}group{index}">{group}</div>        {#each options.filter(option => option.group === group) as option (option.value)}{@render row(option)}{/each}      </div>    {/if}  {/each}</div>
ui/Listbox.vue
<script lang="ts">export interface ListboxOption {  /** What choosing the option gives the model. */  value: string  label: string  description?: string  /** The caption of the group the option belongs to. Options of one group are written together, under it. */  group?: string  disabled?: boolean}</script><script setup lang="ts">import { computed, h, useId, useTemplateRef, type FunctionalComponent } from 'vue'import { listbox } from '@master/ui/behaviors/listbox.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { options } = defineProps<{  options: ListboxOption[]  /** Any number of options may be chosen. */  multiple?: boolean}>()/** The value of the chosen option, null for none; a list of them when `multiple`: `v-model`. */const model = defineModel<string | string[] | null>()/* A listbox that stands in the page. Name it with `aria-label` or `aria-labelledby`. */const id = useId()const first = [model.value ?? []].flat()const groups = computed(() => [...new Set(options.map(option => option.group))])const root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, listbox, undefined, model)const Row: FunctionalComponent<{ option: ListboxOption }> = ({ option }) => h('div', {  'class': 'listbox-option',  'role': 'option',  'data-value': option.value,  'aria-checked': first.includes(option.value),  'aria-disabled': option.disabled || undefined,}, option.description  ? h('span', { class: 'listbox-body' }, [h('span', option.label), h('span', { class: 'listbox-description' }, option.description)])  : option.label)Row.props = ['option']</script><template>  <div class="listbox" role="listbox" tabindex="0" :aria-multiselectable="multiple || undefined" ref="root" v-bind="$attrs">    <template v-for="(group, index) in groups" :key="group ?? ''">      <template v-if="group === undefined">        <template v-for="option in options" :key="option.value"><Row v-if="option.group === undefined" :option="option" /></template>      </template>      <div v-else class="listbox-group" role="group" :aria-labelledby="`${id}-group-${index}`">        <div class="listbox-label" :id="`${id}-group-${index}`">{{ group }}</div>        <template v-for="option in options" :key="option.value"><Row v-if="option.group === group" :option="option" /></template>      </div>    </template>  </div></template>

#클래스

클래스설명
listbox목록을 표시합니다. popover 속성이 있으면 떠 있는 시트로 표시됩니다.
listbox-optionrole="option"이 지정된 요소의 옵션입니다. data-value가 있으면 그 값을 사용하고, 없으면 요소의 텍스트를 사용합니다.
listbox-body옵션 안에 제목을 두고 그 아래에 설명을 배치합니다
listbox-descriptionlistbox-body 안에서 옵션 제목 아래에 낮은 강조도로 표시하는 한 줄 설명
listbox-path옵션의 위치입니다. 제목 아래의 작은 한 줄이며 listbox-body 안에 두고, 단계마다 listbox-crumb을 둡니다. 줄바꿈하지 않으며 위의 제목은 컨트롤의 굵기를 사용합니다.
listbox-crumblistbox-path의 한 단계입니다. 첫 단계를 제외한 모든 단계 앞에 꺾쇠가 붙습니다. 링크가 아닌 텍스트입니다.
listbox-excerpt옵션의 글자 아래에 두는 구절입니다. listbox-body 안에 두며 검색과 일치한 내용을 최대 두 줄로 보여 줍니다. 이 구절이 있으면 아이콘과 끝부분 요소는 제목 옆에 놓입니다.
listbox-end옵션 끝의 단축키 또는 안내
listbox-group옵션과 캡션을 role="group"이 지정된 요소에 배치하고, 캡션을 그룹의 접근 가능한 이름으로 연결합니다. 모든 옵션이 숨겨져 있는 동안 그룹도 숨겨집니다.
listbox-label옵션 그룹 위에 낮은 강조도로 표시하는 캡션입니다.
listbox-separator그룹 사이를 나누는 가는 선으로, 목록 양쪽 가장자리까지 이어집니다.
listbox-empty일치하는 항목이 없을 때 목록에 표시되는 메시지입니다. 모든 옵션이 숨겨지면 나타납니다.

#사용자 지정 속성

속성기본값설명
--listbox-inset4px옵션 둘레의 패딩
--listbox-option-radiusvar(--radius-control-sm)행 모서리 반경. 플로팅 목록의 모서리 반경은 이 값에 안쪽 여백을 더한 값입니다.

#소스 코드

@master/ui/components/listbox.css
/* * Listbox: a list of options to choose from, the surface a combobox and a command palette open. * The stylesheet draws every state from ARIA and leaves the behavior to the script that drives it: * aria-selected marks the active option, the one the arrow keys are on; aria-checked marks a chosen value * with a check. In the flow of the page it is a plain list; with the popover attribute it is a floating * sheet placed against its anchor, whose corner is a row's corner plus its 4px inset. * An option follows one alignment: its icon, its words and its end center on one another, which holds while the * words are a title and one line under it, a description or a path. With an excerpt, a passage of up to two * lines, the option turns to its first line: the icon and the end stand beside the title and the rest runs * under it. A match in an option is a mark, in the title's ink and weight so it is found in a muted line too. */@layer components.ui {  .listbox {    --listbox-inset: 4px;    --listbox-option-radius: var(--radius-control-sm);    min-width: 0;    margin: 0;    padding: var(--listbox-inset);    overflow-y: auto;    overscroll-behavior: contain;    color: var(--color-text-strong);    font: 400 .84375rem/1.2 var(--font-family-sans);    font-feature-settings: inherit;    /* A label, a description or a query echoed in the empty state wraps rather than scroll the list sideways. */    overflow-wrap: anywhere;    list-style: none;    scrollbar-width: thin;    scrollbar-color: var(--color-line-strong) transparent;    /*     * The list holds focus while aria-activedescendant moves through it: the active row shows where, with the     * ink outline the keys leave inside a row, so it never reads as a row under the pointer.     */    &:focus-visible {      outline: none;      .listbox-option[aria-selected="true"] {        outline: 2px solid var(--color-focus);        outline-offset: -2px;      }    }    /*     * Until an option is active (the script has not run yet, a press gave the list focus, or every option is     * filtered out) the list itself shows that it holds the keys.     */    &:focus-visible:not(:has(.listbox-option[aria-selected="true"]:not([hidden]))) {      @apply --focus-ring;    }    /* Floating: opened with showPopover() by the script that owns the field. */    &[popover] {      --surface-color: var(--color-surface-floating);      min-width: 11rem;      max-width: min(24rem, calc(100vw - 1rem));      max-height: min(20rem, 60dvh);      border: 0;      border-radius: calc(var(--listbox-option-radius) * var(--corner-scale) + var(--listbox-inset));      corner-shape: var(--corner-shape);      background: var(--color-surface-floating);      box-shadow: var(--shadow-floating);      transform-origin: top;      @apply --anchored;      @apply --pop;    }    @media (forced-colors: active) {      &[popover] {        outline: 1px solid CanvasText;        outline-offset: -1px;      }    }  }  /* An option: role="option" on any element. */  .listbox-option {    --icon-size: 1rem;    --icon-offset: -.0625rem;    --icon-color: var(--color-text-muted);    display: flex;    align-items: center;    gap: .625rem;    min-height: 2rem;    padding: .25rem .5rem;    border-radius: calc(var(--listbox-option-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    outline: none;    color: var(--color-text-strong);    scroll-margin: var(--listbox-inset);    user-select: none;    -webkit-user-select: none;    -webkit-tap-highlight-color: transparent;    cursor: pointer;    touch-action: manipulation;    /* A script filters by setting hidden; a display on this rule would otherwise bring the option back. */    &[hidden] {      display: none;    }    /* A row answers at once: no fade between rows as the pointer or the keys travel. */    @media (hover: hover) {      &:hover:not([aria-disabled="true"]) {        --icon-color: currentColor;        background: var(--color-surface-chip);      }    }    /* Pressed: a step deeper than the pointer's tone. */    &:active:not([aria-disabled="true"]) {      background: var(--color-surface-inset-hover);    }    &[aria-selected="true"] {      --icon-color: currentColor;      background: var(--color-surface-chip);    }    /* With real focus on the option, the ink outline says so. */    &:focus-visible {      --icon-color: currentColor;      background: var(--color-surface-chip);      outline: 2px solid var(--color-focus);      outline-offset: -2px;    }    &[aria-disabled="true"] {      --icon-color: currentColor;      color: var(--color-text-disabled);      cursor: not-allowed;    }    /* A checkable option keeps room for its mark at the end, so nothing moves when it is chosen. */    &[aria-checked]::after {      content: '';      flex: none;      width: 14px;      height: 14px;      margin-inline-start: auto;      opacity: 0;      background: currentColor;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8L6.3532 11.3532A0.2 0.2 0 0 0 6.6412 11.3479L13 4.5'/%3E%3C/svg%3E") center / contain no-repeat;    }    /* Beside something at the end of the option, the mark follows it: only one of the two is pushed to the end. */    &[aria-checked]:has(.listbox-end)::after {      margin-inline-start: 0;    }    &[aria-checked="true"]::after {      opacity: 1;    }    @media (pointer: coarse) {      min-height: 2.75rem;    }    @media (forced-colors: active) {      &:is(:focus-visible, [aria-selected="true"]):not([aria-disabled="true"]) {        background: Highlight;        color: HighlightText;        forced-color-adjust: none;      }      /* Only a pointer that hovers lights a row: a tap would leave it lit on a touch screen. */      @media (hover: hover) {        &:hover:not([aria-disabled="true"]) {          background: Highlight;          color: HighlightText;          forced-color-adjust: none;        }      }      &[aria-disabled="true"] {        color: GrayText;      }      /* The check is a fill cut by a mask: kept out of forced colors, it takes the row's system ink. */      &::after {        forced-color-adjust: none;        background: currentColor;      }    }  }  /* A title with a line under it, for an option that needs a sentence. */  .listbox-body {    display: grid;    flex: 1 1 0;    gap: .125rem;    min-width: 0;    padding-block: .125rem;  }  .listbox-description {    margin: 0;    color: var(--color-text-muted);    font-size: .75rem;    line-height: 1.4;    text-wrap: pretty;  }  /*   * Where an option is: the steps of a path on one line under the title, a chevron between them. They are not   * links (an option is one target), so this is not a breadcrumb. The line never wraps: its steps give way   * together and end in an ellipsis.   */  .listbox-path {    display: flex;    min-width: 0;    margin: 0;    color: var(--color-text-muted);    font-size: .71875rem;    line-height: 1.4;    white-space: nowrap;  }  .listbox-crumb {    flex: 0 1 auto;    min-width: 0;    overflow: hidden;    text-overflow: ellipsis;    &:not(:first-child)::before {      content: '';      display: inline-block;      width: .75rem;      height: .75rem;      margin-inline: .125rem;      background: var(--color-text-disabled);      vertical-align: -.125rem;      mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5'/%3E%3C/svg%3E") center / contain no-repeat;    }    &:dir(rtl)::before {      scale: -1 1;    }  }  /*   * A passage under an option's words, where a search shows what it matched: two lines at most, then an ellipsis.   * Without line-clamp the passage runs to its end.   */  .listbox-excerpt {    display: -webkit-box;    margin: .125rem 0 0;    overflow: hidden;    color: var(--color-text-muted);    font-size: .75rem;    line-height: 1.45;    -webkit-box-orient: vertical;    -webkit-line-clamp: 2;    line-clamp: 2;  }  /*   * An icon names the option, so it stands on the title's line whatever the body holds under it: a description,   * a path or an excerpt. Centred on two lines it sat between the title and the line under, beside neither, and a   * list that mixes results with and without an excerpt showed its icons at two heights. A picture, an avatar or   * a thumbnail, is as tall as the two lines and still centers on them.   */  .listbox-option:has(.listbox-body) {    /* The title's line and the body's padding, in rem: the end reads it at its own smaller size. */    --listbox-line: calc(.84375rem * 1.2 + .25rem);    .icon {      align-self: start;      margin-block: calc((var(--listbox-line) - var(--icon-size)) / 2);    }  }  /*   * Centering reads as one row for a title and a line under it. An excerpt makes the words taller than that, so   * the option turns to its first line: the icon, the end and the check stand beside the title, each in a box   * as tall as the title's line with the body's own padding, and the row keeps a little more room around it.   */  .listbox-option:has(.listbox-excerpt) {    align-items: start;    padding-block: .375rem;    .listbox-end {      min-height: var(--listbox-line);    }    &[aria-checked]::after {      margin-block: calc((var(--listbox-line) - 14px) / 2);    }  }  /*   * A result's title leads smaller lines, so it takes a control's weight and they do not. A list of results   * keeps one weight whether or not a result has a passage to show.   */  .listbox-option:has(.listbox-path, .listbox-excerpt) {    font-weight: var(--font-weight-control);    :is(.listbox-description, .listbox-path, .listbox-excerpt, .listbox-end) {      font-weight: 400;    }  }  /* A match: the title's ink and a control's weight over the wash, so it is found at a glance in a muted line. */  .listbox-option .mark {    --mark-weight: var(--font-weight-control);  }  .listbox-option:not([aria-disabled="true"]) .mark {    --mark-ink: var(--color-text-strong);  }  /* A shortcut or a hint at the end of an option. */  .listbox-end {    display: inline-flex;    flex: none;    align-items: center;    gap: .25rem;    margin-inline-start: auto;    padding-inline-start: 1rem;    color: var(--color-text-muted);    font-size: .71875rem;    font-variant-numeric: tabular-nums;  }  /* Secondary ink must follow the system-selected foreground, including on highlighted options. */  @media (forced-colors: active) {    :is(.listbox-description, .listbox-path, .listbox-excerpt, .listbox-end) {      color: inherit;    }    /* The chevron is a fill cut by a mask: it takes the row's system ink, as the check does. */    .listbox-crumb:not(:first-child)::before {      forced-color-adjust: none;      background: currentColor;    }  }  /* A group: role="group" around a caption and its options. With every option filtered out, it steps aside. */  .listbox-group:not(:has(.listbox-option:not([hidden]))) {    display: none;  }  /*   * A quiet caption over a group of options. It belongs to the options under it: the room above parts its group from   * the one before, and the room below is small, so the caption reads with the options it leads. The first group still   * shown, or one after a separator, has nothing to part from or a hairline that does it, and keeps a little room.   * Without :nth-child(of), the first group keeps the larger room.   */  .listbox-label {    margin: 0;    padding: .75rem .5rem .25rem;    color: var(--color-text-muted);    font-size: .71875rem;    user-select: none;    -webkit-user-select: none;    .listbox-separator + .listbox-group & {      padding-block-start: .375rem;    }    .listbox-group:nth-child(1 of .listbox-group:has(.listbox-option:not([hidden]))) & {      padding-block-start: .375rem;    }  }  /* A hairline between groups, running to the list's edges. */  .listbox-separator {    height: 1px;    margin: var(--listbox-inset) calc(-1 * var(--listbox-inset));    border: 0;    background: var(--color-line-hair);    /* Forced colors repaint the background as the canvas; a system color keeps the rule. */    @media (forced-colors: active) {      background: CanvasText;    }  }  /* What the list says when nothing matches. It shows by itself once every option is hidden. */  .listbox-empty {    margin: 0;    padding: 1.5rem .75rem;    color: var(--color-text-muted);    text-align: center;    text-wrap: balance;  }  .listbox:has(.listbox-option:not([hidden])) .listbox-empty {    display: none;  }  /* A caption or a rule with no visible option left under its list has nothing to introduce. */  .listbox:not(:has(.listbox-option:not([hidden]))) :is(.listbox-label, .listbox-separator) {    display: none;  }}