탐색

v2.1.0
폼

콤보박스

입력할 때 일치하는 옵션의 목록 상자를 여는 텍스트 필드로, 직접 입력할 수 있는 선택 상자입니다.

이 페이지의 내용

콤보박스는 입력한 텍스트와 일치하는 옵션을 보여 주는 목록 상자를 여는 텍스트 필드로, 직접 입력할 수 있는 선택 컨트롤입니다. 기존 입력 그룹과 플로팅 목록 상자를 combobox 래퍼로 감싸 하나로 묶습니다. 스타일시트는 위치와 모양을 지정하고, combobox 동작은 옵션을 필터링하고 옵션 사이를 이동하며 선택한 값을 필드에 입력합니다.

콤보박스

<div class="field max-w(320) mx-auto">  <label for="region">Region</label>  <div class="combobox">    <div class="input-group">      <input class="input-group-field" id="region" role="combobox" aria-expanded="false" aria-controls="region-list" aria-autocomplete="list" autocomplete="off" placeholder="Search regions">      <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" />        </svg>      </button>    </div>    <div id="region-list" popover="manual" class="listbox" role="listbox" aria-label="Regions">      <div class="listbox-option" role="option" id="region-hnd" aria-checked="false">Tokyo</div>      <div class="listbox-option" role="option" id="region-sin" aria-checked="false">Singapore</div>      <div class="listbox-option" role="option" id="region-fra" aria-checked="false">Frankfurt</div>      <div class="listbox-option" role="option" id="region-lhr" aria-checked="false">London</div>      <div class="listbox-option" role="option" id="region-iad" aria-checked="false">Virginia</div>      <div class="listbox-option" role="option" id="region-pdx" aria-checked="false" aria-disabled="true">        Oregon      </div>      <div class="listbox-empty">No regions match.</div>    </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'import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="field max-w(320) mx-auto">      <label htmlFor="region">Region</label>      <div className="combobox">        <div className="input-group">          <input className="input-group-field" id="region" role="combobox" aria-expanded="false" aria-controls="region-list" aria-autocomplete="list" autoComplete="off" placeholder="Search regions" />          <button type="button" className="combobox-toggle" tabIndex={-1} aria-label="Show regions">            <ChevronDownIcon className="icon" />          </button>        </div>        <div id="region-list" popover="manual" className="listbox" role="listbox" aria-label="Regions">          <div className="listbox-option" role="option" id="region-hnd" aria-checked="false">Tokyo</div>          <div className="listbox-option" role="option" id="region-sin" aria-checked="false">            Singapore          </div>          <div className="listbox-option" role="option" id="region-fra" aria-checked="false">            Frankfurt          </div>          <div className="listbox-option" role="option" id="region-lhr" aria-checked="false">            London          </div>          <div className="listbox-option" role="option" id="region-iad" aria-checked="false">            Virginia          </div>          <div className="listbox-option" role="option" id="region-pdx" aria-checked="false" aria-disabled="true">            Oregon          </div>          <div className="listbox-empty">No regions match.</div>        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><div class="field max-w(320) mx-auto" {@attach attach}>  <label for="region">Region</label>  <div class="combobox">    <div class="input-group">      <input class="input-group-field" id="region" role="combobox" aria-expanded="false" aria-controls="region-list" aria-autocomplete="list" autocomplete="off" placeholder="Search regions">      <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">        <ChevronDownIcon class="icon" />      </button>    </div>    <div id="region-list" popover="manual" class="listbox" role="listbox" aria-label="Regions">      <div class="listbox-option" role="option" id="region-hnd" aria-checked="false">Tokyo</div>      <div class="listbox-option" role="option" id="region-sin" aria-checked="false">Singapore</div>      <div class="listbox-option" role="option" id="region-fra" aria-checked="false">Frankfurt</div>      <div class="listbox-option" role="option" id="region-lhr" aria-checked="false">London</div>      <div class="listbox-option" role="option" id="region-iad" aria-checked="false">Virginia</div>      <div class="listbox-option" role="option" id="region-pdx" aria-checked="false" aria-disabled="true">        Oregon      </div>      <div class="listbox-empty">No regions match.</div>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="field max-w(320) mx-auto">    <label for="region">Region</label>    <div class="combobox">      <div class="input-group">        <input class="input-group-field" id="region" role="combobox" aria-expanded="false" aria-controls="region-list" aria-autocomplete="list" autocomplete="off" placeholder="Search regions">        <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">          <ChevronDownIcon class="icon" />        </button>      </div>      <div id="region-list" popover="manual" class="listbox" role="listbox" aria-label="Regions">        <div class="listbox-option" role="option" id="region-hnd" aria-checked="false">Tokyo</div>        <div class="listbox-option" role="option" id="region-sin" aria-checked="false">          Singapore        </div>        <div class="listbox-option" role="option" id="region-fra" aria-checked="false">          Frankfurt        </div>        <div class="listbox-option" role="option" id="region-lhr" aria-checked="false">London</div>        <div class="listbox-option" role="option" id="region-iad" aria-checked="false">          Virginia        </div>        <div class="listbox-option" role="option" id="region-pdx" aria-checked="false" aria-disabled="true">          Oregon        </div>        <div class="listbox-empty">No regions match.</div>      </div>    </div>  </div></template>
텍스트를 입력해 옵션을 필터링하고, 방향키로 이동한 뒤 Enter 키를 누르거나 클릭해 선택하세요.

