@funstack/ui 0.1.0-alpha.19 → 0.1.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/accordion/accordion-item.mjs +2 -2
- package/dist/accordion/accordion-item.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.d.mts.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +3 -20
- package/dist/accordion/accordion-trigger.mjs.map +1 -1
- package/dist/alert-dialog/alert-dialog-action.d.mts +73 -0
- package/dist/alert-dialog/alert-dialog-action.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-action.mjs +23 -0
- package/dist/alert-dialog/alert-dialog-action.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-cancel.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs +50 -0
- package/dist/alert-dialog/alert-dialog-cancel.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-context.mjs +24 -0
- package/dist/alert-dialog/alert-dialog-context.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts +25 -0
- package/dist/alert-dialog/alert-dialog-description.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-description.mjs +20 -0
- package/dist/alert-dialog/alert-dialog-description.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts +27 -0
- package/dist/alert-dialog/alert-dialog-form.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-form.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-form.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts +42 -0
- package/dist/alert-dialog/alert-dialog-popup.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs +53 -0
- package/dist/alert-dialog/alert-dialog-popup.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts +31 -0
- package/dist/alert-dialog/alert-dialog-root.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-root.mjs +22 -0
- package/dist/alert-dialog/alert-dialog-root.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-title.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-title.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-title.mjs.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts +23 -0
- package/dist/alert-dialog/alert-dialog-trigger.d.mts.map +1 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs +18 -0
- package/dist/alert-dialog/alert-dialog-trigger.mjs.map +1 -0
- package/dist/alert-dialog/index.d.mts +33 -0
- package/dist/alert-dialog/index.d.mts.map +1 -0
- package/dist/alert-dialog/index.mjs +33 -0
- package/dist/alert-dialog/index.mjs.map +1 -0
- package/dist/checkbox-group/checkbox-group-parent.mjs +1 -1
- package/dist/collapsible/collapsible-context.mjs +8 -0
- package/dist/collapsible/collapsible-context.mjs.map +1 -0
- package/dist/collapsible/collapsible-panel.d.mts +53 -0
- package/dist/collapsible/collapsible-panel.d.mts.map +1 -0
- package/dist/collapsible/collapsible-panel.mjs +41 -0
- package/dist/collapsible/collapsible-panel.mjs.map +1 -0
- package/dist/collapsible/collapsible-root.d.mts +108 -0
- package/dist/collapsible/collapsible-root.d.mts.map +1 -0
- package/dist/collapsible/collapsible-root.mjs +147 -0
- package/dist/collapsible/collapsible-root.mjs.map +1 -0
- package/dist/collapsible/collapsible-trigger.d.mts +45 -0
- package/dist/collapsible/collapsible-trigger.d.mts.map +1 -0
- package/dist/collapsible/collapsible-trigger.mjs +62 -0
- package/dist/collapsible/collapsible-trigger.mjs.map +1 -0
- package/dist/collapsible/index.d.mts +21 -0
- package/dist/collapsible/index.d.mts.map +1 -0
- package/dist/collapsible/index.mjs +21 -0
- package/dist/collapsible/index.mjs.map +1 -0
- package/dist/combobox/chip-text.mjs +24 -0
- package/dist/combobox/chip-text.mjs.map +1 -0
- package/dist/combobox/combobox-chips.d.mts +159 -0
- package/dist/combobox/combobox-chips.d.mts.map +1 -0
- package/dist/combobox/combobox-chips.mjs +198 -0
- package/dist/combobox/combobox-chips.mjs.map +1 -0
- package/dist/combobox/combobox-clear.d.mts +5 -2
- package/dist/combobox/combobox-clear.d.mts.map +1 -1
- package/dist/combobox/combobox-clear.mjs +3 -1
- package/dist/combobox/combobox-clear.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs +4 -5
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.d.mts +10 -3
- package/dist/combobox/combobox-input.d.mts.map +1 -1
- package/dist/combobox/combobox-input.mjs +13 -5
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +50 -4
- package/dist/combobox/combobox-keyboard.mjs.map +1 -1
- package/dist/combobox/combobox-list.d.mts +1 -1
- package/dist/combobox/combobox-list.mjs +2 -1
- package/dist/combobox/combobox-list.mjs.map +1 -1
- package/dist/combobox/combobox-option.d.mts +5 -2
- package/dist/combobox/combobox-option.d.mts.map +1 -1
- package/dist/combobox/combobox-option.mjs +4 -3
- package/dist/combobox/combobox-option.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts +127 -35
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +396 -44
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/index.d.mts +8 -2
- package/dist/combobox/index.d.mts.map +1 -1
- package/dist/combobox/index.mjs +7 -1
- package/dist/combobox/index.mjs.map +1 -1
- package/dist/combobox/use-combobox-form.mjs +2 -3
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/dialog/dialog-close.d.mts +9 -5
- package/dist/dialog/dialog-close.d.mts.map +1 -1
- package/dist/dialog/dialog-close.mjs +19 -8
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.d.mts +2 -0
- package/dist/dialog/dialog-context.mjs +14 -2
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-description.d.mts +2 -1
- package/dist/dialog/dialog-description.d.mts.map +1 -1
- package/dist/dialog/dialog-description.mjs +8 -4
- package/dist/dialog/dialog-description.mjs.map +1 -1
- package/dist/dialog/dialog-form.d.mts +2 -1
- package/dist/dialog/dialog-form.d.mts.map +1 -1
- package/dist/dialog/dialog-form.mjs +11 -6
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts +2 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +23 -14
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts +2 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +15 -5
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-title.d.mts +2 -1
- package/dist/dialog/dialog-title.d.mts.map +1 -1
- package/dist/dialog/dialog-title.mjs +8 -4
- package/dist/dialog/dialog-title.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.d.mts +2 -1
- package/dist/dialog/dialog-trigger.d.mts.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +14 -9
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +2 -0
- package/dist/docs/components/alert-dialog.md +546 -0
- package/dist/docs/components/collapsible.md +408 -0
- package/dist/docs/components/combobox.md +288 -26
- package/dist/docs/components/dialog.md +7 -5
- package/dist/docs/components/field.md +180 -3
- package/dist/docs/components/hover-card.md +494 -0
- package/dist/docs/components/multi-select.md +622 -0
- package/dist/docs/components/number-field.md +1 -1
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/select.md +9 -1
- package/dist/docs/components/separator.md +182 -0
- package/dist/docs/components/slider.md +1 -1
- package/dist/docs/components/tooltip.md +1 -1
- package/dist/docs/concepts/experimental.md +3 -3
- package/dist/docs/concepts/server-components.md +1 -1
- package/dist/docs/index.md +7 -2
- package/dist/docs/roadmap.md +8 -0
- package/dist/field/field-control.d.mts +13 -4
- package/dist/field/field-control.d.mts.map +1 -1
- package/dist/field/field-control.mjs +39 -10
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-label.d.mts +6 -2
- package/dist/field/field-label.d.mts.map +1 -1
- package/dist/field/field-label.mjs +12 -2
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.mjs +9 -1
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/hover-card/hover-card-context.mjs +13 -0
- package/dist/hover-card/hover-card-context.mjs.map +1 -0
- package/dist/hover-card/hover-card-popup.d.mts +102 -0
- package/dist/hover-card/hover-card-popup.d.mts.map +1 -0
- package/dist/hover-card/hover-card-popup.mjs +80 -0
- package/dist/hover-card/hover-card-popup.mjs.map +1 -0
- package/dist/hover-card/hover-card-root.d.mts +94 -0
- package/dist/hover-card/hover-card-root.d.mts.map +1 -0
- package/dist/hover-card/hover-card-root.mjs +74 -0
- package/dist/hover-card/hover-card-root.mjs.map +1 -0
- package/dist/hover-card/hover-card-trigger.d.mts +65 -0
- package/dist/hover-card/hover-card-trigger.d.mts.map +1 -0
- package/dist/hover-card/hover-card-trigger.mjs +109 -0
- package/dist/hover-card/hover-card-trigger.mjs.map +1 -0
- package/dist/hover-card/index.d.mts +24 -0
- package/dist/hover-card/index.d.mts.map +1 -0
- package/dist/hover-card/index.mjs +24 -0
- package/dist/hover-card/index.mjs.map +1 -0
- package/dist/hover-card/use-hover-card-interest.mjs +242 -0
- package/dist/hover-card/use-hover-card-interest.mjs.map +1 -0
- package/dist/index.d.mts +38 -9
- package/dist/index.mjs +6 -1
- package/dist/internal/action/use-multiple-selection.mjs +83 -0
- package/dist/internal/action/use-multiple-selection.mjs.map +1 -0
- package/dist/internal/details-summary.mjs +56 -0
- package/dist/internal/details-summary.mjs.map +1 -0
- package/dist/internal/form/field-context.mjs.map +1 -1
- package/dist/internal/form/hidden-values.mjs +29 -0
- package/dist/internal/form/hidden-values.mjs.map +1 -0
- package/dist/internal/form/validity.mjs +3 -1
- package/dist/internal/form/validity.mjs.map +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs +2 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-close.mjs +5 -3
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -1
- package/dist/internal/overlay/use-overlay-root.mjs +4 -1
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-popup.mjs +20 -7
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -1
- package/dist/internal/overlay/use-popover-trigger.d.mts +1 -1
- package/dist/internal/typeahead.mjs +52 -0
- package/dist/internal/typeahead.mjs.map +1 -0
- package/dist/{combobox → internal}/use-active-option.mjs +8 -6
- package/dist/internal/use-active-option.mjs.map +1 -0
- package/dist/{combobox → internal}/use-deferred-leave.mjs +20 -12
- package/dist/internal/use-deferred-leave.mjs.map +1 -0
- package/dist/internal/use-name-warning.mjs +57 -1
- package/dist/internal/use-name-warning.mjs.map +1 -1
- package/dist/internal/use-option-registry.mjs +70 -0
- package/dist/internal/use-option-registry.mjs.map +1 -0
- package/dist/menu/use-menu-keyboard.mjs +7 -27
- package/dist/menu/use-menu-keyboard.mjs.map +1 -1
- package/dist/multi-select/index.d.mts +37 -0
- package/dist/multi-select/index.d.mts.map +1 -0
- package/dist/multi-select/index.mjs +37 -0
- package/dist/multi-select/index.mjs.map +1 -0
- package/dist/multi-select/multi-select-context.mjs +19 -0
- package/dist/multi-select/multi-select-context.mjs.map +1 -0
- package/dist/multi-select/multi-select-group.d.mts +120 -0
- package/dist/multi-select/multi-select-group.d.mts.map +1 -0
- package/dist/multi-select/multi-select-group.mjs +111 -0
- package/dist/multi-select/multi-select-group.mjs.map +1 -0
- package/dist/multi-select/multi-select-keyboard.mjs +145 -0
- package/dist/multi-select/multi-select-keyboard.mjs.map +1 -0
- package/dist/multi-select/multi-select-label.d.mts +42 -0
- package/dist/multi-select/multi-select-label.d.mts.map +1 -0
- package/dist/multi-select/multi-select-label.mjs +41 -0
- package/dist/multi-select/multi-select-label.mjs.map +1 -0
- package/dist/multi-select/multi-select-list.d.mts +47 -0
- package/dist/multi-select/multi-select-list.d.mts.map +1 -0
- package/dist/multi-select/multi-select-list.mjs +65 -0
- package/dist/multi-select/multi-select-list.mjs.map +1 -0
- package/dist/multi-select/multi-select-option.d.mts +68 -0
- package/dist/multi-select/multi-select-option.d.mts.map +1 -0
- package/dist/multi-select/multi-select-option.mjs +93 -0
- package/dist/multi-select/multi-select-option.mjs.map +1 -0
- package/dist/multi-select/multi-select-popup.d.mts +58 -0
- package/dist/multi-select/multi-select-popup.d.mts.map +1 -0
- package/dist/multi-select/multi-select-popup.mjs +71 -0
- package/dist/multi-select/multi-select-popup.mjs.map +1 -0
- package/dist/multi-select/multi-select-root.d.mts +125 -0
- package/dist/multi-select/multi-select-root.d.mts.map +1 -0
- package/dist/multi-select/multi-select-root.mjs +257 -0
- package/dist/multi-select/multi-select-root.mjs.map +1 -0
- package/dist/multi-select/multi-select-trigger.d.mts +66 -0
- package/dist/multi-select/multi-select-trigger.d.mts.map +1 -0
- package/dist/multi-select/multi-select-trigger.mjs +169 -0
- package/dist/multi-select/multi-select-trigger.mjs.map +1 -0
- package/dist/multi-select/multi-select-value.d.mts +57 -0
- package/dist/multi-select/multi-select-value.d.mts.map +1 -0
- package/dist/multi-select/multi-select-value.mjs +41 -0
- package/dist/multi-select/multi-select-value.mjs.map +1 -0
- package/dist/number-field/number-field-root.mjs +1 -1
- package/dist/number-field/use-step-button.d.mts.map +1 -1
- package/dist/number-field/use-step-button.mjs +11 -2
- package/dist/number-field/use-step-button.mjs.map +1 -1
- package/dist/popover/popover-close.d.mts +6 -3
- package/dist/popover/popover-close.d.mts.map +1 -1
- package/dist/popover/popover-close.mjs +3 -2
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-popup.mjs +1 -1
- package/dist/select/select-root.d.mts +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +5 -1
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/separator/index.d.mts +3 -0
- package/dist/separator/index.mjs +1 -0
- package/dist/separator/separator.d.mts +58 -0
- package/dist/separator/separator.d.mts.map +1 -0
- package/dist/separator/separator.mjs +41 -0
- package/dist/separator/separator.mjs.map +1 -0
- package/dist/slider/slider-root.mjs +1 -0
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.mjs +1 -1
- package/package.json +6 -1
- package/skills/funstack-ui-knowledge/SKILL.md +14 -9
- package/dist/combobox/use-active-option.mjs.map +0 -1
- package/dist/combobox/use-deferred-leave.mjs.map +0 -1
- package/dist/combobox/use-option-registry.mjs +0 -52
- package/dist/combobox/use-option-registry.mjs.map +0 -1
|
@@ -246,6 +246,56 @@ export function ComboboxCountry() {
|
|
|
246
246
|
transition: none;
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
+
|
|
250
|
+
/* Combobox `multiple`: the field box holds the chips and the input; Chips is the list of selected
|
|
251
|
+
values, each Chip a focusable list item (the inline-start arrow at the input's start moves into
|
|
252
|
+
them). A chip whose addition is still being saved carries `data-pending`. The box is named as
|
|
253
|
+
an anchor so the listbox can be as wide as it (the Popup's `style` in the example). */
|
|
254
|
+
.demo-combobox-tags {
|
|
255
|
+
display: flex;
|
|
256
|
+
flex-wrap: wrap;
|
|
257
|
+
max-inline-size: 30rem;
|
|
258
|
+
padding: 2px 4px;
|
|
259
|
+
anchor-name: --demo-tags;
|
|
260
|
+
}
|
|
261
|
+
.demo-combobox-tags .demo-combobox-input {
|
|
262
|
+
flex: 1;
|
|
263
|
+
min-inline-size: 8rem;
|
|
264
|
+
}
|
|
265
|
+
.demo-combobox-chips {
|
|
266
|
+
display: flex;
|
|
267
|
+
flex-wrap: wrap;
|
|
268
|
+
}
|
|
269
|
+
.demo-combobox-chip {
|
|
270
|
+
display: inline-flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
gap: 2px;
|
|
273
|
+
margin: 2px;
|
|
274
|
+
padding: 0.1em 0.2em 0.1em 0.55em;
|
|
275
|
+
border-radius: 999px;
|
|
276
|
+
background: var(--color-bg-secondary);
|
|
277
|
+
font-size: 0.9em;
|
|
278
|
+
}
|
|
279
|
+
.demo-combobox-chip:focus-visible {
|
|
280
|
+
outline: 2px solid var(--color-primary);
|
|
281
|
+
outline-offset: 1px;
|
|
282
|
+
}
|
|
283
|
+
.demo-combobox-chip[data-pending] {
|
|
284
|
+
opacity: 0.6;
|
|
285
|
+
cursor: progress;
|
|
286
|
+
}
|
|
287
|
+
.demo-combobox-chip-remove {
|
|
288
|
+
padding: 0 0.35em;
|
|
289
|
+
border: 0;
|
|
290
|
+
border-radius: 999px;
|
|
291
|
+
background: none;
|
|
292
|
+
color: var(--color-text-secondary);
|
|
293
|
+
font: inherit;
|
|
294
|
+
cursor: pointer;
|
|
295
|
+
}
|
|
296
|
+
.demo-combobox-chip-remove:hover {
|
|
297
|
+
color: var(--color-text);
|
|
298
|
+
}
|
|
249
299
|
```
|
|
250
300
|
|
|
251
301
|
## Anatomy
|
|
@@ -373,39 +423,185 @@ export function ComboboxDrink() {
|
|
|
373
423
|
|
|
374
424
|
With `allowCustomValue` the typed text is a value: Enter with no active option, or focus leaving, dispatches it with `details.custom: true` (an emptied text dispatches `null`). Enter on a closed listbox is not prevented, so a form still submits, and the hidden input already holds the new text. Without `allowCustomValue`, text that is not the selection's label reverts when focus leaves (`reason: "dismiss"`), so the field never shows a value it does not have.
|
|
375
425
|
|
|
426
|
+
### <a id="multiple"></a>Multiple selection
|
|
427
|
+
|
|
428
|
+
```tsx title="ComboboxTags.tsx"
|
|
429
|
+
"use client";
|
|
430
|
+
import { startTransition, useState } from "react";
|
|
431
|
+
import { Combobox } from "@funstack/ui/combobox";
|
|
432
|
+
import { DemoErrorBoundary } from "./DemoErrorBoundary.js";
|
|
433
|
+
import { fakeSave } from "./fake-api.js";
|
|
434
|
+
|
|
435
|
+
const LANGUAGES = [
|
|
436
|
+
"C",
|
|
437
|
+
"C++",
|
|
438
|
+
"Elixir",
|
|
439
|
+
"Go",
|
|
440
|
+
"Haskell",
|
|
441
|
+
"Java",
|
|
442
|
+
"JavaScript",
|
|
443
|
+
"Kotlin",
|
|
444
|
+
"OCaml",
|
|
445
|
+
"Python",
|
|
446
|
+
"Ruby",
|
|
447
|
+
"Rust",
|
|
448
|
+
"Swift",
|
|
449
|
+
"TypeScript",
|
|
450
|
+
];
|
|
451
|
+
|
|
452
|
+
export function ComboboxTags() {
|
|
453
|
+
const [saved, setSaved] = useState<string[]>(["TypeScript"]);
|
|
454
|
+
const [fail, setFail] = useState(false);
|
|
455
|
+
return (
|
|
456
|
+
<div className="demo-stack">
|
|
457
|
+
<DemoErrorBoundary>
|
|
458
|
+
<Combobox.Root
|
|
459
|
+
multiple
|
|
460
|
+
name="languages"
|
|
461
|
+
defaultValue={["TypeScript"]}
|
|
462
|
+
allowCustomValue
|
|
463
|
+
valueChangeAction={async (_next, { added, removed }) => {
|
|
464
|
+
// Persist the diff, not `next`: an earlier change may still fail.
|
|
465
|
+
await fakeSave(`+${added.join(",")} -${removed.join(",")}`, { fail });
|
|
466
|
+
startTransition(() =>
|
|
467
|
+
setSaved((prev) => [
|
|
468
|
+
...prev.filter((v) => !removed.includes(v)),
|
|
469
|
+
...added.filter((v) => !prev.includes(v)),
|
|
470
|
+
]),
|
|
471
|
+
);
|
|
472
|
+
}}
|
|
473
|
+
>
|
|
474
|
+
<Combobox.Label>Languages</Combobox.Label>
|
|
475
|
+
<div className="demo-combobox-field demo-combobox-tags">
|
|
476
|
+
<Combobox.Chips className="demo-combobox-chips">
|
|
477
|
+
{({ value }) =>
|
|
478
|
+
value.map((language) => (
|
|
479
|
+
<Combobox.Chip key={language} value={language} className="demo-combobox-chip">
|
|
480
|
+
{({ label }) => (
|
|
481
|
+
<>
|
|
482
|
+
{label ?? language}
|
|
483
|
+
<Combobox.ChipRemove
|
|
484
|
+
className="demo-combobox-chip-remove"
|
|
485
|
+
aria-label={`Remove ${label ?? language}`}
|
|
486
|
+
>
|
|
487
|
+
<span aria-hidden>×</span>
|
|
488
|
+
</Combobox.ChipRemove>
|
|
489
|
+
</>
|
|
490
|
+
)}
|
|
491
|
+
</Combobox.Chip>
|
|
492
|
+
))
|
|
493
|
+
}
|
|
494
|
+
</Combobox.Chips>
|
|
495
|
+
<Combobox.Input className="demo-combobox-input" placeholder="Add a language" />
|
|
496
|
+
{/* As wide as the field box: the box is the anchor (the Root anchors to the Input). */}
|
|
497
|
+
<Combobox.Popup
|
|
498
|
+
className="demo-combobox-popup"
|
|
499
|
+
style={{ positionAnchor: "--demo-tags", minWidth: "anchor-size(--demo-tags width)" }}
|
|
500
|
+
>
|
|
501
|
+
<Combobox.List>
|
|
502
|
+
{({ query }) =>
|
|
503
|
+
LANGUAGES.filter((l) => l.toLowerCase().includes(query.toLowerCase())).map(
|
|
504
|
+
(l) => (
|
|
505
|
+
<Combobox.Option key={l} value={l}>
|
|
506
|
+
{({ pending }) => (
|
|
507
|
+
<>
|
|
508
|
+
{l}
|
|
509
|
+
{pending && <span className="demo-spinner" aria-hidden />}
|
|
510
|
+
</>
|
|
511
|
+
)}
|
|
512
|
+
</Combobox.Option>
|
|
513
|
+
),
|
|
514
|
+
)
|
|
515
|
+
}
|
|
516
|
+
</Combobox.List>
|
|
517
|
+
<Combobox.Empty className="demo-combobox-status">
|
|
518
|
+
Press Enter to add it.
|
|
519
|
+
</Combobox.Empty>
|
|
520
|
+
</Combobox.Popup>
|
|
521
|
+
</div>
|
|
522
|
+
</Combobox.Root>
|
|
523
|
+
</DemoErrorBoundary>
|
|
524
|
+
<label>
|
|
525
|
+
<input type="checkbox" checked={fail} onChange={(e) => setFail(e.target.checked)} /> Make
|
|
526
|
+
the save fail
|
|
527
|
+
</label>
|
|
528
|
+
<output className="demo-readout">
|
|
529
|
+
saved: <code>{JSON.stringify(saved)}</code>
|
|
530
|
+
</output>
|
|
531
|
+
</div>
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
`combobox.css`: the same file as above.
|
|
537
|
+
|
|
538
|
+
`multiple` on the Root turns the selection into a list of values (`string[]`, in pick order) shown as chips. The text is then only a search:
|
|
539
|
+
|
|
540
|
+
- **A pick toggles** the option (a selected option is removed), clears the text and leaves the listbox open for the next pick. The listbox is `aria-multiselectable` and every option keeps its `aria-selected`. A rejection rolls back that one change (the chip and `data-selected`), never the text.
|
|
541
|
+
- **The value follows the set rules** of CheckboxGroup: each dispatch is one change, with `details.added` and `details.removed`; picks made while an earlier save runs stack, and only the changes whose action resolved are kept. Persist the diff, not `next`, which may contain a change that fails later.
|
|
542
|
+
- **`Combobox.Chips`** is a list of the optimistic values (a removed chip disappears at once and comes back if its save fails); you map them to `Combobox.Chip`s. A chip's `label` state is the text of the option the library last saw for its value, so an async search needs no map of its own. It is the list of chips only, not the field box: put the Input next to it in your own element.
|
|
543
|
+
- **Keys:** Backspace in the empty input removes the last chip; the inline-start arrow (Left, Right in RTL) at the caret's start moves focus into the chips, where the arrows, Home and End move, Backspace or Delete remove, Escape goes back and a letter types into the input. The combobox keeps one Tab stop. Chips removed outside the listbox are announced (`"Japan removed"`, `announceRemoved` to localise).
|
|
544
|
+
- **Forms:** one hidden input per value (`formData.getAll(name)`), nothing for an empty selection. `required` on the Input means "at least one": native `required` is rendered only while nothing is selected, and `aria-required` always. Unmatched text is cleared when focus leaves and by Enter in a closed listbox, so it never satisfies `required`. With `allowCustomValue`, Enter (prevented, the form does not submit) and focus leaving add the text as a value instead.
|
|
545
|
+
|
|
546
|
+
```tsx
|
|
547
|
+
<Combobox.Root multiple name="countries" defaultValue={["jp"]} valueChangeAction={saveCountries}>
|
|
548
|
+
<Combobox.Label>Countries</Combobox.Label>
|
|
549
|
+
<div className="field"> {/* your box around chips and input */}
|
|
550
|
+
<Combobox.Chips> {/* div[role=list] */}
|
|
551
|
+
{({ value }) => value.map((code) => (
|
|
552
|
+
<Combobox.Chip key={code} value={code}> {/* div[role=listitem][tabindex=-1] */}
|
|
553
|
+
{({ label }) => (
|
|
554
|
+
<>
|
|
555
|
+
{label ?? code}
|
|
556
|
+
<Combobox.ChipRemove aria-label={`Remove ${label ?? code}`} /> {/* button */}
|
|
557
|
+
</>
|
|
558
|
+
)}
|
|
559
|
+
</Combobox.Chip>
|
|
560
|
+
))}
|
|
561
|
+
</Combobox.Chips>
|
|
562
|
+
<Combobox.Input placeholder="Add a country" required />
|
|
563
|
+
</div>
|
|
564
|
+
<Combobox.Popup>…</Combobox.Popup>
|
|
565
|
+
</Combobox.Root>
|
|
566
|
+
```
|
|
567
|
+
|
|
376
568
|
## Props
|
|
377
569
|
|
|
378
570
|
### `Combobox.Root`
|
|
379
571
|
|
|
380
572
|
| Prop | Type | Default | Description |
|
|
381
573
|
| - | - | - | - |
|
|
382
|
-
| `
|
|
383
|
-
| `
|
|
384
|
-
| `
|
|
574
|
+
| `multiple` | `boolean` | `false` | `true`: the selection is a list of values shown as chips ([Multiple selection](#multiple)); `value`, `defaultValue`, `valueChangeAction`, `announce` and `children` take the multiple types below. Fixed at mount (development warns on a change). |
|
|
575
|
+
| `value` | `string \| null; string[] with multiple` | – | Controlled selection. `null`: nothing selected. `undefined` means uncontrolled. With `multiple`: `string[]`, `[]` for nothing; the order is the chip order, duplicates are ignored. |
|
|
576
|
+
| `defaultValue` | `string \| null; string[] with multiple` | `null` | Initial selection when uncontrolled; what a form reset returns to. With `multiple`: `string[]`, default `[]`. |
|
|
577
|
+
| `valueChangeAction` | `ChangeAction<string \| null, ComboboxValueChangeDetails>; with multiple ChangeAction<string[], ComboboxMultipleValueChangeDetails>` | – | Runs in the Root's transition when the user accepts an option, commits free text, presses Clear, or the form resets. Awaited; the listbox closes in the commit that ends it; a rejection rolls the text and the selection back and leaves the listbox open. May be a Server Function. A `setState` after your own `await` needs `startTransition`. With `multiple`: `ChangeAction<string[], ComboboxMultipleValueChangeDetails>`, called for every change (a pick, a removed chip, Clear, free text, a reset); the listbox does not close; a rejection undoes that change only. |
|
|
385
578
|
| `inputValue` | `string` | – | Controlled text. `undefined` means uncontrolled. |
|
|
386
|
-
| `defaultInputValue` | `string` | `""` | Initial text when uncontrolled, and the visible input's form-reset target.
|
|
579
|
+
| `defaultInputValue` | `string` | `""` | Initial text when uncontrolled, and the visible input's form-reset target. Single selection: pass the selected option's label together with `defaultValue`. With `multiple` the text is only a search (usually left empty). |
|
|
387
580
|
| `onInputValueChange` | `UrgentChangeHandler<string, ComboboxInputValueChangeDetails>` | – | A [handler](../concepts/action-props.md#on-handler), not an action: called synchronously, outside any transition, on every change of the text (typing, and the library's own writes). Not awaited, never pending. Set your state in the body. May return a promise; a rejection or a throw goes to `reportError` ([the rule of every on\* handler](../concepts/action-props.md#handlers)). |
|
|
388
581
|
| `open` | `boolean` | – | Controlled open state. `undefined` means uncontrolled. Pass `onOpenChange` too (development warns). |
|
|
389
582
|
| `defaultOpen` | `boolean` | `false` | Initial open state; opens after hydration. |
|
|
390
|
-
| `openChangeAction` | `ChangeAction<boolean, ComboboxOpenChangeDetails>` | – | Requests only: awaited for opens and for the closes a part asks for (an accepted option, the Trigger, Alt+ArrowUp). Never called for a dismissal (`onOpenChange`). Runs in the Root's transition; may be a Server Function. `details.reason`: `"activate"` (typing, ArrowDown / ArrowUp / Alt+ArrowDown, the Trigger, a click on the input with `openOnClick`, an accepted option, Alt+ArrowUp, a foreign `showPopover()`) or `"platform"` (found open on mount, which only script can cause; `event` is `undefined`). |
|
|
583
|
+
| `openChangeAction` | `ChangeAction<boolean, ComboboxOpenChangeDetails>` | – | Requests only: awaited for opens and for the closes a part asks for (an accepted option, the Trigger, Alt+ArrowUp; with `multiple`, a chip taking focus while an open is still on its way cancels it). Never called for a dismissal (`onOpenChange`). Runs in the Root's transition; may be a Server Function. `details.reason`: `"activate"` (typing, ArrowDown / ArrowUp / Alt+ArrowDown, the Trigger, a click on the input with `openOnClick`, an accepted option, Alt+ArrowUp, the cancel by a focused chip, a foreign `showPopover()`) or `"platform"` (found open on mount, which only script can cause; `event` is `undefined`). |
|
|
391
584
|
| `onOpenChange` | `UrgentChangeHandler<boolean, ComboboxOpenChangeDetails>` | – | Facts only: the listbox was closed without the library closing it on request. Always `false`. `details.reason`: `"dismiss"` (Escape, focus leaving the input, a click outside, a Clear click while open, another popover opening, script) or `"activate"` (a [foreign invoker](../concepts/browser-owned-state.md#foreign-invoker), whose press does not move focus out of the input, so the text is left as typed; a Trigger rendered as another element, pressed while open). Called synchronously in the browser's `toggle` event, outside any transition, and not awaited: nothing is pending and no view transition runs. In controlled mode set state directly here (`onOpenChange={setOpen}`), never in `startTransition` or after an `await`; a parent that keeps `open` gets the listbox shown again at once, with focus left where the dismissal put it. May return a promise (a Server Function); a rejection or a throw goes to `reportError`. |
|
|
392
|
-
| `allowCustomValue` | `boolean` | `false` | Free text is a value (Enter with no active option, focus leaving), dispatched with `details.custom: true`. Otherwise unmatched text reverts when focus leaves. |
|
|
585
|
+
| `allowCustomValue` | `boolean` | `false` | Free text is a value (Enter with no active option, focus leaving), dispatched with `details.custom: true`. Otherwise unmatched text reverts when focus leaves. With `multiple`: Enter (prevented, open or closed) and focus leaving add the text as a value (`added: [text]`) and clear it; without it unmatched text is cleared. |
|
|
393
586
|
| `autoHighlight` | `boolean` | `false` | Make the first enabled option active when the results for an open or an edit settle (APG automatic selection): typing then Enter picks the first match. Stale results are never highlighted, so an Enter before they settle commits the typed text (`allowCustomValue`) or does nothing. |
|
|
394
587
|
| `openOnClick` | `boolean` | `false` | Open on a click in the input (never on focus alone). |
|
|
395
588
|
| `loop` | `boolean` | `false` | ArrowDown / ArrowUp wrap from the last option to the first and back. |
|
|
396
|
-
| `announce` | `(count: number, state: ComboboxRootState) => string \| null` | `"No results" / "1 result" / "N results"` | The message `ariaNotify()` announces on the List when the results settle. Override for localisation; return `null` to announce nothing. Ignored where `ariaNotify` is missing. |
|
|
397
|
-
| `
|
|
589
|
+
| `announce` | `(count: number, state: ComboboxRootState) => string \| null; ComboboxMultipleRootState with multiple` | `"No results" / "1 result" / "N results"` | The message `ariaNotify()` announces on the List when the results settle. Override for localisation; return `null` to announce nothing. Ignored where `ariaNotify` is missing. |
|
|
590
|
+
| `announceRemoved` | `(labels: readonly string[], state: ComboboxMultipleRootState) => string \| null` | `"Japan removed" (the labels joined with ", ")` | `multiple` only. The message `ariaNotify()` announces on the Input when chips are removed outside the listbox (Backspace, Delete, `ChipRemove`, Clear). A label is the Chip's `label`, else the option text the library saw, else the chip's text. Return `null` to announce nothing. |
|
|
591
|
+
| `name` | `string` | – | Renders `<input type="hidden" name>` holding the optimistic value (`""` for `null`), the Root's only element. With `multiple`: one hidden input per value, in value order; none named while the selection is empty. |
|
|
398
592
|
| `form` | `string` | – | The hidden input's `form` attribute. |
|
|
399
|
-
| `disabled` | `boolean` | `false` | Disables the Input, Trigger and Clear; nothing dispatches for user interaction. The hidden input stays enabled, so the selection still posts (wrap in `<fieldset disabled>` to drop it). |
|
|
400
|
-
| `children` | `ReactNode \| ((state: ComboboxRootState) => ReactNode)` | – | The parts, or a function of the Root's state. |
|
|
593
|
+
| `disabled` | `boolean` | `false` | Disables the Input, Trigger and Clear (and every `ChipRemove`); nothing dispatches for user interaction. The hidden input stays enabled, so the selection still posts (wrap in `<fieldset disabled>` to drop it). |
|
|
594
|
+
| `children` | `ReactNode \| ((state: ComboboxRootState) => ReactNode); ComboboxMultipleRootState with multiple` | – | The parts, or a function of the Root's state (`ComboboxMultipleRootState` with `multiple`). |
|
|
401
595
|
|
|
402
|
-
- **State**: `ComboboxRootState` is `{ value, inputValue, query, stale, activeValue, open, pending, disabled }`; `value` and `open` are optimistic; `stale` is `inputValue !== query`; `pending` covers the value and the open transitions.
|
|
403
|
-
- **Owned**: nothing rendered: the Root has no element (no `ref`, `className` or `style`), only the hidden input when `name` is given.
|
|
596
|
+
- **State**: `ComboboxRootState` is `{ value, inputValue, query, stale, activeValue, open, pending, disabled }`; `value` and `open` are optimistic; `stale` is `inputValue !== query`; `pending` covers the value and the open transitions. `ComboboxMultipleRootState` is the same with `value: readonly string[]` (pick order).
|
|
597
|
+
- **Owned**: nothing rendered: the Root has no element (no `ref`, `className` or `style`), only the hidden input(s) when `name` is given.
|
|
404
598
|
|
|
405
|
-
`multiple` is not
|
|
599
|
+
The props type is `ComboboxRootProps = ComboboxSingleProps | ComboboxMultipleProps`, discriminated on `multiple`. `Partial<ComboboxRootProps>` is not assignable to either member, so a wrapper that spreads one into `Combobox.Root` types it as `Partial<ComboboxSingleProps>` (or the multiple one) instead.
|
|
406
600
|
|
|
407
601
|
`ComboboxValueChangeDetails`: `{ reason, custom, event }`. `reason` is `"activate"` (an accepted option: the `keydown` or `click`; free text: the `keydown` or `focusout`; Clear: the `click`) or `"platform"` (a form reset: the `reset` event). `ComboboxInputValueChangeDetails`: `{ reason, event }`, with `"activate"` for typing (the `input` event), an accepted label and Clear, `"dismiss"` for a revert, `"platform"` for a reset or text found at mount (no event). `ComboboxOpenChangeDetails`: `{ reason, event }`; the reasons are listed with `openChangeAction` and `onOpenChange` above.
|
|
408
602
|
|
|
603
|
+
`ComboboxMultipleValueChangeDetails` (with `multiple`): `{ reason, added, removed, custom, event }`. `added` lists the values this dispatch added, in the order they join; `removed` the values it removed, in value order; `custom` is `true` for free text. `reason` is `"activate"` (a toggled option: the `keydown` or `click`; a removed chip: the `keydown` of Backspace or Delete, the `click` of `ChipRemove`; Clear; free text: the `keydown` or `focusout`) or `"platform"` (a form reset, dispatched whole with the diff). With `multiple` the library writes the text on typing, a pick (`""`, `"activate"`), Clear, focus leaving (`""`, `"dismiss"`), a reset and at mount.
|
|
604
|
+
|
|
409
605
|
### `Combobox.Label`
|
|
410
606
|
|
|
411
607
|
| Prop | Type | Default | Description |
|
|
@@ -426,13 +622,13 @@ One per Root: the Input is the listbox's anchor, so a second `Combobox.Input` in
|
|
|
426
622
|
|
|
427
623
|
| Prop | Type | Default | Description |
|
|
428
624
|
| - | - | - | - |
|
|
429
|
-
| `required` | `boolean` | – | Native: an empty text is `valueMissing`, with the browser's message. |
|
|
625
|
+
| `required` | `boolean` | – | Native: an empty text is `valueMissing`, with the browser's message. With `multiple` it means at least one value: native `required` only while nothing is selected (optimistic), `aria-required` always. |
|
|
430
626
|
| `className` | `string \| ((state: ComboboxInputState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
431
627
|
| `style` | `CSSProperties \| ((state: ComboboxInputState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
432
628
|
| `render` | `ReactElement \| ((props, state: ComboboxInputState) => ReactNode)` | – | Replace the default \<input> (element form) or take over rendering (function form). |
|
|
433
629
|
|
|
434
|
-
- **State**: `ComboboxInputState` is `{ value, inputValue, open, pending, stale, disabled }`.
|
|
435
|
-
- **Owned**: `id`, `type` (`"text"`, or `"search"` when a `render` element says so), `role`, `value`, `autoComplete` (`"off"`), `aria-autocomplete`, `aria-expanded`, `aria-controls`, `aria-activedescendant`, `disabled`, `onChange`, `onKeyDown`, `onFocus`, `onBlur`, `onClick`, `onPointerDown`, `data-open`, `data-pending`, `data-selected`, `data-stale`, `data-disabled`. Inside a `Field.Root` also `required`, `aria-invalid`, `aria-describedby` (token-merged) and `data-invalid`.
|
|
630
|
+
- **State**: `ComboboxInputState` is `{ value, values, inputValue, open, pending, stale, disabled }`. `values` is the optimistic selection as a list (`[value]` or `[]` in single mode); with `multiple`, `value` is always `null`.
|
|
631
|
+
- **Owned**: `id`, `type` (`"text"`, or `"search"` when a `render` element says so), `role`, `value`, `autoComplete` (`"off"`), `aria-autocomplete`, `aria-expanded`, `aria-controls`, `aria-activedescendant`, `disabled`, `onChange`, `onKeyDown`, `onFocus`, `onBlur`, `onClick`, `onPointerDown`, `data-open`, `data-pending`, `data-selected`, `data-stale`, `data-disabled`. Inside a `Field.Root` also `required`, `aria-invalid`, `aria-describedby` (token-merged) and `data-invalid`. With `multiple` also `required` and `aria-required`.
|
|
436
632
|
|
|
437
633
|
`placeholder`, `name` (a second field with the raw text), `aria-describedby`, `onFocusCapture` (to react to focus) and other input props pass through. During a primary mouse or pen press while the listbox is open, the Input's `onPointerUp`, `onMouseUp` and `onDoubleClick` go to the Popup instead (the press is captured to it), and the Input gets pointer and mouse leave (then enter) events. A `render` element must stay an `<input>` of type text or search.
|
|
438
634
|
|
|
@@ -446,10 +642,10 @@ One per Root: the Input is the listbox's anchor, so a second `Combobox.Input` in
|
|
|
446
642
|
| `children` | `ReactNode \| ((state: ComboboxTriggerState \| ComboboxClearState) => ReactNode)` | – | Content, usually an icon; give the button an `aria-label` (development warns without a name). |
|
|
447
643
|
| `render` | `ReactElement \| ((props, state: ComboboxTriggerState \| ComboboxClearState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
448
644
|
|
|
449
|
-
- **State**: `ComboboxTriggerState` is `{ open, pending, disabled }`; `ComboboxClearState` is `{ value, inputValue, disabled }
|
|
645
|
+
- **State**: `ComboboxTriggerState` is `{ open, pending, disabled }`; `ComboboxClearState` is `{ value, values, inputValue, disabled }` (`values` as on the Input).
|
|
450
646
|
- **Owned**: `type` (on a `<button>`), `tabIndex` (`-1`: the input is the one Tab stop), `disabled`, `aria-disabled` (link or component `render`), `onClick`, `onPointerDown`, `onMouseDown`, `data-disabled`; the Trigger also `aria-expanded` (only when it is no invoker: a non-button `render`, or while `aria-disabled`), `aria-controls`, `popovertarget` (written as an attribute after hydration, only on a `<button>`, while enabled or natively disabled; not while `aria-disabled`), `data-open`, `data-pending`. Owned on the Trigger and never written as props: `popoverTarget`, `popoverTargetAction`, `commandfor`, `command`; these and `aria-expanded` are not in its props type.
|
|
451
647
|
|
|
452
|
-
Both keep focus in the input when pressed and focus it when clicked. The Trigger toggles the listbox; on a `<button>` Trigger a click while it is open keeps it shown until `openChangeAction(false)` settles (a controlled parent that keeps `open` sees no flicker). A Trigger rendered as another element is light-dismissed before its click and warns in development ([Triggers of a popup](../concepts/browser-owned-state.md#popup-triggers)). Clear empties the text and dispatches `null` unless nothing is selected; it is always rendered, so hide it with CSS (`:has(input:placeholder-shown)`) or its state. A click on Clear while the listbox is open closes it (light dismiss: the button is outside the popup).
|
|
648
|
+
Both keep focus in the input when pressed and focus it when clicked. The Trigger toggles the listbox; on a `<button>` Trigger a click while it is open keeps it shown until `openChangeAction(false)` settles (a controlled parent that keeps `open` sees no flicker). A Trigger rendered as another element is light-dismissed before its click and warns in development ([Triggers of a popup](../concepts/browser-owned-state.md#popup-triggers)). Clear empties the text and dispatches `null` unless nothing is selected (with `multiple`: one change removing every value, announced); it is always rendered, so hide it with CSS (`:has(input:placeholder-shown)`) or its state. A click on Clear while the listbox is open closes it (light dismiss: the button is outside the popup).
|
|
453
649
|
|
|
454
650
|
### `Combobox.Popup`
|
|
455
651
|
|
|
@@ -477,7 +673,7 @@ Inline style `position-area: self-block-end span-self-inline-end; position-try-f
|
|
|
477
673
|
| `render` | `ReactElement \| ((props, state: ComboboxListState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
|
|
478
674
|
|
|
479
675
|
- **State**: `ComboboxListState` is `{ query, stale, empty }`.
|
|
480
|
-
- **Owned**: `id`, `role` (`"listbox"`), `aria-labelledby` (token-merged with yours; only while a `Combobox.Label` is rendered), `aria-busy`, `data-stale`, `data-empty
|
|
676
|
+
- **Owned**: `id`, `role` (`"listbox"`), `aria-labelledby` (token-merged with yours; only while a `Combobox.Label` is rendered), `aria-busy`, `data-stale`, `data-empty`; with `multiple`, `aria-multiselectable` (`"true"`).
|
|
481
677
|
|
|
482
678
|
Without a Label give the List an `aria-label` (development warns otherwise). `aria-busy="true"` is set while the results are stale or loading (a `Status` fallback inside it); `data-empty` when settled with no options.
|
|
483
679
|
|
|
@@ -493,7 +689,7 @@ Without a Label give the List an `aria-label` (development warns otherwise). `ar
|
|
|
493
689
|
| `children` | `ReactNode \| ((state: ComboboxOptionState) => ReactNode)` | – | Content, or a function of the option's state; must not suspend. |
|
|
494
690
|
| `render` | `ReactElement \| ((props, state: ComboboxOptionState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
|
|
495
691
|
|
|
496
|
-
- **State**: `ComboboxOptionState` is `{ value, selected, active, pending, disabled }`; `selected` is optimistic, `active` is virtual focus, `pending` is true on the option being saved.
|
|
692
|
+
- **State**: `ComboboxOptionState` is `{ value, selected, active, pending, disabled }`; `selected` is optimistic, `active` is virtual focus, `pending` is true on the option being saved (with `multiple`: being added or removed).
|
|
497
693
|
- **Owned**: `id` (derived from `value`), `role`, `aria-selected`, `aria-disabled`, `onClick`, `onPointerDown`, `onMouseDown`, `onPointerMove`, `data-selected`, `data-active`, `data-pending`, `data-disabled`.
|
|
498
694
|
|
|
499
695
|
Never focused, no `tabindex`; hovering makes it active.
|
|
@@ -512,6 +708,50 @@ Never focused, no `tabindex`; hovering makes it active.
|
|
|
512
708
|
|
|
513
709
|
`Group` is named by the `GroupLabel` inside it. `Status` inside the List (as a Suspense fallback) marks the results as loading (the List is `aria-busy`); in the Popup it is a plain hint. `Empty` is a plain `<div>` that renders nothing unless the results are settled and empty, so "No results" never flashes during a search.
|
|
514
710
|
|
|
711
|
+
### `Combobox.Chips` (with `multiple`)
|
|
712
|
+
|
|
713
|
+
| Prop | Type | Default | Description |
|
|
714
|
+
| - | - | - | - |
|
|
715
|
+
| `className` | `string \| ((state: ComboboxChipsState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
716
|
+
| `style` | `CSSProperties \| ((state: ComboboxChipsState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
717
|
+
| `children` | `ReactNode \| ((state: ComboboxChipsState) => ReactNode)` | – | Usually a function of `{ value }` rendering one `Combobox.Chip` per value, keyed by the value; must not suspend. |
|
|
718
|
+
| `render` | `ReactElement \| ((props, state: ComboboxChipsState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
|
|
719
|
+
|
|
720
|
+
- **State**: `ComboboxChipsState` is `{ value, pending, disabled }`; `value` is the optimistic selection in pick order, `pending` the value action in flight.
|
|
721
|
+
- **Owned**: `role` (`"list"`, absent while empty), `aria-labelledby` (the Label, token-merged; absent while empty), `onKeyDown` (the chip keys), `onPointerDown`, `onMouseDown`, `onClick` (a press keeps focus where it is; a click focuses the Input), `onFocus`, `onBlur` (a chip is inside the combobox: focus on it closes the listbox and keeps the text), `data-empty`, `data-pending`, `data-disabled`.
|
|
722
|
+
|
|
723
|
+
The list of chips, not the field box: render the Input next to it, in your own element. Under a Root without `multiple` it warns in development and renders empty.
|
|
724
|
+
|
|
725
|
+
### `Combobox.Chip`
|
|
726
|
+
|
|
727
|
+
| Prop | Type | Default | Description |
|
|
728
|
+
| - | - | - | - |
|
|
729
|
+
| `value` | `string` | – | Required: a value of the selection (development warns otherwise). |
|
|
730
|
+
| `label` | `string` | – | The chip's text for the removal announcement. Default: the state's `label`, else the chip's trimmed text. |
|
|
731
|
+
| `className` | `string \| ((state: ComboboxChipState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
732
|
+
| `style` | `CSSProperties \| ((state: ComboboxChipState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
733
|
+
| `children` | `ReactNode \| ((state: ComboboxChipState) => ReactNode)` | – | Content, or a function of the chip's state; default `label ?? value`. Must not suspend. |
|
|
734
|
+
| `render` | `ReactElement \| ((props, state: ComboboxChipState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |
|
|
735
|
+
|
|
736
|
+
- **State**: `ComboboxChipState` is `{ value, label, pending, disabled }`. `label` is the text of the option with this value as the library last saw it (written at the pick), `undefined` if no option for it was ever rendered (a preselected value before the listbox first opens). `pending`: its addition is not committed yet.
|
|
737
|
+
- **Owned**: `role` (`"listitem"`), `tabIndex` (`-1`), `data-pending`, `data-disabled`.
|
|
738
|
+
|
|
739
|
+
Focused by keys only, never a Tab stop. On a focused chip: the previous / next arrow (in the inline direction) moves, the next arrow past the last chip returns to the Input, Home / End go to the first / last chip, Backspace and Delete remove it (focus moves first to the next chip, else the previous, else the Input), Escape returns to the Input, a printable key types into the Input; Enter and Space do nothing. `aria-description` passes through for a hint such as "Press Backspace to remove".
|
|
740
|
+
|
|
741
|
+
### `Combobox.ChipRemove`
|
|
742
|
+
|
|
743
|
+
| Prop | Type | Default | Description |
|
|
744
|
+
| - | - | - | - |
|
|
745
|
+
| `className` | `string \| ((state: ComboboxChipRemoveState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
746
|
+
| `style` | `CSSProperties \| ((state: ComboboxChipRemoveState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
747
|
+
| `children` | `ReactNode \| ((state: ComboboxChipRemoveState) => ReactNode)` | – | Content, usually an icon in an `aria-hidden` element (never read as part of the chip's text in the removal announcement, nor is any `aria-hidden` content); give the button an `aria-label` (development warns without a name). |
|
|
748
|
+
| `render` | `ReactElement \| ((props, state: ComboboxChipRemoveState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
749
|
+
|
|
750
|
+
- **State**: `ComboboxChipRemoveState` is `{ value, pending, disabled }` (the Chip's value and pending).
|
|
751
|
+
- **Owned**: `type` (on a `<button>`), `tabIndex` (`-1`), `disabled` (the Root's), `aria-disabled` (link or component `render`), `onClick`, `onPointerDown`, `onMouseDown`, `data-pending`, `data-disabled`.
|
|
752
|
+
|
|
753
|
+
Inside a `Combobox.Chip` (outside one it throws). A press keeps focus in the Input; the click removes the chip's value, announces it and focuses the Input. A press while the listbox is open closes it (light dismiss), as Clear's does.
|
|
754
|
+
|
|
515
755
|
## Data attributes
|
|
516
756
|
|
|
517
757
|
| Hook | On | Meaning |
|
|
@@ -519,13 +759,16 @@ Never focused, no `tabindex`; hovering makes it active.
|
|
|
519
759
|
| `data-open` | Input, Trigger | Optimistic open state. The Input's `aria-expanded` follows the shown listbox instead; a `<button>` Trigger has no `aria-expanded` (the browser exposes its state). |
|
|
520
760
|
| `data-pending` | Input | A selection or an open is in flight (the Root's `pending`). |
|
|
521
761
|
| `data-pending` | Trigger | The open (or close) is in flight. |
|
|
522
|
-
| `data-pending` | Option | The option the in-flight selection is choosing. |
|
|
523
|
-
| `data-
|
|
762
|
+
| `data-pending` | Option | The option the in-flight selection is choosing (with `multiple`: being added or removed). |
|
|
763
|
+
| `data-pending` | Chip, ChipRemove | With `multiple`: the chip's addition is not committed yet (a removed chip is gone at once). |
|
|
764
|
+
| `data-pending` | Chips | With `multiple`: a value action is in flight. |
|
|
765
|
+
| `data-selected` | Input | A value is selected (optimistic, not `null`; with `multiple`, at least one). |
|
|
524
766
|
| `data-selected` | Option | This option is the optimistic selection. |
|
|
525
767
|
| `data-active` | Option | `aria-activedescendant` points here (keyboard or hover). |
|
|
526
768
|
| `data-stale` | Input, Popup, List | The results shown are for an older text; the List also has `aria-busy`. |
|
|
527
769
|
| `data-empty` | List | Settled with no options. |
|
|
528
|
-
| `data-
|
|
770
|
+
| `data-empty` | Chips | With `multiple`: nothing is selected. |
|
|
771
|
+
| `data-disabled` | Input, Trigger, Clear, Option, Chips, Chip, ChipRemove | Disabled. |
|
|
529
772
|
| `:popover-open` | Popup | The listbox is shown (browser-owned, no attribute). |
|
|
530
773
|
|
|
531
774
|
## Keyboard and ARIA
|
|
@@ -545,6 +788,24 @@ Never focused, no `tabindex`; hovering makes it active.
|
|
|
545
788
|
|
|
546
789
|
Disabled options are skipped. Keys during an IME composition belong to the composition. Ctrl and Meta combinations are left alone.
|
|
547
790
|
|
|
791
|
+
With `multiple`, in the Input (the chip keys are with [Combobox.Chip](#props)):
|
|
792
|
+
|
|
793
|
+
| Key | When | Behaviour |
|
|
794
|
+
| - | - | - |
|
|
795
|
+
| Enter | open, active option | Toggles it; the listbox stays open. |
|
|
796
|
+
| Enter | open, no active option | Adds the text as a value with `allowCustomValue`; otherwise nothing. |
|
|
797
|
+
| Enter | opening (requested, not shown yet), text typed | Nothing: prevented, the text is kept (you are about to pick). Right after Escape the closed rule below applies. |
|
|
798
|
+
| Enter | closed, text typed | `allowCustomValue`: adds the text (prevented, the form does not submit). Otherwise clears the text, then a form submits. |
|
|
799
|
+
| Alt+ArrowUp | open | Closes; the active option is not toggled. |
|
|
800
|
+
| Backspace | empty text | Removes the last chip and announces it (not on key repeat). |
|
|
801
|
+
| Left (Right in RTL) | caret at the start | Moves focus to the last chip; the listbox closes, the text stays. |
|
|
802
|
+
|
|
803
|
+
Screen readers hear a toggled option through its `aria-selected` under `aria-activedescendant`; a chip removed outside the listbox is announced with `ariaNotify()` on the Input (`"Japan removed"`). The label is the Chip's `label`, else the option text the library saw, else the chip's text without its `ChipRemove` and without `aria-hidden` content. The announcement is optimistic: if the removal's save fails the chip comes back without a second announcement. Localise it with:
|
|
804
|
+
|
|
805
|
+
```tsx
|
|
806
|
+
<Combobox.Root multiple announceRemoved={(labels) => `${labels.join("、")}を削除しました`}>
|
|
807
|
+
```
|
|
808
|
+
|
|
548
809
|
### Accessibility and announcements
|
|
549
810
|
|
|
550
811
|
- The Input is `role="combobox"` with `aria-autocomplete="list"`, `aria-expanded`, `aria-controls` (the List) and `aria-activedescendant` (the active option, never a stale id; removed while you edit the text). Name it with `Combobox.Label`, which names the listbox too.
|
|
@@ -558,13 +819,13 @@ Disabled options are skipped. Keys during an IME composition belong to the compo
|
|
|
558
819
|
|
|
559
820
|
Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)
|
|
560
821
|
|
|
561
|
-
Every value dispatch: `fsui-combobox` and `fsui-combobox-select
|
|
822
|
+
Every value dispatch: `fsui-combobox` and `fsui-combobox-select` (with `multiple`: `-select` when something is added, `fsui-combobox-deselect` when something is removed). Opens and closes: `fsui-combobox` plus `fsui-combobox-open` or `fsui-combobox-close`. A deferred results render carries no `fsui-*` type, so give the Popup's `transition` a map with `default: "none"`.
|
|
562
823
|
|
|
563
824
|
## Optimistic and pending
|
|
564
825
|
|
|
565
826
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
566
827
|
|
|
567
|
-
The selected value and the open state are optimistic (`data-selected` on the Input and the Option). `data-pending` is on the Input while a selection or an open is in flight, on the Trigger while an open or close is, and on the Option being chosen. The typed text is urgent, not optimistic (a [fact](../concepts/action-props.md#fact), reported to `onInputValueChange`).
|
|
828
|
+
The selected value and the open state are optimistic (`data-selected` on the Input and the Option). `data-pending` is on the Input while a selection or an open is in flight, on the Trigger while an open or close is, and on the Option being chosen. With `multiple` the chips render from the optimistic value: a removed chip disappears at once and returns if its save fails, an added chip has `data-pending` until it is committed. The typed text is urgent, not optimistic (a [fact](../concepts/action-props.md#fact), reported to `onInputValueChange`).
|
|
568
829
|
|
|
569
830
|
### A slow `openChangeAction`
|
|
570
831
|
|
|
@@ -659,6 +920,7 @@ A plain text field: typing works and the form posts the default selection (and t
|
|
|
659
920
|
## Forms
|
|
660
921
|
|
|
661
922
|
- `name` on the Root posts the value through a hidden input (`""` for `null`); a `name` on the Input posts the raw text as well. `required` on the Input is native.
|
|
923
|
+
- With `multiple`: one hidden input per value, so the form posts what same-named checkboxes would (`formData.getAll(name)`, nothing for an empty selection). `required` means at least one value (see [Multiple selection](#multiple)). A form reset replaces the whole selection with the reset target, even while saves are still running. Inside a `Field.Root`, `validate` gets the first value; read the others from `formData.getAll(name)`.
|
|
662
924
|
- A form reset (the Reset button, `form.reset()`, or React's automatic reset after a form action) dispatches `valueChangeAction` with `reason: "platform"` and writes the text: uncontrolled, back to the latest `defaultValue` / `defaultInputValue`; controlled, to the mount-time values.
|
|
663
925
|
- Text typed before hydration (and Firefox's form restoration) is kept and reported once through `onInputValueChange` with `reason: "platform"`.
|
|
664
926
|
|
|
@@ -686,7 +948,7 @@ A plain text field: typing works and the form posts the default selection (and t
|
|
|
686
948
|
>
|
|
687
949
|
```
|
|
688
950
|
|
|
689
|
-
Types: every value dispatch adds `fsui-combobox` and `fsui-combobox-select`; opens and closes add `fsui-combobox-open` / `fsui-combobox-close`.
|
|
951
|
+
Types: every value dispatch adds `fsui-combobox` and `fsui-combobox-select`; opens and closes add `fsui-combobox-open` / `fsui-combobox-close`. With `multiple`, a value dispatch adds `fsui-combobox-select` when it adds a value and `fsui-combobox-deselect` when it removes one. Chips have no `transition` prop: to animate them, wrap each in your own `<ViewTransition>` and key on these types.
|
|
690
952
|
|
|
691
953
|
Keep the CSS exit above next to `transition`: it animates the dismissals (focus leaving, Escape, a click outside). The library turns the popup's CSS transitions off for the moment of its own show and hide while a view transition runs, so you need no extra rule ([A popup with a CSS exit and a view transition](../concepts/transitions.md#css-exit)).
|
|
692
954
|
|
|
@@ -193,6 +193,8 @@ ul.demo-list .demo-row {
|
|
|
193
193
|
}
|
|
194
194
|
```
|
|
195
195
|
|
|
196
|
+
For confirmations, [AlertDialog](alert-dialog.md) is this pattern with the defaults built in: `role="alertdialog"`, no light dismiss, focus on Cancel, and a confirm button that runs an async action.
|
|
197
|
+
|
|
196
198
|
This confirmation is a Server Component in JS-free mode. Every button is a native invoker or a `method="dialog"` submit, so it works before hydration and with JavaScript disabled.
|
|
197
199
|
|
|
198
200
|
## Anatomy
|
|
@@ -283,13 +285,13 @@ One per Root: focus returns to the Trigger that mounted last, and a non-modal di
|
|
|
283
285
|
- **State**: `DialogPopupState` is `{ open, modal }`; `open` is committed (`false` in JS-free mode; `:open` is the DOM truth).
|
|
284
286
|
- **Owned**: `id`, `open` (never rendered: opening goes through `showModal()` only), `closedby`, `data-modal`, `suppressHydrationWarning`; `aria-labelledby` and `aria-describedby` are merged with yours. `onToggle` and `onBeforeToggle` are not accepted: use a `ref` for the platform events.
|
|
285
287
|
|
|
286
|
-
Other props, such as `role
|
|
288
|
+
Other props, such as `role` or `onCancel`, pass through. For a confirmation, use [AlertDialog](alert-dialog.md): `role="alertdialog"`, no light dismiss and focus on Cancel are its defaults.
|
|
287
289
|
|
|
288
290
|
### `Dialog.Close`
|
|
289
291
|
|
|
290
292
|
| Prop | Type | Default | Description |
|
|
291
293
|
| - | - | - | - |
|
|
292
|
-
| `action` | `Action<[details: DialogCloseDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the dialog with `value` as `returnValue`: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set; the button stays pending until the dialog closes), in JS-free mode with `close(value)`. A rejection reaches the nearest Error Boundary above the button and leaves the dialog open. If the dialog was closed and opened again while the action ran, the close is dropped: it belonged to the previous opening. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"`. Without `action` the button is a native `command="request-close"` invoker in JS-free mode and goes straight through the Root in library mode. `details.returnValue` is the `value`. |
|
|
294
|
+
| `action` | `Action<[details: DialogCloseDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the dialog with `value` as `returnValue`: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set; the button stays pending until the dialog closes), in JS-free mode with `close(value)`. A rejection reaches the nearest Error Boundary above the button and leaves the dialog open. If the dialog was closed and opened again while the action ran, the close is dropped: it belonged to the previous opening. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"`. With `action` the button renders no `commandfor` / `command`, so a click before hydration does nothing (rather than closing the dialog without running the action). Without `action` the button is a native `command="request-close"` invoker in JS-free mode and goes straight through the Root in library mode. `details.returnValue` is the `value`. |
|
|
293
295
|
| `whilePending` | `"run" \| "ignore"` | `"ignore"` | What a click, Enter or Space does while this part's `action` is pending. `"ignore"`: nothing (the click is cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again (`data-pending` until every run has settled, no `aria-disabled`); the dialog closes once the last run has settled, and only if the latest run resolved: a rejection leaves it open in both modes. No effect without `action`. See [A second click while pending](../concepts/pending-and-optimistic.md#second-click). |
|
|
294
296
|
| `value` | `string` | – | Becomes `dialog.returnValue`, and `details.returnValue` of `openChangeAction(false)`. |
|
|
295
297
|
| `disabled` | `boolean` | `false` | Native `disabled`; owned, so a `render` element cannot re-enable it. With a link or component `render` where the Close handles the click (library mode, or with `action`), `aria-disabled="true"` instead (the element stays focusable). A host link is `aria-disabled` in every mode (it cannot be natively disabled), and its click is cancelled. |
|
|
@@ -299,7 +301,7 @@ Other props, such as `role="alertdialog"` or `onCancel`, pass through.
|
|
|
299
301
|
| `render` | `ReactElement \| ((props, state: DialogCloseState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
300
302
|
|
|
301
303
|
- **State**: `DialogCloseState` is `{ pending, disabled }`.
|
|
302
|
-
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled`, `commandfor`, `command` (not on a link or other non-button host element), `value`, `onClick` (library mode, or with `action`), `data-pending`, `data-disabled`; a `render` element cannot re-enable a disabled Close.
|
|
304
|
+
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled`, `commandfor`, `command` (not with `action`, and not on a link or other non-button host element), `value`, `onClick` (library mode, or with `action`), `data-pending`, `data-disabled`; a `render` element cannot re-enable a disabled Close.
|
|
303
305
|
|
|
304
306
|
By default (`whilePending="ignore"`) a second click, Enter or Space while the action is pending is ignored (and cancelled), and the button is `aria-disabled="true"` for as long as it shows `data-pending`, which spans the action and the close; it is never natively disabled, so it keeps focus. To close at once and finish the work in the background, do not return the promise: `action={() => { void save(); }}`.
|
|
305
307
|
|
|
@@ -374,7 +376,7 @@ The CSS exit animates in Chromium and Safari; Firefox closes a dialog instantly.
|
|
|
374
376
|
| Escape in a nested dialog | Closes the innermost one only | the browser |
|
|
375
377
|
| Enter in a form field | Submits the Form: closes (through the Root in library mode), or runs the action and then closes | the browser / Form |
|
|
376
378
|
|
|
377
|
-
- The Popup's role is the native `dialog`; `aria-modal` is exposed by the browser after `showModal()`, never set by hand. `role="alertdialog"` passes through. `aria-labelledby` and `aria-describedby` point at Title and Description. A Popup with neither a Title nor an `aria-label` is a development warning.
|
|
379
|
+
- The Popup's role is the native `dialog`; `aria-modal` is exposed by the browser after `showModal()`, never set by hand. `role="alertdialog"` passes through; for a confirmation that needs an answer, [AlertDialog](alert-dialog.md) renders it for you, with no light dismiss and focus on Cancel. `aria-labelledby` and `aria-describedby` point at Title and Description. A Popup with neither a Title nor an `aria-label` is a development warning.
|
|
378
380
|
- There is no focus trap: `showModal()` makes the rest of the page inert. Focus return is the platform's; the library only steps in when the opener has been removed (focus goes to the Trigger if it is still there, else to the body), and when a library-driven close of a non-modal dialog unmounted the focused button before the dialog closed (focus goes to the Trigger).
|
|
379
381
|
- For long or destructive dialogs, focus a static element so the title is heard first: `initialFocus` pointing at a `<Dialog.Title tabIndex={-1}>`.
|
|
380
382
|
- The Trigger is a plain button: no `aria-expanded`, no `aria-haspopup`. Give an icon-only Close an `aria-label`.
|
|
@@ -554,7 +556,7 @@ JS-free mode: the browser owns everything through Invoker Commands. Library mode
|
|
|
554
556
|
|
|
555
557
|
Concept: [Server Components](../concepts/server-components.md#before-hydration)
|
|
556
558
|
|
|
557
|
-
JS-free mode: everything for a modal dialog: open (`command="show-modal"`), Escape, Close buttons (`command="request-close"`), `<form method="dialog">`, focus and focus return, `autoFocus` in server-rendered markup, CSS animation; a `Dialog.Form` with a Server Function action submits with React's progressive enhancement. Hydration adds `initialFocus`, `lightDismiss` and closing after a form action. A non-modal dialog needs JavaScript to open. Library mode: the Trigger opens the dialog natively, but its content is not in the HTML; on hydration it is reconciled with one `openChangeAction(true)` call (`reason: "platform"`) and the content mounts.
|
|
559
|
+
JS-free mode: everything for a modal dialog: open (`command="show-modal"`), Escape, Close buttons without `action` (`command="request-close"`; one with `action` does nothing until hydration), `<form method="dialog">`, focus and focus return, `autoFocus` in server-rendered markup, CSS animation; a `Dialog.Form` with a Server Function action submits with React's progressive enhancement. Hydration adds `initialFocus`, `lightDismiss` and closing after a form action. A non-modal dialog needs JavaScript to open. Library mode: the Trigger opens the dialog natively, but its content is not in the HTML; on hydration it is reconciled with one `openChangeAction(true)` call (`reason: "platform"`) and the content mounts.
|
|
558
560
|
|
|
559
561
|
### The [platform paths](../concepts/browser-owned-state.md#platform-path)
|
|
560
562
|
|