Select
ボタンをトリガーとして、ユーザーが選択できるオプションのリストを表示します。
SelectはSelect-Only Combobox WAI-ARIAデザインパターンに従っています。
ネイティブの<select>で十分な場合はField.Select(Field)を、入力なしのカスタムスタイルドロップダウンにはSelectを、ユーザーが入力して選択肢を絞り込む必要がある場合はComboboxを使用してください。
Selected: none
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './default.css?inline';
const FRUITS = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'blueberry', label: 'Blueberry' },
{ value: 'cherry', label: 'Cherry' },
{ value: 'grape', label: 'Grape' },
{ value: 'lemon', label: 'Lemon', disabled: true },
{ value: 'orange', label: 'Orange' },
{ value: 'peach', label: 'Peach' },
];
export default component$(() => {
useStyles$(styles);
const value = useSignal<string | null>(null);
return (
<div class="select-default">
<Select.Root bind:value={value} class="select-default-root">
<Select.Label class="select-default-label">Fruit</Select.Label>
<Select.Trigger class="select-default-trigger">
<Select.Value placeholder="Select a fruit" class="select-default-value" />
<LuChevronDown aria-hidden="true" class="select-default-icon" />
</Select.Trigger>
<Select.Content sideOffset={4} class="select-default-content">
<Select.List>
{FRUITS.map((fruit) => (
<Select.Item
key={fruit.value}
value={fruit.value}
disabled={fruit.disabled}
class="select-default-item"
>
<Select.ItemText>{fruit.label}</Select.ItemText>
<Select.ItemIndicator class="select-default-indicator">
<LuCheck aria-hidden="true" class="select-default-icon" />
</Select.ItemIndicator>
</Select.Item>
))}
</Select.List>
</Select.Content>
</Select.Root>
<p class="select-default-status">Selected: {value.value ?? 'none'}</p>
</div>
);
});.select-default {
display: flex;
flex-direction: column;
gap: 12px;
font-family: inherit;
}
.select-default-root {
display: flex;
flex-direction: column;
gap: 6px;
width: 240px;
}
.select-default-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.select-default-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
padding: 8px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 14px;
cursor: pointer;
text-align: left;
}
.select-default-trigger:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-default-trigger:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-default-value[data-placeholder] {
color: light-dark(#475569, #c9ddf0);
}
.select-default-icon {
flex-shrink: 0;
width: 16px;
height: 16px;
}
/* The Content is a popover in the top layer; the library sets its position */
.select-default-content {
box-sizing: border-box;
width: var(--leve-select-anchor-width);
max-height: min(240px, var(--leve-select-available-height));
overflow-y: auto;
padding: 4px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
box-shadow: 0 8px 24px rgb(15 23 42 / 0.18);
}
.select-default-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: 4px;
font-size: 14px;
cursor: default;
}
/* Arrow keys, typeahead, and pointer hover move the highlight while focus stays on Trigger */
.select-default-item[data-highlighted] {
background: #009dfd;
color: #ffffff;
}
.select-default-item[data-disabled] {
opacity: 0.5;
cursor: not-allowed;
}
.select-default-indicator {
display: inline-flex;
}
.select-default-indicator[hidden] {
display: none;
}
.select-default-status {
margin: 0;
font-size: 14px;
color: light-dark(#475569, #c9ddf0);
}インストール#
個別のパッケージをインストールするか、@leve-ui/coreを使用してすべてのコンポーネントをまとめて取得します。
pnpm add @leve-ui/selectnpm install @leve-ui/selectyarn add @leve-ui/selectbun add @leve-ui/selectpnpm add @leve-ui/corenpm install @leve-ui/coreyarn add @leve-ui/corebun add @leve-ui/core構造#
import { Select } from '@leve-ui/select'; // or '@leve-ui/core'
<Select.Root>
<Select.Label />
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<Select.HiddenInput />
<Select.Content>
<Select.List>
<Select.Item>
<Select.ItemText />
<Select.ItemIndicator />
</Select.Item>
<Select.Group>
<Select.GroupLabel />
<Select.Item />
</Select.Group>
</Select.List>
</Select.Content>
</Select.Root>
| パーツ | 要素 | 説明 |
|---|---|---|
Select.Root | <div> | パーツをラップし、選択された値と開閉状態を保持します。 |
Select.Label | <label> | トリガーのラベルおよびリストボックスのアクセシブルな名前です。 |
Select.Trigger | <button> | リストボックスを切り替えるrole="combobox"を持つボタンです。フォーカスはここに留まります。 |
Select.Value | <span> | 選択されたオプションのテキストまたはプレースホルダーを表示します。 |
Select.HiddenInput | <input> | 任意です。ネイティブの<form>で選択された値を送信します。 |
Select.Content | <div> | ポップアップです。トップレイヤーに配置されるpopover="manual"要素です。 |
Select.List | <div> | リストボックス(role="listbox")です。 |
Select.Item | <div> | オプション(role="option")です。 |
Select.ItemText | <span> | オプションが選択されたときにSelect.Valueに表示されるテキストです。 |
Select.ItemIndicator | <span> | 選択されたオプションのチェックマークです。それ以外の場合は非表示になります。 |
Select.Group | <div> | オプションのグループです。GroupLabelによって名前が付けられます。 |
Select.GroupLabel | <div> | グループの名前です。選択できません。 |
使用例#
グループとループ#
Select.GroupとSelect.GroupLabelでオプションをラベル付きのグループに整理します。loopを使用すると、矢印キーで最初と最後のオプション間をループできます。
import { component$, useStyles$ } from '@builder.io/qwik';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './grouped.css?inline';
const TIMEZONES = [
{ region: 'Americas', zones: ['New York', 'Chicago', 'Los Angeles'] },
{ region: 'Europe', zones: ['London', 'Paris', 'Berlin'] },
{ region: 'Asia', zones: ['Tokyo', 'Seoul', 'Singapore'] },
];
export default component$(() => {
useStyles$(styles);
return (
<Select.Root loop class="select-grouped">
<Select.Label class="select-grouped-label">Time zone</Select.Label>
<Select.Trigger class="select-grouped-trigger">
<Select.Value placeholder="Select a time zone" class="select-grouped-value" />
<LuChevronDown aria-hidden="true" class="select-grouped-icon" />
</Select.Trigger>
<Select.Content sideOffset={4} class="select-grouped-content">
<Select.List>
{TIMEZONES.map((group) => (
<Select.Group key={group.region}>
<Select.GroupLabel class="select-grouped-group-label">
{group.region}
</Select.GroupLabel>
{group.zones.map((zone) => (
<Select.Item key={zone} value={zone} class="select-grouped-item">
<Select.ItemText>{zone}</Select.ItemText>
<Select.ItemIndicator class="select-grouped-indicator">
<LuCheck aria-hidden="true" class="select-grouped-icon" />
</Select.ItemIndicator>
</Select.Item>
))}
</Select.Group>
))}
</Select.List>
</Select.Content>
</Select.Root>
);
});.select-grouped {
display: flex;
flex-direction: column;
gap: 6px;
width: 240px;
font-family: inherit;
}
.select-grouped-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.select-grouped-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
padding: 8px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 14px;
cursor: pointer;
text-align: left;
}
.select-grouped-trigger:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-grouped-trigger:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-grouped-value[data-placeholder] {
color: light-dark(#475569, #c9ddf0);
}
.select-grouped-icon {
flex-shrink: 0;
width: 16px;
height: 16px;
}
/* The Content is a popover in the top layer; the library sets its position */
.select-grouped-content {
box-sizing: border-box;
width: var(--leve-select-anchor-width);
max-height: min(240px, var(--leve-select-available-height));
overflow-y: auto;
padding: 4px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
box-shadow: 0 8px 24px rgb(15 23 42 / 0.18);
}
.select-grouped-group-label {
padding: 6px 8px 2px;
font-size: 12px;
font-weight: 600;
color: light-dark(#475569, #c9ddf0);
}
.select-grouped-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: 4px;
font-size: 14px;
cursor: default;
}
.select-grouped-item[data-highlighted] {
background: #009dfd;
color: #ffffff;
}
.select-grouped-indicator {
display: inline-flex;
}
.select-grouped-indicator[hidden] {
display: none;
}無効化#
Select.Rootにdisabledを指定すると開くことができなくなり、Select.TriggerとSelect.HiddenInputが無効になります。
import { component$, useStyles$ } from '@builder.io/qwik';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './disabled.css?inline';
export default component$(() => {
useStyles$(styles);
return (
<Select.Root disabled defaultValue="starter" class="select-disabled">
<Select.Label class="select-disabled-label">Plan</Select.Label>
<Select.Trigger class="select-disabled-trigger">
<Select.Value placeholder="Choose a plan" />
<LuChevronDown aria-hidden="true" class="select-disabled-icon" />
</Select.Trigger>
<Select.Content sideOffset={4} class="select-disabled-content">
<Select.List>
<Select.Item value="free" class="select-disabled-item">
<Select.ItemText>Free</Select.ItemText>
<Select.ItemIndicator class="select-disabled-indicator">
<LuCheck aria-hidden="true" class="select-disabled-icon" />
</Select.ItemIndicator>
</Select.Item>
<Select.Item value="starter" class="select-disabled-item">
<Select.ItemText>Starter</Select.ItemText>
<Select.ItemIndicator class="select-disabled-indicator">
<LuCheck aria-hidden="true" class="select-disabled-icon" />
</Select.ItemIndicator>
</Select.Item>
<Select.Item value="pro" class="select-disabled-item">
<Select.ItemText>Pro</Select.ItemText>
<Select.ItemIndicator class="select-disabled-indicator">
<LuCheck aria-hidden="true" class="select-disabled-icon" />
</Select.ItemIndicator>
</Select.Item>
</Select.List>
</Select.Content>
</Select.Root>
);
});.select-disabled {
display: flex;
flex-direction: column;
gap: 6px;
width: 240px;
font-family: inherit;
}
.select-disabled-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.select-disabled-label[data-disabled] {
opacity: 0.5;
}
.select-disabled-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
padding: 8px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 14px;
text-align: left;
}
.select-disabled-trigger:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.select-disabled-icon {
flex-shrink: 0;
width: 16px;
height: 16px;
}
.select-disabled-content {
box-sizing: border-box;
width: var(--leve-select-anchor-width);
padding: 4px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
}
.select-disabled-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: 4px;
font-size: 14px;
}
.select-disabled-indicator {
display: inline-flex;
}
.select-disabled-indicator[hidden] {
display: none;
}Fieldとフォーム#
Field内では、Select.TriggerはFieldのid、ラベル、説明、エラーメッセージ、およびinvalid、disabled、requiredの状態を受け取ります。ネイティブの<form>の送信とリセットに参加させるには、Select.HiddenInputを追加します。
import { component$, useComputed$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Field } from '@leve-ui/field';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './field.css?inline';
const COUNTRIES = [
{ value: 'jp', label: 'Japan' },
{ value: 'us', label: 'United States' },
{ value: 'uk', label: 'United Kingdom' },
];
export default component$(() => {
useStyles$(styles);
const country = useSignal<string | null>(null);
const submitted = useSignal(false);
const result = useSignal<string | null>(null);
const invalid = useComputed$(() => submitted.value && country.value === null);
const status = useComputed$(() => (result.value !== null ? `Submitted: ${result.value}` : ''));
return (
<form
class="select-field-form"
noValidate
preventdefault:submit
onSubmit$={(_event, form) => {
submitted.value = true;
if (country.value === null) return;
const data = new FormData(form);
result.value = String(data.get('country') ?? '');
}}
onReset$={() => {
submitted.value = false;
result.value = null;
}}
>
<Field.Root hasDescription invalid={invalid.value} required class="select-field">
<Field.Label class="select-field-label">Country</Field.Label>
{/* position: relative keeps HiddenInput anchored inside Root */}
<Select.Root bind:value={country} class="select-field-root">
<Select.Trigger class="select-field-trigger">
<Select.Value placeholder="Choose a country" class="select-field-value" />
<LuChevronDown aria-hidden="true" class="select-field-icon" />
</Select.Trigger>
<Select.HiddenInput name="country" />
<Select.Content sideOffset={4} class="select-field-content">
<Select.List>
{COUNTRIES.map((item) => (
<Select.Item key={item.value} value={item.value} class="select-field-item">
<Select.ItemText>{item.label}</Select.ItemText>
<Select.ItemIndicator class="select-field-indicator">
<LuCheck aria-hidden="true" class="select-field-icon" />
</Select.ItemIndicator>
</Select.Item>
))}
</Select.List>
</Select.Content>
</Select.Root>
<Field.Description class="select-field-description">
Used for shipping and tax calculation.
</Field.Description>
<Field.ErrorMessage class="select-field-error">Please select a country.</Field.ErrorMessage>
</Field.Root>
<div class="select-field-actions">
<button type="submit" class="select-field-button">
Submit
</button>
<button
type="reset"
class="select-field-button"
onClick$={() => {
country.value = null;
}}
>
Reset
</button>
</div>
<p class="select-field-status">{status.value}</p>
</form>
);
});.select-field-form {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.select-field {
display: flex;
flex-direction: column;
gap: 6px;
width: 240px;
}
.select-field-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.select-field-root {
/* HiddenInput is absolutely positioned inside Root */
position: relative;
}
.select-field-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
padding: 8px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 14px;
cursor: pointer;
text-align: left;
}
.select-field-trigger:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-field-trigger:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-field-trigger[data-invalid] {
border-color: light-dark(#dc2626, #f87171);
}
.select-field-value[data-placeholder] {
color: light-dark(#475569, #c9ddf0);
}
.select-field-icon {
flex-shrink: 0;
width: 16px;
height: 16px;
}
/* The Content is a popover in the top layer; the library sets its position */
.select-field-content {
box-sizing: border-box;
width: var(--leve-select-anchor-width);
max-height: min(240px, var(--leve-select-available-height));
overflow-y: auto;
padding: 4px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
box-shadow: 0 8px 24px rgb(15 23 42 / 0.18);
}
.select-field-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: 4px;
font-size: 14px;
cursor: default;
}
.select-field-item[data-highlighted] {
background: #009dfd;
color: #ffffff;
}
.select-field-indicator {
display: inline-flex;
}
.select-field-indicator[hidden] {
display: none;
}
.select-field-description {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}
.select-field-error {
margin: 0;
font-size: 13px;
color: light-dark(#dc2626, #f87171);
}
.select-field-actions {
display: flex;
gap: 8px;
}
.select-field-button {
height: 32px;
padding: 0 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.select-field-button:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-field-button:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-field-status {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}
.select-field-status:empty {
display: none;
}状態制御#
シグナルで選択された値を読み取りおよび更新するには、bind:valueを使用します。nullを設定するとプレースホルダーに戻ります。
Current value: banana
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Select } from '@leve-ui/select';
import { LuCheck, LuChevronDown } from '@qwikest/icons/lucide';
import styles from './controlled.css?inline';
export default component$(() => {
useStyles$(styles);
const selected = useSignal<string | null>('banana');
return (
<div class="select-controlled">
<Select.Root bind:value={selected} class="select-controlled-root">
<Select.Label class="select-controlled-label">Favorite fruit</Select.Label>
<Select.Trigger class="select-controlled-trigger">
<Select.Value placeholder="Select a fruit" class="select-controlled-value" />
<LuChevronDown aria-hidden="true" class="select-controlled-icon" />
</Select.Trigger>
<Select.Content sideOffset={4} class="select-controlled-content">
<Select.List>
<Select.Item value="apple" class="select-controlled-item">
<Select.ItemText>Apple</Select.ItemText>
<Select.ItemIndicator class="select-controlled-indicator">
<LuCheck aria-hidden="true" class="select-controlled-icon" />
</Select.ItemIndicator>
</Select.Item>
<Select.Item value="banana" class="select-controlled-item">
<Select.ItemText>Banana</Select.ItemText>
<Select.ItemIndicator class="select-controlled-indicator">
<LuCheck aria-hidden="true" class="select-controlled-icon" />
</Select.ItemIndicator>
</Select.Item>
<Select.Item value="orange" class="select-controlled-item">
<Select.ItemText>Orange</Select.ItemText>
<Select.ItemIndicator class="select-controlled-indicator">
<LuCheck aria-hidden="true" class="select-controlled-icon" />
</Select.ItemIndicator>
</Select.Item>
</Select.List>
</Select.Content>
</Select.Root>
<div class="select-controlled-controls">
<button
type="button"
class="select-controlled-button"
onClick$={() => {
selected.value = 'apple';
}}
>
Select Apple
</button>
<button
type="button"
class="select-controlled-button"
onClick$={() => {
selected.value = 'orange';
}}
>
Select Orange
</button>
<button
type="button"
class="select-controlled-button"
onClick$={() => {
selected.value = null;
}}
>
Clear Selection
</button>
</div>
<p class="select-controlled-status">Current value: {selected.value ?? 'none'}</p>
</div>
);
});.select-controlled {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 12px;
font-family: inherit;
}
.select-controlled-root {
display: flex;
flex-direction: column;
gap: 6px;
width: 240px;
}
.select-controlled-label {
font-size: 14px;
font-weight: 500;
color: light-dark(#0f172a, #ffffff);
}
.select-controlled-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
width: 100%;
padding: 8px 10px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 14px;
cursor: pointer;
text-align: left;
}
.select-controlled-trigger:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-controlled-trigger:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-controlled-value[data-placeholder] {
color: light-dark(#475569, #c9ddf0);
}
.select-controlled-icon {
flex-shrink: 0;
width: 16px;
height: 16px;
}
/* The Content is a popover in the top layer; the library sets its position */
.select-controlled-content {
box-sizing: border-box;
width: var(--leve-select-anchor-width);
max-height: min(240px, var(--leve-select-available-height));
overflow-y: auto;
padding: 4px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font-family: inherit;
box-shadow: 0 8px 24px rgb(15 23 42 / 0.18);
}
.select-controlled-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 8px;
border-radius: 4px;
font-size: 14px;
cursor: default;
}
.select-controlled-item[data-highlighted] {
background: #009dfd;
color: #ffffff;
}
.select-controlled-indicator {
display: inline-flex;
}
.select-controlled-indicator[hidden] {
display: none;
}
.select-controlled-controls {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.select-controlled-button {
height: 32px;
padding: 0 12px;
border: 1px solid light-dark(#cbd5e1, #ffffff3d);
border-radius: 6px;
background: light-dark(#ffffff, #1b2045);
color: light-dark(#0f172a, #ffffff);
font: inherit;
font-size: 13px;
font-weight: 500;
cursor: pointer;
}
.select-controlled-button:hover {
background: light-dark(#f1f5f9, #ffffff14);
}
.select-controlled-button:focus-visible {
outline: 2px solid #009dfd;
outline-offset: 2px;
}
.select-controlled-status {
margin: 0;
font-size: 13px;
color: light-dark(#475569, #c9ddf0);
}APIリファレンス#
Root#
| Prop | デフォルト | 型 |
|---|---|---|
| ids | – | { label?: string; trigger?: string; list?: string } パーツの要素IDを上書きします。Field内では、ラベルとトリガーにFieldのIDが使用されます。 |
| defaultValue | null | string | null 初期状態で選択されているアイテムの値です(非制御)。 |
| bind:value | – | Signal<string | null> 選択されているアイテムの値を持つシグナルです(制御)。何も選択されていない場合は |
| onValueChange$ | – | QRL<(value: string | null) => void> 選択された値が変更されたときに呼び出されます。 |
| defaultOpen | false | boolean リストボックスが初期状態で開いているかどうかです(非制御)。 |
| bind:open | – | Signal<boolean> リストボックスの開閉状態を持つシグナルです(制御)。 |
| onOpenChange$ | – | QRL<(open: boolean) => void> リストボックスが開閉したときに呼び出されます。 |
| disabled | false | boolean Selectが無効かどうかです。FieldまたはFieldset内では、継承された |
| required | false | boolean フォームで値が必須かどうかを指定します。Field内では、Fieldの |
| loop | false | boolean 最後のアイテムでArrowDownを押したときに最初のアイテムへ移動し、最初のアイテムでArrowUpを押したときに最後のアイテムへ移動するかどうかです。 |
<div>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select | 常に存在 |
data-state | "open" | "closed" |
data-disabled | disabled時に付与 |
Label#
独自のpropsはありません。 <label>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-label | 常に存在 |
data-disabled | disabled時に付与 |
Trigger#
| Prop | デフォルト | 型 |
|---|---|---|
| invalid | false | boolean 選択値が無効かどうかを指定します。Field内では、Fieldの |
<button>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-trigger | 常に存在 |
data-state | "open" | "closed" |
data-placeholder | オプションが選択されていない場合に存在します。 |
data-disabled | disabled時に付与 |
data-invalid | 無効な場合に付与 |
値#
| Prop | デフォルト | 型 |
|---|---|---|
| placeholder | – | string 項目が選択されていないときに表示されるテキストです。 |
<span>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-value | 常に存在 |
data-placeholder | オプションが選択されていない場合に存在します。 |
defaultValueまたはbind:valueに初期値がある場合、Select.Valueはクライアント側のDOMから一致する選択肢のテキストを解決します。クライアントが解決する前のSSR中に初期ラベルがレンダリングされるよう、フォールバックテキストを子要素として渡してください(例:<Select.Value>Banana</Select.Value>)。
HiddenInput#
| Prop | デフォルト | 型 |
|---|---|---|
| form | – | string 入力を関連付けるフォーム要素の |
<input>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-hidden-input | 常に存在 |
絶対配置されるため、Select.Rootにはposition: relativeを指定してください。
Content#
| Prop | デフォルト | 型 |
|---|---|---|
| side | 'bottom' | 'top' | 'right' | 'bottom' | 'left' リストボックスを配置するTriggerの側です。スペースがない場合は反転します。 |
| align | 'start' | 'start' | 'center' | 'end' その側に沿った配置です。 |
| sideOffset | 0 | number Triggerからの距離(px)です。 |
| alignOffset | 0 | number 辺に沿ったオフセット(px)です。 |
| avoidCollisions | true | boolean ビューポート内に収まるようにリストボックスを反転・シフトするかどうかです。 |
| collisionPadding | 0 | number 衝突を回避する際のビューポートの端からのパディング(px)です。 |
<div>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-content | 常に存在 |
data-state | "open" | "closed" |
data-side | 反転後の最終的な配置側 |
data-align | "start" | "center" | "end" |
| CSS変数 | 値 |
|---|---|
--leve-select-anchor-width | Triggerの幅(たとえば、リストボックスの幅に合わせるため) |
--leve-select-anchor-height | Triggerの高さ |
--leve-select-available-width | ビューポート内で利用可能な幅 |
--leve-select-available-height | ビューポート内で利用可能な高さ(たとえばmax-height用) |
List#
独自のpropsはありません。 <div>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-list | 常に存在 |
Item#
| Prop | デフォルト | 型 |
|---|---|---|
| value (必須) | – | string アイテムの値です。Select内で一意である必要があります。 |
| disabled | false | boolean アイテムを選択不可にするかどうかを指定します。矢印キーとタイプアヘッドはこれをスキップします。 |
| textValue | – | string
|
<div>のすべての属性も受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-item | 常に存在 |
data-value | valueの値 |
data-state | "checked" | "unchecked" |
data-highlighted | ハイライトされたオプションに付与 |
data-disabled | disabled時に付与 |
data-text-value | textValueの値(設定されている場合) |
フォーカスはトリガーに留まるため、ハイライトされたオプションのスタイル設定には:focusではなく[data-highlighted]を使用します。
ItemText#
独自のpropsはありません。 <span>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-item-text | 常に存在 |
ItemIndicator#
独自のpropsはありません。 <span>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-item-indicator | 常に存在 |
data-state | "checked" | "unchecked" |
オプションが選択されていない間、hidden属性が付与されます。displayを設定する場合は、[hidden] { display: none; }で再び非表示にしてください。
Group#
独自のpropsはありません。 <div>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-group | 常に存在 |
GroupLabel#
独自のpropsはありません。 <div>のすべての属性を受け付けます。
| データ属性 | 値 |
|---|---|
data-leve-select-group-label | 常に存在 |
アクセシビリティ#
Select-Only Combobox WAI-ARIAデザインパターンに準拠しています。
Select.Triggerは、aria-haspopup="listbox"、aria-expanded、aria-controls、aria-labelledbyを備えた<button type="button" role="combobox">をレンダリングします。フォーカスはトリガーに留まり、開いている間はaria-activedescendantがハイライトされたオプションを指します。Select.Listはラベルによって名前付けされたrole="listbox"をレンダリングします。オプションはaria-selected付きのrole="option"をレンダリングし、無効なオプションはaria-disabled="true"をレンダリングして矢印キーとタイプアヘッドでスキップされます。Select.Groupは、Select.GroupLabelによって名前付けされたrole="group"をレンダリングします。aria-selectedが状態を伝えるため、Select.ItemIndicatorはaria-hidden="true"によって支援技術から隠されます。- Field内では、トリガーはFieldのid、ラベル、説明、エラーメッセージ、および
invalid、disabled、requiredの状態を受け取ります。
キーボード操作#
| キー | 説明 |
|---|---|
Enter / Space | 閉じているときはリストボックスを開き、選択されているオプション(または最初の有効なオプション)をハイライトします。開いているときはハイライトされているオプションを選択して閉じます。 |
ArrowDown | 閉じているときはリストボックスを開き、選択されているオプション(または最初の有効なオプション)をハイライトします。開いているときは次の有効なオプションをハイライトします。 |
ArrowUp | 閉じているときはリストボックスを開き、選択されているオプション(または最後の有効なオプション)をハイライトします。開いているときは前の有効なオプションをハイライトします(Alt + ArrowUpの場合は閉じます)。 |
Home | 閉じている場合はリストボックスを開き、最初の有効なオプションをハイライトします。 |
End | 閉じている場合はリストボックスを開き、最後の有効なオプションをハイライトします。 |
Escape | 値を変更せずにリストボックスを閉じ、フォーカスをトリガーに維持します。 |
Tab | リストボックスを閉じ、次のフォーカス可能な要素にフォーカスを移動します。 |
| 文字キー | タイプアヘッド:一致する有効なオプションにジャンプします(閉じている場合はリストボックスを開きます)。 |