#스타일시트의 역할

  • 배치. combobox 래퍼는 자신을 앵커로 지정하고 앵커 이름의 범위를 래퍼 자체로 제한합니다. 목록 상자는 캐럿이나 버튼이 아닌 필드 전체를 기준으로 그 아래 6px에 열리며, anchor-size()를 사용해 목록 상자의 너비를 최소한 필드 너비만큼 확보합니다. 별도의 측정이 필요 없으며 한 페이지에 콤보박스가 여러 개 있어도 서로 영향을 주지 않습니다.
  • 꺾쇠 아이콘. combobox-toggle은 필드 끝에 있는 작은 버튼으로, 꺾쇠 아이콘을 담습니다. 필드가 aria-expanded="true" 상태인 동안 꺾쇠 아이콘이 반대 방향을 향합니다.
  • 빈 상태. 모든 옵션이 hidden 상태가 되면 listbox-empty가 자동으로 표시됩니다.
  • 필드 상태. 호버, 포커스, 유효하지 않음, 비활성화 상태는 입력 그룹에서 처리합니다.

앵커 위치 지정을 지원하지 않는 브라우저에서도 목록 상자는 열리며, 마크업에 놓인 위치대로 필드 바로 아래에 목록 상자 자체의 너비로 표시됩니다.

#동작

combobox 동작은 combobox 클래스가 있는 루트 요소와 옵션 객체를 받아, 연결한 동작을 해제하는 함수를 반환합니다. role="combobox"로 필드를 찾고 role="listbox"로 목록을 찾습니다. filter 옵션의 기본값은 true입니다. filter: false를 지정하면 자동 완성에서 보듯이 옵션을 페이지가 처리합니다. name, removeLabel, draw는 여러 값 선택에 사용합니다.

app.js
import { combobox } from '@master/ui/behaviors/combobox.js'const box = combobox(document.querySelector('.combobox'))box.value // what the chosen option stands for, or nullbox.query // the text in the field

반환된 함수에는 외부에서 읽고 설정할 수 있는 속성이 두 개 있습니다. 어느 속성을 설정해도 이벤트는 발행하지 않습니다.

  • value 속성은 선택한 옵션이 나타내는 값으로, 옵션의 data-value 또는 텍스트입니다. 필드에 텍스트를 입력한 뒤 옵션을 선택하지 않은 상태에서는 null입니다. 값을 설정하면 해당 옵션에 체크 표시를 하고 그 텍스트를 필드에 입력합니다.

  • query 속성은 필드의 텍스트, 즉 사용자가 찾고 있는 내용입니다. 선택 값과는 다릅니다. 키를 누를 때마다 바뀌며, 옵션을 선택하면 그 옵션의 텍스트가 됩니다. 값을 설정하면 필드에 입력하고, 직접 입력할 때와 마찬가지로 옵션을 필터링합니다.

  • 텍스트를 입력하면 대소문자를 구분하지 않고 입력한 문자열이 포함되어 있는지 확인합니다. 텍스트에 해당 문자열이 없는 옵션에 hidden 속성을 설정하고 목록을 연 뒤, 첫 번째 일치 항목을 활성 옵션으로 지정합니다.

  • 활성 옵션에는 aria-selected="true"가 설정되며, 필드의 aria-activedescendant 속성이 해당 옵션을 가리킵니다. 포커스는 필드에 유지됩니다.

  • Enter 키나 포인터로 옵션을 선택하면 옵션에서 listbox-description과 listbox-end를 제외한 텍스트를 필드에 입력하고, 선택한 옵션은 aria-checked="true"로, 나머지 옵션은 false로 표시한 뒤 목록을 닫습니다. 선택한 값을 직접 수정하면 해당 옵션의 체크 표시가 사라집니다.

  • 열기와 닫기. 목록 상자는 popover="manual"이므로 필드에 입력하거나 필드를 클릭해도 닫히지 않습니다. 이 동작은 필드를 클릭하거나 토글 버튼을 조작하거나 방향키를 누르면 목록을 열고, Esc 키를 누르거나 포커스가 콤보박스를 벗어나면 목록을 닫습니다. aria-expanded는 목록의 열림 상태에 맞춰 갱신합니다.

  • 이벤트. 옵션을 선택하면 필드에 직접 입력할 때와 마찬가지로 필드에서 input, change 순서로 이벤트를 발생시킵니다. 값은 필드의 value입니다.

비활성화되거나 숨겨진 옵션은 건너뜁니다. 입력기로 문자를 조합하는 동안에는 입력기가 Enter 키와 방향키를 처리합니다.

동작을 연결하지 않으면 필드는 일반 텍스트 입력란으로 작동합니다. 값을 직접 입력할 수 있으며 목록은 열리지 않습니다.

#여러 값 선택

aria-multiselectable="true"가 설정된 목록 상자에는 여러 값을 담을 수 있습니다. 이때 필드는 태그 입력과 마찬가지로 input-group-wrap을 적용한 입력 그룹이 되며, 선택한 옵션은 각각 필드 앞에 칩으로 표시됩니다. 옵션을 선택하면 체크 표시가 켜지거나 꺼지고, 필드가 비워지며, 목록은 열린 상태로 유지됩니다. 따라서 다음 값도 키 몇 번으로 바로 고를 수 있습니다. 옵션의 체크 표시도 유지되므로, 칩과 마찬가지로 목록에서도 무엇을 선택했는지 알 수 있습니다.

여러 값 선택

