@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
|
@@ -194,6 +194,24 @@ export function FieldSignUp() {
|
|
|
194
194
|
border: 0;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/* A native fieldset around several Fields (no Fieldset part). Its `disabled` is inherited by
|
|
198
|
+
every control, which `data-disabled` does not see: select the platform's `:disabled`. */
|
|
199
|
+
.demo-address {
|
|
200
|
+
display: grid;
|
|
201
|
+
gap: 1rem;
|
|
202
|
+
margin: 0;
|
|
203
|
+
padding: 0.75rem 1rem 1rem;
|
|
204
|
+
border: 1px solid var(--color-border);
|
|
205
|
+
border-radius: 8px;
|
|
206
|
+
min-inline-size: 0;
|
|
207
|
+
}
|
|
208
|
+
.demo-address > legend {
|
|
209
|
+
padding: 0 0.3em;
|
|
210
|
+
}
|
|
211
|
+
.demo-address .demo-fieldset:has(:disabled) {
|
|
212
|
+
opacity: 0.5;
|
|
213
|
+
}
|
|
214
|
+
|
|
197
215
|
/* The form's submission: the whole form dims, the button blocks repeat clicks with CSS. */
|
|
198
216
|
.demo-form[data-pending] .demo-fieldset {
|
|
199
217
|
opacity: 0.7;
|
|
@@ -231,8 +249,8 @@ import { Form } from "@funstack/ui/form";
|
|
|
231
249
|
```
|
|
232
250
|
|
|
233
251
|
- **`Field.Root` is a `div`** that owns the ids and the field's state. `name`, `required` and `disabled` go to the control unless it sets its own.
|
|
234
|
-
- **`Field.Control` is a native `<input>`**, or a `<textarea>` / `<select>` through `render`. Every other input prop passes through (`type`, `defaultValue`, a controlled `value` / `onChange`, `pattern`, …).
|
|
235
|
-
- **Any FUNSTACK form control is a Field's control** without a wrapper: Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, Slider and NumberField (see [Slider inside a Field](slider.md#inside-a-field) and [NumberField inside a Field](number-field.md#inside-a-field)). A group (RadioGroup, CheckboxGroup, a Slider with several thumbs) is named by `Field.Label` through `aria-labelledby` instead of `for`. A RadioGroup carries `aria-invalid` on its `radiogroup`; a CheckboxGroup and a Slider on every item, because ARIA 1.2 does not support it on a `group`.
|
|
252
|
+
- **`Field.Control` is a native `<input>`**, or a `<textarea>` / `<select>` through `render`. Every other input prop passes through (`type`, `defaultValue`, a controlled `value` / `onChange`, `pattern`, …). Outside a `Field.Root` it is the plain control ([on its own](#field-control-alone)). There is no Input, Textarea or Fieldset part: the native elements, with the [textarea](#textarea) and [fieldset](#fieldset) recipes below.
|
|
253
|
+
- **Any FUNSTACK form control is a Field's control** without a wrapper: Checkbox, Switch, RadioGroup, CheckboxGroup, Select, Combobox, MultiSelect, Slider and NumberField (see [Slider inside a Field](slider.md#inside-a-field) and [NumberField inside a Field](number-field.md#inside-a-field)). A group (RadioGroup, CheckboxGroup, a Slider with several thumbs) is named by `Field.Label` through `aria-labelledby` instead of `for`. A RadioGroup carries `aria-invalid` on its `radiogroup`; a CheckboxGroup and a Slider on every item, because ARIA 1.2 does not support it on a `group`.
|
|
236
254
|
- **`Field.Error` is rendered only while an error is shown**. Write it once, unconditionally; its text is the browser's message, a server error, or what your function `children` return. An error that appears on blur can shift the layout, so a click right after typing (the click's press is the blur) may miss a button that moved; reserve the error's space if that matters.
|
|
237
255
|
- `Field.Description` is always referenced by the control, rendered or not.
|
|
238
256
|
|
|
@@ -333,6 +351,7 @@ const [state, dispatch] = useActionState(saveProfile, {});
|
|
|
333
351
|
|
|
334
352
|
| Prop | Type | Default | Description |
|
|
335
353
|
| - | - | - | - |
|
|
354
|
+
| `id` | `string` | – | Native `id`, outside a `Field.Root` only. Inside one the Field owns the id (so `Field.Label` can point at it) and this prop is ignored with a development warning. |
|
|
336
355
|
| `name` | `string` | `the Field's` | Native `name`. |
|
|
337
356
|
| `required, disabled` | `boolean` | `the Field's` | Native; the Field's value also applies (either one is enough). |
|
|
338
357
|
| `className` | `string \| ((state: FieldState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
@@ -341,7 +360,9 @@ const [state, dispatch] = useActionState(saveProfile, {});
|
|
|
341
360
|
| `…` | `native` | – | Every other `<input>` prop passes through; the Field's listeners are native, so your `onInput` / `onBlur` run independently. |
|
|
342
361
|
|
|
343
362
|
- **State**: the Field's.
|
|
344
|
-
- **Owned**: `id`, `name`, `required`, `disabled`, `aria-invalid` (always `"true"` or `"false"`: it stops Chromium announcing a `typeMismatch` before it is shown, and exposes `valueMissing`, which it otherwise never does), `aria-describedby` (your tokens first, then the description, then the error while shown), and the Field's four `data-*` attributes.
|
|
363
|
+
- **Owned**: Inside a Field: `id`, `name`, `required`, `disabled`, `aria-invalid` (always `"true"` or `"false"`: it stops Chromium announcing a `typeMismatch` before it is shown, and exposes `valueMissing`, which it otherwise never does), `aria-describedby` (your tokens first, then the description, then the error while shown), and the Field's four `data-*` attributes.
|
|
364
|
+
|
|
365
|
+
Outside a `Field.Root` it is the plain native control: every prop passes through (`id` included), the library adds no attribute, and the function props receive a `FieldState` with the control's own `disabled` / `required` and a constant valid, not-pending rest. The other Field parts still throw outside a Field. See [Field.Control on its own](#field-control-alone).
|
|
345
366
|
|
|
346
367
|
### `Field.Error`
|
|
347
368
|
|
|
@@ -584,5 +605,161 @@ export function FieldControls() {
|
|
|
584
605
|
- Inside a `Field.Root` the control's `id` belongs to the Field (so `Field.Label` can point at it); `name`, `required` and `disabled` default from the Field.
|
|
585
606
|
- The [two channels](../concepts/action-props.md#form-channel) stay separate: a control's own action (the Switch above saves on its own) gives _it_ `data-pending`; the form's submission gives the Field `data-pending`, never the control.
|
|
586
607
|
- Combobox: the `Combobox.Input` is the control, the hidden input takes the Field's `name`, and the listbox is named by `Field.Label` when no `Combobox.Label` is rendered. `validate` reads the selection (the hidden input), and picking an option counts as an edit: it re-runs `validate` and dismisses a server error, like typing.
|
|
608
|
+
- MultiSelect: the Trigger (a `<button>`) is the control; `Field.Label` focuses it instead of clicking it, as a label does for a `<select>`. Its validity is a hidden `<select>`'s, which shows no browser bubble, so `Field.Error` is where a `required` message appears ([MultiSelect forms](multi-select.md#forms)).
|
|
587
609
|
- NumberField: the visible text input is the control (labelled, described, focused), while its validity is the hidden `<input type="number">`'s, so `Field.Error`'s function `children` can branch on `validity.stepMismatch`, `rangeUnderflow` or `rangeOverflow`: `{({ validity, messages }) => validity.stepMismatch ? "Enter a multiple of six." : messages.join(" ")}`. `validate` reads the committed number, never a half-typed draft.
|
|
588
610
|
- "Submit on change": `checkedChangeAction={() => formRef.current?.requestSubmit()}` goes through the Form like a click. Never call `form.submit()`, which skips validation and the Form.
|
|
611
|
+
|
|
612
|
+
### <a id="fieldset"></a>Fields in a fieldset
|
|
613
|
+
|
|
614
|
+
There is no Fieldset part: a set of Fields with a common caption is the native `<fieldset>`, which already names the group (`<legend>`), describes it (`aria-describedby`) and disables every native control inside it. Every FUNSTACK form control has a native element, so `<fieldset disabled>` reaches them all: they leave the `FormData`, skip validation and the Tab order, and the pointer surfaces (a Slider's Track, NumberField's buttons) ignore presses too.
|
|
615
|
+
|
|
616
|
+
```tsx title="FieldAddress.tsx"
|
|
617
|
+
"use client";
|
|
618
|
+
import { useRef, useState } from "react";
|
|
619
|
+
import { Field } from "@funstack/ui/field";
|
|
620
|
+
import { Form } from "@funstack/ui/form";
|
|
621
|
+
import { NumberField } from "@funstack/ui/number-field";
|
|
622
|
+
import { fakeSave } from "./fake-api.js";
|
|
623
|
+
|
|
624
|
+
// A native <fieldset> captions a set of Fields and disables all of them: every FUNSTACK control
|
|
625
|
+
// has a native element, so `disabled` on the fieldset reaches each one (and the NumberField's
|
|
626
|
+
// buttons ignore the pointer too). The library's `data-disabled` does not see an inherited
|
|
627
|
+
// `disabled`, so the CSS selects `:disabled` instead. The fieldset is never disabled because a
|
|
628
|
+
// submission is pending: that would drop focus; after a save, focus moves to the checkbox before
|
|
629
|
+
// the fieldset is disabled, for the same reason. The notes are a textarea that grows with its
|
|
630
|
+
// content (`field-sizing: content`).
|
|
631
|
+
export function FieldAddress() {
|
|
632
|
+
const [editing, setEditing] = useState(false);
|
|
633
|
+
const [saved, setSaved] = useState<string | null>(null);
|
|
634
|
+
const editRef = useRef<HTMLInputElement>(null);
|
|
635
|
+
return (
|
|
636
|
+
<Form.Root
|
|
637
|
+
className="demo-form"
|
|
638
|
+
autoReset={false}
|
|
639
|
+
action={async (formData) => {
|
|
640
|
+
await fakeSave("the address");
|
|
641
|
+
setSaved(`${String(formData.get("street"))}, ${String(formData.get("city"))}`);
|
|
642
|
+
// Disabling the fieldset would drop focus from the Save button inside it: move focus to
|
|
643
|
+
// the checkbox (outside the fieldset) first.
|
|
644
|
+
editRef.current?.focus();
|
|
645
|
+
setEditing(false);
|
|
646
|
+
}}
|
|
647
|
+
>
|
|
648
|
+
<label className="demo-field">
|
|
649
|
+
<input
|
|
650
|
+
ref={editRef}
|
|
651
|
+
type="checkbox"
|
|
652
|
+
checked={editing}
|
|
653
|
+
onChange={(e) => setEditing(e.target.checked)}
|
|
654
|
+
/>{" "}
|
|
655
|
+
Edit the address
|
|
656
|
+
</label>
|
|
657
|
+
<fieldset className="demo-address" disabled={!editing} aria-describedby="address-hint">
|
|
658
|
+
<legend className="demo-label">Shipping address</legend>
|
|
659
|
+
<p id="address-hint" className="demo-description">
|
|
660
|
+
Used for this order only.
|
|
661
|
+
</p>
|
|
662
|
+
<Field.Root name="street" required className="demo-fieldset">
|
|
663
|
+
<Field.Label className="demo-label">Street</Field.Label>
|
|
664
|
+
<Field.Control
|
|
665
|
+
className="demo-input"
|
|
666
|
+
autoComplete="address-line1"
|
|
667
|
+
defaultValue="1 Main St"
|
|
668
|
+
/>
|
|
669
|
+
<Field.Error className="demo-field-error" />
|
|
670
|
+
</Field.Root>
|
|
671
|
+
<Field.Root name="city" required className="demo-fieldset">
|
|
672
|
+
<Field.Label className="demo-label">City</Field.Label>
|
|
673
|
+
<Field.Control
|
|
674
|
+
className="demo-input"
|
|
675
|
+
autoComplete="address-level2"
|
|
676
|
+
defaultValue="Springfield"
|
|
677
|
+
/>
|
|
678
|
+
<Field.Error className="demo-field-error" />
|
|
679
|
+
</Field.Root>
|
|
680
|
+
<Field.Root name="floor" className="demo-fieldset">
|
|
681
|
+
<Field.Label className="demo-label">Floor</Field.Label>
|
|
682
|
+
<NumberField.Root
|
|
683
|
+
defaultValue={1}
|
|
684
|
+
min={0}
|
|
685
|
+
max={99}
|
|
686
|
+
locale="en-US"
|
|
687
|
+
className="demo-number-field"
|
|
688
|
+
>
|
|
689
|
+
<div className="demo-number-group">
|
|
690
|
+
<NumberField.Decrement className="demo-number-step">−</NumberField.Decrement>
|
|
691
|
+
<NumberField.Input className="demo-number-input" />
|
|
692
|
+
<NumberField.Increment className="demo-number-step">+</NumberField.Increment>
|
|
693
|
+
</div>
|
|
694
|
+
</NumberField.Root>
|
|
695
|
+
</Field.Root>
|
|
696
|
+
<Field.Root name="notes" className="demo-fieldset">
|
|
697
|
+
<Field.Label className="demo-label">Delivery notes</Field.Label>
|
|
698
|
+
<Field.Control
|
|
699
|
+
render={<textarea rows={1} maxLength={500} />}
|
|
700
|
+
className="demo-input demo-grow"
|
|
701
|
+
/>
|
|
702
|
+
<Field.Description className="demo-description">
|
|
703
|
+
Grows as you type (<code>field-sizing: content</code>).
|
|
704
|
+
</Field.Description>
|
|
705
|
+
</Field.Root>
|
|
706
|
+
<div className="demo-row">
|
|
707
|
+
<Form.Submit className="demo-button demo-primary demo-submit">Save address</Form.Submit>
|
|
708
|
+
</div>
|
|
709
|
+
</fieldset>
|
|
710
|
+
{saved !== null && <output className="demo-readout">Saved {saved}.</output>}
|
|
711
|
+
</Form.Root>
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
`field.css`: the same file as above.
|
|
717
|
+
|
|
718
|
+
```tsx
|
|
719
|
+
<fieldset disabled={!canEdit} aria-describedby="address-hint">
|
|
720
|
+
<legend>Shipping address</legend>
|
|
721
|
+
<p id="address-hint">Used for this order only.</p>
|
|
722
|
+
<Field.Root name="street"><Field.Label>Street</Field.Label><Field.Control required /><Field.Error /></Field.Root>
|
|
723
|
+
<Field.Root name="city"><Field.Label>City</Field.Label><Field.Control required /><Field.Error /></Field.Root>
|
|
724
|
+
</fieldset>
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
- An inherited `disabled` is the platform's: `data-disabled` and `state.disabled` stay the props'. Style it with the platform's selector, which covers both sources: `.field:has(.control:disabled) { opacity: .5; }`.
|
|
728
|
+
- Errors stay per Field. A rule over several controls is one Field's `validate` (it receives the whole `FormData`); a message that belongs to no control is your own element, referenced from the fieldset's `aria-describedby`.
|
|
729
|
+
- [RadioGroup](radio-group.md) and [CheckboxGroup](checkbox-group.md) are fieldsets themselves (their `Label` is the `<legend>`): do not wrap one in another fieldset to caption it.
|
|
730
|
+
- Do not disable a fieldset while a submission is pending: `<fieldset disabled={pending}>` drops focus from the control the user is on. Mark pending with `form[data-pending]`.
|
|
731
|
+
|
|
732
|
+
### <a id="textarea"></a>A textarea that grows
|
|
733
|
+
|
|
734
|
+
A textarea is `Field.Control render={<textarea />}`; textarea-only props (`rows`, `wrap`) go on the render element. It grows with its content through CSS, so there is no `autoSize` prop (the notes in the example above):
|
|
735
|
+
|
|
736
|
+
```tsx
|
|
737
|
+
<Field.Root name="notes">
|
|
738
|
+
<Field.Label>Delivery notes</Field.Label>
|
|
739
|
+
<Field.Control render={<textarea rows={1} maxLength={500} />} className="control grow" />
|
|
740
|
+
</Field.Root>
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
```css
|
|
744
|
+
.grow { field-sizing: content; min-block-size: 2lh; max-block-size: 8lh; resize: none; }
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
### <a id="field-control-alone"></a>Field.Control on its own
|
|
748
|
+
|
|
749
|
+
Outside a `Field.Root`, `Field.Control` renders the plain native control: `id`, `name`, `disabled` and `required` pass through, and nothing is added. For a direct call site write the native element (`<input type="search" aria-label="Search">`); the standalone form is for your own styled input built on `Field.Control`, which then works in a form field and in a search box or a table cell alike:
|
|
750
|
+
|
|
751
|
+
```tsx
|
|
752
|
+
function TextInput(props: FieldControlProps) {
|
|
753
|
+
return <Field.Control {...props} className={(s) => (s.invalid ? "input invalid" : "input")} />;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
<Field.Root name="email" required>
|
|
757
|
+
<Field.Label>Email</Field.Label>
|
|
758
|
+
<TextInput type="email" /> {/* wired to the Field */}
|
|
759
|
+
</Field.Root>
|
|
760
|
+
|
|
761
|
+
<label htmlFor="q">Search</label>
|
|
762
|
+
<TextInput id="q" type="search" /> {/* the plain <input>, state never invalid */}
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
Outside a Field the function props receive a `FieldState` whose `disabled` and `required` are the control's own props (as inside a Field), so `className={(s) => s.disabled ? …}` works in both places; `invalid`, `validity` and `pending` are constant (valid, not pending: there is no validation without a Field), and no `data-*` attribute is rendered. Select a plain control's validity with `:user-invalid`. A search box has no Field to wire; let the query leave the urgent lane with `useDeferredValue`, or use a [Combobox](combobox.md) when the result is a list of options. The text of an input is a fact, not a request, so there is no `valueChangeAction` on a text control.
|