<div class="field max-w(360) mx-auto">  <label for="regions">Regions</label>  <div class="combobox">    <div class="input-group input-group-wrap">      <span class="chip" data-value="hnd">        Tokyo<input type="hidden" name="regions" value="hnd"><button type="button" class="chip-remove" tabindex="-1" aria-label="Remove Tokyo">          <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 4L12 12" /><path d="M4 12L12 4" />          </svg>        </button>      </span>      <input class="input-group-field" id="regions" role="combobox" aria-expanded="false" aria-controls="regions-list" aria-autocomplete="list" autocomplete="off" placeholder="Add a region">      <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" />        </svg>      </button>    </div>    <div id="regions-list" popover="manual" class="listbox" role="listbox" aria-label="Regions" aria-multiselectable="true">      <div class="listbox-option" role="option" data-value="hnd" aria-checked="true">Tokyo</div>      <div class="listbox-option" role="option" data-value="sin" aria-checked="false">        Singapore      </div>      <div class="listbox-option" role="option" data-value="fra" aria-checked="false">        Frankfurt      </div>      <div class="listbox-option" role="option" data-value="lhr" aria-checked="false">London</div>      <div class="listbox-option" role="option" data-value="iad" aria-checked="false">Virginia</div>      <div class="listbox-empty">No regions match.</div>    </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'import XIcon from '@master/icons-react/native/16/soft/x'import ChevronDownIcon from '@master/icons-react/native/16/soft/chevron-down'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="field max-w(360) mx-auto">      <label htmlFor="regions">Regions</label>      <div className="combobox">        <div className="input-group input-group-wrap">          <span className="chip" data-value="hnd">            Tokyo<input type="hidden" name="regions" value="hnd" /><button type="button" className="chip-remove" tabIndex={-1} aria-label="Remove Tokyo">              <XIcon className="icon" />            </button>          </span>          <input className="input-group-field" id="regions" role="combobox" aria-expanded="false" aria-controls="regions-list" aria-autocomplete="list" autoComplete="off" placeholder="Add a region" />          <button type="button" className="combobox-toggle" tabIndex={-1} aria-label="Show regions">            <ChevronDownIcon className="icon" />          </button>        </div>        <div id="regions-list" popover="manual" className="listbox" role="listbox" aria-label="Regions" aria-multiselectable="true">          <div className="listbox-option" role="option" data-value="hnd" aria-checked="true">Tokyo</div>          <div className="listbox-option" role="option" data-value="sin" aria-checked="false">            Singapore          </div>          <div className="listbox-option" role="option" data-value="fra" aria-checked="false">            Frankfurt          </div>          <div className="listbox-option" role="option" data-value="lhr" aria-checked="false">            London          </div>          <div className="listbox-option" role="option" data-value="iad" aria-checked="false">            Virginia          </div>          <div className="listbox-empty">No regions match.</div>        </div>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import XIcon from '@master/icons-svelte/native/16/soft/x'  import ChevronDownIcon from '@master/icons-svelte/native/16/soft/chevron-down'</script><div class="field max-w(360) mx-auto" {@attach attach}>  <label for="regions">Regions</label>  <div class="combobox">    <div class="input-group input-group-wrap">      <span class="chip" data-value="hnd">        Tokyo<input type="hidden" name="regions" value="hnd"><button type="button" class="chip-remove" tabindex="-1" aria-label="Remove Tokyo">          <XIcon class="icon" />        </button>      </span>      <input class="input-group-field" id="regions" role="combobox" aria-expanded="false" aria-controls="regions-list" aria-autocomplete="list" autocomplete="off" placeholder="Add a region">      <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">        <ChevronDownIcon class="icon" />      </button>    </div>    <div id="regions-list" popover="manual" class="listbox" role="listbox" aria-label="Regions" aria-multiselectable="true">      <div class="listbox-option" role="option" data-value="hnd" aria-checked="true">Tokyo</div>      <div class="listbox-option" role="option" data-value="sin" aria-checked="false">        Singapore      </div>      <div class="listbox-option" role="option" data-value="fra" aria-checked="false">        Frankfurt      </div>      <div class="listbox-option" role="option" data-value="lhr" aria-checked="false">London</div>      <div class="listbox-option" role="option" data-value="iad" aria-checked="false">Virginia</div>      <div class="listbox-empty">No regions match.</div>    </div>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import XIcon from '@master/icons-vue/native/16/soft/x'import ChevronDownIcon from '@master/icons-vue/native/16/soft/chevron-down'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="field max-w(360) mx-auto">    <label for="regions">Regions</label>    <div class="combobox">      <div class="input-group input-group-wrap">        <span class="chip" data-value="hnd">          Tokyo<input type="hidden" name="regions" value="hnd"><button type="button" class="chip-remove" tabindex="-1" aria-label="Remove Tokyo">            <XIcon class="icon" />          </button>        </span>        <input class="input-group-field" id="regions" role="combobox" aria-expanded="false" aria-controls="regions-list" aria-autocomplete="list" autocomplete="off" placeholder="Add a region">        <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show regions">          <ChevronDownIcon class="icon" />        </button>      </div>      <div id="regions-list" popover="manual" class="listbox" role="listbox" aria-label="Regions" aria-multiselectable="true">        <div class="listbox-option" role="option" data-value="hnd" aria-checked="true">Tokyo</div>        <div class="listbox-option" role="option" data-value="sin" aria-checked="false">          Singapore        </div>        <div class="listbox-option" role="option" data-value="fra" aria-checked="false">          Frankfurt        </div>        <div class="listbox-option" role="option" data-value="lhr" aria-checked="false">London</div>        <div class="listbox-option" role="option" data-value="iad" aria-checked="false">          Virginia        </div>        <div class="listbox-empty">No regions match.</div>      </div>    </div>  </div></template>
지역을 몇 개 선택해 보세요. 빈 필드에서 Backspace 키를 누르면 마지막 칩으로 이동하고, 한 번 더 누르면 그 칩이 삭제됩니다.
  • 필드는 검색에만 사용합니다. 텍스트를 입력하면 목록이 필터링될 뿐, 체크 표시가 해제되지는 않습니다. 선택한 값은 칩이 유지합니다.
  • 칩. 탭 순서에서 멈추는 곳은 필드 하나뿐입니다. 빈 필드에서 Backspace 키를 누르거나 뒤쪽을 가리키는 방향키를 누르면 칩으로 이동하며, 칩에서 사용하는 키는 태그 입력과 같습니다. 칩의 버튼이나 Backspace 키로 칩을 삭제하면 해당 옵션의 체크 표시도 해제됩니다.
  • 폼. 기존 칩에 name이 있는 숨겨진 입력 요소가 이미 들어 있거나 name 옵션을 지정하면, 동작이 작성하는 칩에도 값을 담은 숨겨진 입력 요소가 포함됩니다. removeLabel은 페이지 언어로 칩의 삭제 버튼 이름을 지정합니다.
  • 값은 선택한 값을 선택한 순서대로 담은 목록입니다.

목록에서 고르지 않고 값을 자유롭게 입력해야 한다면 태그 입력을 사용하세요.

#자동 완성

일치 항목을 서버에서 가져오거나 페이지 자체의 검색으로 찾는다면 filter: false로 동작을 연결하세요. 동작은 아무것도 숨기지 않습니다. 필드에서 input이 발생할 때마다 query를 읽어 검색하고, 일치 항목을 목록의 옵션으로 작성하세요. 입력에 대한 응답이 늦게 도착해도 도착한 옵션 중 하나가 활성 옵션으로 지정되므로, Enter 키와 방향키로 조작할 수 있습니다.

자동 완성

<div class="field max-w(320) mx-auto">  <label for="city">City</label>  <div class="combobox" id="city-combobox">    <div class="input-group">      <input class="input-group-field" id="city" role="combobox" aria-expanded="false" aria-controls="city-list" aria-autocomplete="list" autocomplete="off" placeholder="Start typing a city">      <button type="button" class="combobox-toggle" tabindex="-1" aria-label="Show cities">        <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">          <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" />        </svg>      </button>    </div>    <div id="city-list" popover="manual" class="listbox" role="listbox" aria-label="Cities">      <div class="listbox-empty">No cities start with that.</div>    </div>  </div></div><script>addEventListener('DOMContentLoaded', function () {var root = document.getElementById('city-combobox')var list = document.getElementById('city-list')var cities = ['Amsterdam', 'Athens', 'Auckland', 'Bangkok', 'Barcelona', 'Berlin', 'Bogotá', 'Boston', 'Brussels', 'Buenos Aires', 'Cairo', 'Cape Town', 'Chicago', 'Copenhagen', 'Dublin', 'Frankfurt', 'Helsinki', 'Hong Kong', 'Istanbul', 'Lisbon', 'London', 'Los Angeles', 'Madrid', 'Melbourne', 'Mexico City', 'Montreal', 'Mumbai', 'Nairobi', 'New York', 'Oslo', 'Paris', 'Prague', 'Rome', 'San Francisco', 'Santiago', 'São Paulo', 'Seoul', 'Singapore', 'Stockholm', 'Sydney', 'Taipei', 'Tokyo', 'Toronto', 'Vienna', 'Warsaw', 'Zurich']var box = MasterUI.combobox(root, { filter: false })var asked = 0// Stands for a request to a server: the cities that start with the query, a moment later.function search(query) {  return new Promise(function (resolve) {    setTimeout(function () {      var text = query.trim().toLowerCase()      resolve(cities.filter(function (city) { return city.toLowerCase().startsWith(text) }).slice(0, 6))    }, 120)  })}function write(matches) {  list.querySelectorAll('.listbox-option').forEach(function (option) { option.remove() })  matches.forEach(function (city) {    var option = document.createElement('div')    option.className = 'listbox-option'    option.setAttribute('role', 'option')    option.setAttribute('aria-checked', 'false')    option.textContent = city    list.insertBefore(option, list.querySelector('.listbox-empty'))  })}root.addEventListener('input', function (event) {  // A choice says input too; its text is the option's, with nothing more to look for.  if (event.target.getAttribute('role') !== 'combobox' || box.value !== null) return  var ticket = ++asked  search(box.query).then(function (matches) {    // An answer to an older query that arrives late is dropped.    if (ticket === asked) write(matches)  })})search('').then(write)})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
몇 글자를 입력해 보세요. 페이지가 검색어로 검색한 뒤 잠시 후 옵션을 작성합니다. 방향키와 Enter 키로 옵션을 선택하세요.
  • 이벤트가 아니라 query를 읽으세요. 검색어는 필드의 텍스트입니다. 사용자가 입력했든 프레임워크가 작성했든 query는 같은 방식으로 이 텍스트를 읽습니다.
  • 옵션을 선택해도 input이 발생합니다. 이때 텍스트는 선택한 옵션의 텍스트이며, value는 더 이상 null이 아닙니다. 검색할 내용이 없으며, 이때 새 옵션을 작성하면 선택한 옵션이 사라집니다.
  • 응답은 순서가 뒤바뀌어 도착할 수 있습니다. 가장 최근 검색어에 대한 응답만 사용하세요.
  • 빈 상태는 스타일시트가 처리합니다. 목록에 옵션이 없는 동안 listbox-empty가 자동으로 표시됩니다.

React, Svelte, Vue에서는 컴포넌트의 query와 onQueryChange(Svelte에서는 바인딩 가능한 query, Vue에서는 v-model:query)가 같은 텍스트를 전달합니다. 이 텍스트로 검색하고, filter를 false로 설정한 뒤 일치 항목을 options로 전달하세요.

#컨트롤 선택 기준

단순한 옵션이 12개 이하라면 셀렉트에서 스크립트 없이 플랫폼 기본 기능으로 글자를 입력해 옵션을 찾을 수 있습니다. 목록이 길어 검색이 필요하거나, 입력에 따라 옵션을 불러오거나, 각 행에 부가 설명 등 다양한 콘텐츠를 표시해야 할 때는 콤보박스를 사용하세요.

#키보드 조작

키보드 입력은 연결한 동작에서 처리합니다. 목록이 닫혀 있거나 Shift 키를 누른 상태에서는 Home과 End 키가 일반 입력 필드에서처럼 캐럿을 이동합니다. 활성 옵션이 없으면 Enter 키의 기본 동작을 그대로 두므로 양식을 제출할 수 있습니다.

키동작
ArrowDown, ArrowUp목록을 열고 활성 항목을 바꿉니다. 양 끝을 지나면 반대쪽 끝으로 이동합니다.
Home, End목록이 열려 있는 동안 첫 번째 또는 마지막 옵션으로 이동합니다.
Enter활성 옵션을 선택하고 목록을 닫습니다. 여러 값을 선택하는 경우에는 옵션의 체크 상태를 전환하고 목록을 열어 둡니다.
Escape목록을 닫습니다. 입력 필드의 텍스트는 그대로 유지됩니다.
Typing옵션을 필터링하고 첫 번째 일치 항목을 활성 상태로 두어 목록을 엽니다.
Backspace여러 값을 선택하는 경우, 빈 필드에서는 마지막 칩으로 이동합니다. 칩에서는 해당 옵션의 체크를 해제하고 이전 칩으로 이동합니다. 첫 번째 칩이었다면 다음 칩으로, 남은 칩이 없으면 필드로 이동합니다.
Delete여러 값을 선택하는 경우, 칩에서는 해당 옵션의 체크를 해제하고 다음 칩으로 이동합니다. 마지막 칩이었다면 필드로 이동합니다.
ArrowLeft, ArrowRight여러 값을 선택하는 경우, 태그 입력과 마찬가지로 필드의 시작 위치에서 칩 사이를 이동합니다.
Home, End여러 값을 선택하는 경우, 칩에서는 첫 번째 칩으로 이동하거나 필드로 돌아갑니다.
Escape여러 값을 선택하는 경우, 칩에서는 필드로 돌아갑니다.

#접근성

  • 입력 요소에는 role="combobox", 목록 상자를 가리키는 aria-controls, aria-autocomplete="list", aria-expanded 속성이 설정됩니다.
  • 포커스는 입력 요소에 유지되며, 스크린 리더는 aria-activedescendant 속성을 통해 활성 옵션을 읽어 줍니다.
  • 필드에서 방향키로 목록을 열 수 있으므로 tabindex="-1"을 설정해 토글 버튼을 탭 순서에서 제외하세요.
  • 브라우저의 자체 추천 항목이 목록을 가리지 않도록 autocomplete="off"로 설정하세요.

#React, Svelte, Vue

combobox 컴포넌트는 옵션 목록을 바탕으로 이 마크업을 렌더링하고 동작을 연결하며, 선택한 값을 받아 외부로 전달할 수 있습니다. multiple을 지정하면 값이 목록이 되고, 컴포넌트가 그 값으로 칩을 작성합니다. group이 있는 옵션은 해당 캡션 아래, listbox-label로 레이블이 지정되고 role="group"이 있는 listbox-group 안에 작성됩니다. 그룹의 옵션이 모두 필터링되면 그룹도 함께 숨겨집니다. 컴포넌트는 값 외에 검색어도 전달합니다. React에서는 query와 onQueryChange, Svelte에서는 onQueryChange와 함께 쓰는 바인딩 가능한 query, Vue에서는 v-model:query를 사용합니다. 검색어는 사용자가 입력할 때마다 전달되며, 옵션을 선택하면 선택 값을 전달한 뒤 검색어를 전달합니다. 외부에서 지정한 검색어는 필드에 반영되며, 그 검색어로 옵션을 필터링합니다. npx master-ui add combobox 명령을 실행해 프로젝트에 복사하세요. 컴포넌트의 구성과 사용 방법은 React, Svelte, Vue에서 확인할 수 있습니다.

ui/combobox.tsx
'use client'import { useEffect, useId, useRef, useState, type ComponentProps, type ReactNode } from 'react'import { combobox } from '@master/ui/behaviors/combobox.js'import { useBehavior } from './use-behavior'export interface ComboboxOption {  /** What choosing the option gives `onValueChange`. */  value: string  /** What the option says, and what the field holds once it is chosen. */  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}interface Shared extends Omit<ComponentProps<'input'>, 'value' | 'defaultValue' | 'role' | 'multiple' | 'name'> {  options: ComboboxOption[]  /**   * The text in the field, what the reader is looking for: written into the field each time it changes.   * It is not the value; with one value it holds the chosen option's label once one is chosen.   */  query?: string  /** Called with the text in the field each time the reader changes it, by typing or by choosing. */  onQueryChange?: (query: string) => void  /** False when `options` are already the matches: search for `query` and give the matches as `options`. */  filter?: boolean  /** The name of the list, for assistive technology. */  listLabel: string  /** The name of the button that opens the list. */  toggleLabel: string  /** What the list says when no option matches. */  empty?: ReactNode}interface One extends Shared {  multiple?: false  /** The value of the chosen option; null while the field holds text no option was chosen for. */  value?: string | null  defaultValue?: string | null  onValueChange?: (value: string | null) => void}interface Several extends Shared {  /** Several values, each a chip in the field. */  multiple: true  /** The chosen values, in the order they were chosen. */  value?: string[]  defaultValue?: string[]  onValueChange?: (value: string[]) => void  /** The name each value is submitted with, in a hidden input of its chip. */  name?: string  /** The accessible name of a chip's remove button. `Remove <label>` by default. */  removeLabel?: (label: string) => string}export type ComboboxProps = One | Several/** * A combobox. Name the field with `aria-label`, or give it an `id` a label points at; every other prop of * an input goes to the field, so `onChange` hears what is typed. With `multiple`, the chosen values are * chips in the field, which React writes from the value. */export function Combobox(props: ComboboxProps) {  const { options, value, defaultValue, onValueChange, query, onQueryChange, filter = true, listLabel, toggleLabel, empty, className, multiple, ...rest } = props  const { name, removeLabel = (label: string) => `Remove ${label}`, ...field } = rest as Omit<Several, keyof Shared | 'multiple' | 'value' | 'defaultValue' | 'onValueChange'> & ComponentProps<'input'>  const id = useId()  const handle = useRef<ReturnType<typeof combobox> | null>(null)  /** The last query the owner gave or was told. */  const known = useRef<string | undefined>(undefined)  const heard = useRef(onQueryChange)  useEffect(() => { heard.current = onQueryChange })  const [first] = useState(value ?? defaultValue)  const [firstQuery] = useState(query)  const [chips, setChips] = useState<string[]>(() => (multiple ? [first ?? []].flat() as string[] : []))  const ref = useBehavior(combobox, multiple ? { filter, draw: setChips, removeLabel } : { filter }, {    value,    defaultValue,    onValueChange,    attached: (attached: unknown) => { handle.current = attached as ReturnType<typeof combobox> | null },    on: {      input: () => {        const next = handle.current?.query        if (next === undefined || next === known.current) return        heard.current?.(known.current = next)      },    },  } as never)  /** Where the first render drew a chosen option's name, that is what the field says: only a query given later is written over it. */  const drawn = useRef(false)  useEffect(() => {    if (!drawn.current) {      drawn.current = true      if (!multiple && options.some(option => option.value === first)) {        known.current = query        return      }    }    if (query === undefined || query === known.current || !handle.current) return    handle.current.query = known.current = query  }, [query])  const chosen = (option: ComboboxOption) => (multiple ? [first ?? []].flat().includes(option.value) : option.value === first)  const labelOf = (each: string) => options.find(option => option.value === each)?.label ?? each  const groups = [...new Set(options.map(option => option.group))]  return (    <div className={className ? `combobox ${className}` : 'combobox'} ref={ref}>      <div className={multiple ? 'input-group input-group-wrap' : 'input-group'}>        {multiple && (value !== undefined ? value as string[] : chips).map(each => (          <span className="chip" data-value={each} key={each}>            {labelOf(each)}            {name && <input type="hidden" name={name} value={each} />}            <button type="button" className="chip-remove" tabIndex={-1} aria-label={removeLabel(labelOf(each))}><svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M4 4L12 12" /><path d="M4 12L12 4" /></svg></button>          </span>        ))}        <input className="input-group-field" role="combobox" aria-expanded="false" aria-controls={`${id}list`} aria-autocomplete="list" autoComplete="off" defaultValue={(multiple ? undefined : options.find(option => option.value === first)?.label) ?? firstQuery} {...field} />        <button type="button" className="combobox-toggle" tabIndex={-1} aria-label={toggleLabel}><svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /></svg></button>      </div>      <div id={`${id}list`} popover="manual" className="listbox" role="listbox" aria-label={listLabel} aria-multiselectable={multiple || undefined}>        {groups.map((group, index) => {          const rows = options.filter(option => option.group === group).map(option => (            <div className="listbox-option" role="option" key={option.value} data-value={option.value} aria-checked={chosen(option)} 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 group === undefined            ? rows            : (                <div className="listbox-group" role="group" aria-labelledby={`${id}group${index}`} key={group}>                  <div className="listbox-label" id={`${id}group${index}`}>{group}</div>                  {rows}                </div>              )        })}        {empty !== undefined && <div className="listbox-empty">{empty}</div>}      </div>    </div>  )}
ui/Combobox.svelte
<script lang="ts" module>  import type { HTMLInputAttributes } from 'svelte/elements'  export interface ComboboxOption {    /** What choosing the option gives `onValueChange`. */    value: string    /** What the option says, and what the field holds once it is chosen. */    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 ComboboxProps extends Omit<HTMLInputAttributes, 'value' | 'role' | 'children' | 'multiple' | 'name'> {    options: ComboboxOption[]    /**     * The value of the chosen option; null while the field holds text no option was chosen for. With     * `multiple`, the chosen values in the order they were chosen. Bind it, or leave it out.     */    value?: string | string[] | null    onValueChange?: (value: string | string[] | null) => void    /**     * The text in the field, what the reader is looking for. Bind it, or leave it out. It is not the value;     * with one value it holds the chosen option's label once one is chosen.     */    query?: string    /** Called with the text in the field each time the reader changes it, by typing or by choosing. */    onQueryChange?: (query: string) => void    /** Several values, each a chip in the field. */    multiple?: boolean    /** With `multiple`: the name each value is submitted with, in a hidden input of its chip. */    name?: string    /** With `multiple`: the accessible name of a chip's remove button. `Remove <label>` by default. */    removeLabel?: (label: string) => string    /** False when `options` are already the matches: search for `query` and give the matches as `options`. */    filter?: boolean    /** The name of the list, for assistive technology. */    listLabel: string    /** The name of the button that opens the list. */    toggleLabel: string    /** What the list says when no option matches. */    empty?: string  }</script><script lang="ts">  import { untrack } from 'svelte'  import { combobox } from '@master/ui/behaviors/combobox.js'  import { behavior } from './behavior.svelte.js'  let { options, value = $bindable(), onValueChange, query = $bindable(), onQueryChange, multiple, name, removeLabel = (label: string) => `Remove ${label}`, filter = true, listLabel, toggleLabel, empty, class: className, ...field }: ComboboxProps = $props()  const id = $props.id()  const first = untrack(() => value)  const several = untrack(() => multiple)  const firsts = [first ?? []].flat() as string[]  // An option written later, from new options, is drawn with the value as it is then, which is not read as state.  const chosen = { values: firsts }  const text = (several ? undefined : untrack(() => options.find(option => option.value === first)?.label)) ?? untrack(() => query)  // With several values the behavior asks for the chips it wants; Svelte writes them from this list.  let chips = $state(several ? firsts : [])  const labelOf = (each: string) => options.find(option => option.value === each)?.label ?? each  const groups = $derived([...new Set(options.map(option => option.group))])  let handle = $state.raw<ReturnType<typeof combobox> | null>(null)  /** The last query the owner gave or was told. The first render drew the field, so the first query is known. */  let known: string | undefined = untrack(() => (!several && options.some(option => option.value === first) ? query : undefined))  const attach = behavior(combobox, () => (multiple ? { filter, removeLabel, draw: (values: string[]) => { chips = values } } : { filter }), {    value: () => value,    change: (next) => { chosen.values = [next ?? []].flat(); value = next; onValueChange?.(next) },    settled: (held) => { chosen.values = [held ?? []].flat() },    attached: (attached) => { handle = attached as ReturnType<typeof combobox> | null },    on: {      input: () => {        const next = handle?.query        if (next === undefined || next === known) return        query = known = next        onQueryChange?.(next)      },    },  })  $effect(() => {    const next = query    if (next === undefined || !handle || next === known) return    handle.query = known = next  })</script>{#snippet row(option: ComboboxOption)}  <!-- 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 combobox. Name the field with `aria-label`, or give it an `id` a label points at; every other prop of  an input goes to the field, so `oninput` hears what is typed. With `multiple`, the chosen values are chips  in the field.--><div class={['combobox', className]} {@attach attach}>  <div class={several ? 'input-group input-group-wrap' : 'input-group'}>    {#each chips as each (each)}      <span class="chip" data-value={each}>        {labelOf(each)}        {#if name}<input type="hidden" {name} value={each} />{/if}        <button type="button" class="chip-remove" tabindex={-1} aria-label={removeLabel(labelOf(each))}><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 4L12 12" /><path d="M4 12L12 4" /></svg></button>      </span>    {/each}    <input class="input-group-field" role="combobox" aria-expanded="false" aria-controls="{id}list" aria-autocomplete="list" autocomplete="off" value={text} {...field} />    <button type="button" class="combobox-toggle" tabindex={-1} aria-label={toggleLabel}><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /></svg></button>  </div>  <div id="{id}list" popover="manual" class="listbox" role="listbox" aria-label={listLabel} aria-multiselectable={several || undefined}>    {#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}    {#if empty !== undefined}<div class="listbox-empty">{empty}</div>{/if}  </div></div>
ui/Combobox.vue
<script lang="ts">export interface ComboboxOption {  /** What choosing the option gives the model. */  value: string  /** What the option says, and what the field holds once it is chosen. */  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, onMounted, ref, useAttrs, useId, useTemplateRef, watch, type FunctionalComponent } from 'vue'import { combobox } from '@master/ui/behaviors/combobox.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { options, filter = true, multiple, removeLabel = (label: string) => `Remove ${label}` } = defineProps<{  options: ComboboxOption[]  /** False when `options` are already the matches: search for the query and give the matches as `options`. */  filter?: boolean  /** Several values, each a chip in the field; the model is then the list of them. */  multiple?: boolean  /** With `multiple`: the name each value is submitted with, in a hidden input of its chip. */  name?: string  /** With `multiple`: the accessible name of a chip's remove button. `Remove <label>` by default. */  removeLabel?: (label: string) => string  /** The name of the list, for assistive technology. */  listLabel: string  /** The name of the button that opens the list. */  toggleLabel: string  /** What the list says when no option matches. */  empty?: string}>()/** * The value of the chosen option; null while the field holds text no option was chosen for. With * `multiple`, the chosen values in the order they were chosen: `v-model`. */const model = defineModel<string | string[] | null>()/** * The text in the field, what the reader is looking for: `v-model:query`. It is not the value; with one value * it holds the chosen option's label once one is chosen. */const query = defineModel<string>('query')/* * A combobox. Name the field with `aria-label`, or give it an `id` a label points at; every attribute but * the class goes to the field, so `@input` hears what is typed. With `multiple`, the chosen values are chips in * the field, which Vue writes from the list the behavior asks for. */const id = useId()const attrs = useAttrs()const field = () => {  const { class: _, ...rest } = attrs  return rest}const first = model.valueconst firsts = [first ?? []].flat() as string[]const several = multiple// The first label is the field's default value, an attribute: what is typed after is not Vue's to write.const firstLabel = (several ? undefined : options.find(option => option.value === first)?.label) ?? query.value// With several values the behavior asks for the chips it wants; Vue writes them from this list.const chips = ref<string[]>(several ? firsts : [])const labelOf = (each: string) => options.find(option => option.value === each)?.label ?? eachconst checked = (option: ComboboxOption) => (several ? firsts.includes(option.value) : option.value === first)const root = useTemplateRef<HTMLDivElement>('root')/** The last query the owner gave or was told. */// The first render drew the field, the chosen option's name before the query: the first query is known.let known: string | undefined = !several && options.some(option => option.value === first) ? query.value : undefinedconst behavior = useBehavior(root, combobox, () => (multiple ? { filter, removeLabel, draw: (values: string[]) => { chips.value = values } } : { filter }), model, {  input: () => {    const next = handle()?.query    if (next === undefined || next === known) return    query.value = known = next  },})const handle = () => behavior.handle() as ReturnType<typeof combobox> | undefined/** Query in: a query the owner gives is written into the field, and filters the options as typing does. */const write = () => {  const given = query.value  const current = handle()  if (given === undefined || !current || given === known) return  current.query = known = given}onMounted(write)watch(query, write, { flush: 'post' })const groups = computed(() => [...new Set(options.map(option => option.group))])const Row: FunctionalComponent<{ option: ComboboxOption }> = ({ option }) => h('div', {  'class': 'listbox-option',  'role': 'option',  'data-value': option.value,  'aria-checked': checked(option),  '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="combobox" :class="$attrs.class" ref="root">    <div :class="several ? 'input-group input-group-wrap' : 'input-group'">      <span v-for="each in chips" :key="each" class="chip" :data-value="each">        {{ labelOf(each) }}        <input v-if="name" type="hidden" :name="name" :value="each">        <button type="button" class="chip-remove" tabindex="-1" :aria-label="removeLabel(labelOf(each))"><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 4L12 12" /><path d="M4 12L12 4" /></svg></button>      </span>      <input class="input-group-field" role="combobox" aria-expanded="false" :aria-controls="`${id}-list`" aria-autocomplete="list" autocomplete="off" :value.attr="firstLabel" v-bind="field()">      <button type="button" class="combobox-toggle" tabindex="-1" :aria-label="toggleLabel"><svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(90 8 8)" /></svg></button>    </div>    <div :id="`${id}-list`" popover="manual" class="listbox" role="listbox" :aria-label="listLabel" :aria-multiselectable="several || undefined">      <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 v-if="empty !== undefined" class="listbox-empty">{{ empty }}</div>    </div>  </div></template>

#클래스

클래스설명
combobox입력 필드를 기준으로 목록 상자의 위치를 잡는 래퍼
combobox-toggle필드 끝에서 목록을 열고 닫는 버튼으로, 꺾쇠 아이콘을 담습니다

input-group, input-group-field, 그리고 popover 속성이 있는 listbox와 함께 사용합니다.

콤보박스는 다음 컴포넌트로 구성되며, 각 컴포넌트는 자체 클래스와 상태를 유지합니다.

#소스 코드

@master/ui/components/combobox.css
/* * Combobox: a text field that opens a listbox of matches. * The wrapper names itself as an anchor and scopes that name, so its listbox opens against the whole field * and takes at least its width, with no measuring. Filtering, the active option and the popover's open state * belong to the script; the stylesheet reads aria-expanded to turn the chevron. */@layer components.ui {  .combobox {    display: block;    min-width: 0;    anchor-name: --combobox;    anchor-scope: --combobox;    /*     * The list. Without anchor positioning it stays where it is in the flow, directly under the field,     * which is why it is written after the field in the markup.     */    .listbox[popover] {      position-anchor: --combobox;      inset: auto;      margin: 6px 0;      min-inline-size: anchor-size(--combobox inline);    }    /* With several values, a chosen value grows out of the field it was chosen from, as in a tags field. */    .input-group-wrap .chip {      transform-origin: 100% 50%;      transition-property: opacity, scale;      transition-duration: var(--duration-quick);      transition-timing-function: var(--easing-glide);      /* The field is at the line's end, so right to left it stands on the left. */      &:dir(rtl) {        transform-origin: 0 50%;      }      @starting-style {        opacity: 0;        scale: .8;      }      @media (prefers-reduced-motion: reduce) {        transition-property: opacity;        @starting-style {          scale: 1;        }      }    }  }  /* The button that opens the list from the field's end: a chevron that turns over while the list is open. */  .combobox-toggle {    position: relative;    display: inline-grid;    flex: none;    place-items: center;    width: 1.5rem;    height: 1.5rem;    /* Its chevron ends 2px inside the field's padding at every size, where a select's chevron ends. */    margin-block: 0;    margin-inline: 0 -.4375rem;    padding: 0;    border: 0;    border-radius: calc((var(--radius-chip) - 2px) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: transparent;    -webkit-tap-highlight-color: transparent;    color: var(--color-text-muted);    appearance: none;    cursor: pointer;    /* The glyph is the button's icon. It takes no pointer of its own, so a press is the button's. */    .icon {      pointer-events: none;      width: .875rem;      height: .875rem;      transition: rotate var(--duration-base) var(--easing-glide);    }    @media (hover: hover) {      &:hover:not(:disabled) {        color: var(--color-text-strong);      }    }    /* Pressed: the strong ink, as under the pointer. */    &:active:not(:disabled) {      color: var(--color-text-strong);    }    /* Disabled with its field: the chevron takes the field's disabled ink and answers no pointer. */    &:disabled, .combobox:has(.input-group-field:disabled) & {      color: var(--color-text-disabled);      cursor: not-allowed;    }    /* A read-only field opens no list either: the chevron keeps its quiet ink under the pointer and offers no press. */    .combobox:has(.input-group-field[readonly]:not(:disabled)) &:not(:disabled) {      color: var(--color-text-muted);      cursor: default;    }    &:focus-visible {      @apply --focus-ring;      outline-offset: 0;    }    @media (prefers-reduced-motion: reduce) {      .icon {        transition: none;      }    }    @media (forced-colors: active) {      .icon {        color: ButtonText;      }      &:disabled .icon, .combobox:has(.input-group-field:disabled) & .icon {        color: GrayText;      }    }    /* On touch the target reaches 44px around the toggle, which keeps its size, and so does the field. */    @media (pointer: coarse) {      &::after {        @apply --touch-target;      }    }  }  .combobox:has([aria-expanded="true"]) .combobox-toggle .icon {    rotate: x 180deg;  }}