@funstack/ui 0.1.0-alpha.17 → 0.1.0-alpha.19
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 +1 -1
- package/dist/accordion/accordion-panel.mjs +1 -1
- package/dist/accordion/accordion-root.d.mts.map +1 -1
- package/dist/accordion/accordion-root.mjs +35 -38
- package/dist/accordion/accordion-root.mjs.map +1 -1
- package/dist/accordion/accordion-trigger.mjs +1 -1
- package/dist/button/button.d.mts +18 -11
- package/dist/button/button.d.mts.map +1 -1
- package/dist/button/button.mjs +32 -16
- package/dist/button/button.mjs.map +1 -1
- package/dist/checkbox/checkbox.mjs +1 -1
- package/dist/checkbox/checkbox.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-item.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-item.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-parent.mjs +3 -3
- package/dist/checkbox-group/checkbox-group-parent.mjs.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.d.mts.map +1 -1
- package/dist/checkbox-group/checkbox-group-root.mjs +15 -12
- package/dist/checkbox-group/checkbox-group-root.mjs.map +1 -1
- package/dist/combobox/combobox-context.mjs.map +1 -1
- package/dist/combobox/combobox-input.mjs +2 -2
- package/dist/combobox/combobox-input.mjs.map +1 -1
- package/dist/combobox/combobox-keyboard.mjs +81 -0
- package/dist/combobox/combobox-keyboard.mjs.map +1 -0
- package/dist/combobox/combobox-popup.mjs +3 -3
- package/dist/combobox/combobox-popup.mjs.map +1 -1
- package/dist/combobox/combobox-root.d.mts.map +1 -1
- package/dist/combobox/combobox-root.mjs +44 -129
- package/dist/combobox/combobox-root.mjs.map +1 -1
- package/dist/combobox/combobox-trigger.d.mts.map +1 -1
- package/dist/combobox/combobox-trigger.mjs +2 -9
- package/dist/combobox/combobox-trigger.mjs.map +1 -1
- package/dist/combobox/use-active-option.mjs +49 -0
- package/dist/combobox/use-active-option.mjs.map +1 -0
- package/dist/combobox/use-combobox-form.mjs +3 -5
- package/dist/combobox/use-combobox-form.mjs.map +1 -1
- package/dist/combobox/use-combobox-text.mjs +43 -0
- package/dist/combobox/use-combobox-text.mjs.map +1 -0
- package/dist/combobox/use-option-registry.mjs +7 -17
- package/dist/combobox/use-option-registry.mjs.map +1 -1
- package/dist/dialog/dialog-close.mjs +2 -2
- package/dist/dialog/dialog-close.mjs.map +1 -1
- package/dist/dialog/dialog-context.mjs.map +1 -1
- package/dist/dialog/dialog-dismiss.mjs +108 -0
- package/dist/dialog/dialog-dismiss.mjs.map +1 -0
- package/dist/dialog/dialog-form.mjs +4 -4
- package/dist/dialog/dialog-form.mjs.map +1 -1
- package/dist/dialog/dialog-popup.d.mts.map +1 -1
- package/dist/dialog/dialog-popup.mjs +73 -161
- package/dist/dialog/dialog-popup.mjs.map +1 -1
- package/dist/dialog/dialog-root.d.mts.map +1 -1
- package/dist/dialog/dialog-root.mjs +4 -3
- package/dist/dialog/dialog-root.mjs.map +1 -1
- package/dist/dialog/dialog-trigger.mjs +11 -8
- package/dist/dialog/dialog-trigger.mjs.map +1 -1
- package/dist/docs/components/accordion.md +1 -1
- package/dist/docs/components/button.md +13 -10
- package/dist/docs/components/dialog.md +4 -4
- package/dist/docs/components/field.md +4 -3
- package/dist/docs/components/popover.md +4 -4
- package/dist/docs/components/toast.md +8 -5
- package/dist/docs/concepts/browser-owned-state.md +1 -1
- package/dist/docs/roadmap.md +9 -1
- package/dist/field/field-control.d.mts +1 -1
- package/dist/field/field-control.mjs +2 -2
- package/dist/field/field-control.mjs.map +1 -1
- package/dist/field/field-description.d.mts +1 -1
- package/dist/field/field-description.mjs +1 -1
- package/dist/field/field-description.mjs.map +1 -1
- package/dist/field/field-error.d.mts +1 -1
- package/dist/field/field-error.mjs +1 -1
- package/dist/field/field-error.mjs.map +1 -1
- package/dist/field/field-label.d.mts +1 -1
- package/dist/field/field-label.mjs +1 -1
- package/dist/field/field-label.mjs.map +1 -1
- package/dist/field/field-root.d.mts +2 -2
- package/dist/field/field-root.d.mts.map +1 -1
- package/dist/field/field-root.mjs +4 -4
- package/dist/field/field-root.mjs.map +1 -1
- package/dist/field/index.d.mts +2 -2
- package/dist/form/form-root.d.mts +1 -1
- package/dist/form/form-root.d.mts.map +1 -1
- package/dist/form/form-root.mjs +14 -4
- package/dist/form/form-root.mjs.map +1 -1
- package/dist/form/form-submit.d.mts +7 -3
- package/dist/form/form-submit.d.mts.map +1 -1
- package/dist/form/form-submit.mjs +11 -7
- package/dist/form/form-submit.mjs.map +1 -1
- package/dist/form/index.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/internal/{action-details.mjs → action/action-details.mjs} +1 -1
- package/dist/internal/action/action-details.mjs.map +1 -0
- package/dist/internal/{call-urgent-handler.mjs → action/call-urgent-handler.mjs} +5 -10
- package/dist/internal/action/call-urgent-handler.mjs.map +1 -0
- package/dist/internal/{report-dropped.mjs → action/report-dropped.mjs} +3 -21
- package/dist/internal/action/report-dropped.mjs.map +1 -0
- package/dist/internal/{use-action-trigger.mjs → action/use-action-trigger.mjs} +3 -2
- package/dist/internal/action/use-action-trigger.mjs.map +1 -0
- package/dist/internal/action/use-connected.mjs +24 -0
- package/dist/internal/action/use-connected.mjs.map +1 -0
- package/dist/internal/{use-controllable-action.mjs → action/use-controllable-action.mjs} +20 -32
- package/dist/internal/action/use-controllable-action.mjs.map +1 -0
- package/dist/internal/action/use-pure-trigger.mjs +34 -0
- package/dist/internal/action/use-pure-trigger.mjs.map +1 -0
- package/dist/internal/action/use-step-commit.mjs +147 -0
- package/dist/internal/action/use-step-commit.mjs.map +1 -0
- package/dist/internal/{field-context.d.mts → form/field-context.d.mts} +1 -1
- package/dist/internal/form/field-context.d.mts.map +1 -0
- package/dist/internal/{field-context.mjs → form/field-context.mjs} +2 -2
- package/dist/internal/form/field-context.mjs.map +1 -0
- package/dist/internal/{focus-first-invalid.mjs → form/focus-first-invalid.mjs} +3 -3
- package/dist/internal/form/focus-first-invalid.mjs.map +1 -0
- package/dist/internal/{form-status-watcher.mjs → form/form-status-watcher.mjs} +1 -1
- package/dist/internal/form/form-status-watcher.mjs.map +1 -0
- package/dist/internal/{group-member.mjs → form/group-member.mjs} +2 -2
- package/dist/internal/form/group-member.mjs.map +1 -0
- package/dist/internal/{sync-presence.mjs → form/sync-presence.mjs} +1 -1
- package/dist/internal/form/sync-presence.mjs.map +1 -0
- package/dist/internal/{use-checkable-input.mjs → form/use-checkable-input.mjs} +5 -5
- package/dist/internal/form/use-checkable-input.mjs.map +1 -0
- package/dist/internal/{use-field-control.mjs → form/use-field-control.mjs} +3 -3
- package/dist/internal/form/use-field-control.mjs.map +1 -0
- package/dist/internal/{use-fieldset-group.mjs → form/use-fieldset-group.mjs} +3 -3
- package/dist/internal/form/use-fieldset-group.mjs.map +1 -0
- package/dist/internal/{use-form-owner-event.mjs → form/use-form-owner-event.mjs} +1 -1
- package/dist/internal/form/use-form-owner-event.mjs.map +1 -0
- package/dist/internal/{use-form-reset.mjs → form/use-form-reset.mjs} +15 -3
- package/dist/internal/form/use-form-reset.mjs.map +1 -0
- package/dist/internal/{use-native-checked.mjs → form/use-native-checked.mjs} +5 -4
- package/dist/internal/form/use-native-checked.mjs.map +1 -0
- package/dist/internal/{use-native-group-reconciliation.mjs → form/use-native-group-reconciliation.mjs} +8 -8
- package/dist/internal/form/use-native-group-reconciliation.mjs.map +1 -0
- package/dist/internal/{use-native-select-value.mjs → form/use-native-select-value.mjs} +2 -2
- package/dist/internal/form/use-native-select-value.mjs.map +1 -0
- package/dist/internal/{validity.d.mts → form/validity.d.mts} +1 -1
- package/dist/internal/form/validity.d.mts.map +1 -0
- package/dist/internal/{validity.mjs → form/validity.mjs} +1 -1
- package/dist/internal/form/validity.mjs.map +1 -0
- package/dist/internal/{anchor-position.d.mts → overlay/anchor-position.d.mts} +1 -1
- package/dist/internal/overlay/anchor-position.d.mts.map +1 -0
- package/dist/internal/{anchor-position.mjs → overlay/anchor-position.mjs} +1 -1
- package/dist/internal/overlay/anchor-position.mjs.map +1 -0
- package/dist/internal/{content-focus-probe.mjs → overlay/content-focus-probe.mjs} +1 -1
- package/dist/internal/overlay/content-focus-probe.mjs.map +1 -0
- package/dist/internal/{css-transition-cut.mjs → overlay/css-transition-cut.mjs} +1 -1
- package/dist/internal/overlay/css-transition-cut.mjs.map +1 -0
- package/dist/internal/{focus-visible.mjs → overlay/focus-visible.mjs} +1 -1
- package/dist/internal/overlay/focus-visible.mjs.map +1 -0
- package/dist/internal/{invokers.mjs → overlay/invokers.mjs} +1 -1
- package/dist/internal/overlay/invokers.mjs.map +1 -0
- package/dist/internal/{modal-registry.mjs → overlay/modal-registry.mjs} +1 -1
- package/dist/internal/overlay/modal-registry.mjs.map +1 -0
- package/dist/internal/{overlay-popup.mjs → overlay/overlay-popup.mjs} +3 -3
- package/dist/internal/overlay/overlay-popup.mjs.map +1 -0
- package/dist/internal/overlay/overlay-show.mjs +73 -0
- package/dist/internal/overlay/overlay-show.mjs.map +1 -0
- package/dist/internal/{popover-open.mjs → overlay/popover-open.mjs} +1 -1
- package/dist/internal/overlay/popover-open.mjs.map +1 -0
- package/dist/internal/{trigger-ref.mjs → overlay/trigger-ref.mjs} +1 -1
- package/dist/internal/overlay/trigger-ref.mjs.map +1 -0
- package/dist/internal/overlay/use-apply-open-state.mjs +44 -0
- package/dist/internal/overlay/use-apply-open-state.mjs.map +1 -0
- package/dist/internal/{use-exit-animation.mjs → overlay/use-exit-animation.mjs} +2 -2
- package/dist/internal/overlay/use-exit-animation.mjs.map +1 -0
- package/dist/internal/{use-interest-dismiss.mjs → overlay/use-interest-dismiss.mjs} +1 -1
- package/dist/internal/overlay/use-interest-dismiss.mjs.map +1 -0
- package/dist/internal/{use-modal-registration.mjs → overlay/use-modal-registration.mjs} +1 -1
- package/dist/internal/overlay/use-modal-registration.mjs.map +1 -0
- package/dist/internal/{use-overlay-close.mjs → overlay/use-overlay-close.mjs} +14 -13
- package/dist/internal/overlay/use-overlay-close.mjs.map +1 -0
- package/dist/internal/overlay/use-overlay-root.d.mts +2 -0
- package/dist/internal/{use-overlay-root.mjs → overlay/use-overlay-root.mjs} +44 -28
- package/dist/internal/overlay/use-overlay-root.mjs.map +1 -0
- package/dist/internal/{use-popover-popup.mjs → overlay/use-popover-popup.mjs} +74 -63
- package/dist/internal/overlay/use-popover-popup.mjs.map +1 -0
- package/dist/internal/{use-popover-trigger.d.mts → overlay/use-popover-trigger.d.mts} +3 -3
- package/dist/internal/overlay/use-popover-trigger.d.mts.map +1 -0
- package/dist/internal/{use-popover-trigger.mjs → overlay/use-popover-trigger.mjs} +47 -26
- package/dist/internal/overlay/use-popover-trigger.mjs.map +1 -0
- package/dist/internal/{use-resolved-placement.mjs → overlay/use-resolved-placement.mjs} +2 -2
- package/dist/internal/overlay/use-resolved-placement.mjs.map +1 -0
- package/dist/internal/render-element.mjs +47 -9
- package/dist/internal/render-element.mjs.map +1 -1
- package/dist/internal/transition-boundary.mjs +4 -8
- package/dist/internal/transition-boundary.mjs.map +1 -1
- package/dist/internal/use-mount-fixed.mjs +22 -0
- package/dist/internal/use-mount-fixed.mjs.map +1 -0
- package/dist/internal/use-register-count.mjs +4 -1
- package/dist/internal/use-register-count.mjs.map +1 -1
- package/dist/internal/use-render.mjs +2 -2
- package/dist/internal/use-render.mjs.map +1 -1
- package/dist/internal/use-roving-focus.mjs.map +1 -1
- package/dist/menu/menu-checkbox-item.mjs +2 -2
- package/dist/menu/menu-checkbox-item.mjs.map +1 -1
- package/dist/menu/menu-context.d.mts +1 -1
- package/dist/menu/menu-context.mjs.map +1 -1
- package/dist/menu/menu-gestures.mjs +1 -1
- package/dist/menu/menu-gestures.mjs.map +1 -1
- package/dist/menu/menu-item.d.mts.map +1 -1
- package/dist/menu/menu-item.mjs +9 -10
- package/dist/menu/menu-item.mjs.map +1 -1
- package/dist/menu/menu-outside.mjs +1 -1
- package/dist/menu/menu-outside.mjs.map +1 -1
- package/dist/menu/menu-popup.d.mts +1 -1
- package/dist/menu/menu-popup.d.mts.map +1 -1
- package/dist/menu/menu-popup.mjs +10 -6
- package/dist/menu/menu-popup.mjs.map +1 -1
- package/dist/menu/menu-radio-group.mjs +2 -2
- package/dist/menu/menu-radio-group.mjs.map +1 -1
- package/dist/menu/menu-root.mjs +2 -2
- package/dist/menu/menu-root.mjs.map +1 -1
- package/dist/menu/menu-submenu-trigger.mjs +3 -3
- package/dist/menu/menu-submenu-trigger.mjs.map +1 -1
- package/dist/menu/menu-trigger.d.mts +1 -1
- package/dist/menu/menu-trigger.mjs +3 -3
- package/dist/menu/menu-trigger.mjs.map +1 -1
- package/dist/number-field/number-field-input.mjs +1 -1
- package/dist/number-field/number-field-input.mjs.map +1 -1
- package/dist/number-field/number-field-root.d.mts.map +1 -1
- package/dist/number-field/number-field-root.mjs +43 -107
- package/dist/number-field/number-field-root.mjs.map +1 -1
- package/dist/popover/popover-close.mjs +3 -3
- package/dist/popover/popover-close.mjs.map +1 -1
- package/dist/popover/popover-context.mjs.map +1 -1
- package/dist/popover/popover-popup.d.mts +1 -1
- package/dist/popover/popover-popup.mjs +3 -3
- package/dist/popover/popover-popup.mjs.map +1 -1
- package/dist/popover/popover-root.mjs +2 -2
- package/dist/popover/popover-root.mjs.map +1 -1
- package/dist/popover/popover-trigger.d.mts +1 -1
- package/dist/popover/popover-trigger.mjs +1 -1
- package/dist/popover/popover-trigger.mjs.map +1 -1
- package/dist/radio-group/radio-group-item.mjs +3 -3
- package/dist/radio-group/radio-group-item.mjs.map +1 -1
- package/dist/radio-group/radio-group-root.d.mts.map +1 -1
- package/dist/radio-group/radio-group-root.mjs +5 -5
- package/dist/radio-group/radio-group-root.mjs.map +1 -1
- package/dist/select/select-group-label.d.mts.map +1 -1
- package/dist/select/select-group-label.mjs +3 -1
- package/dist/select/select-group-label.mjs.map +1 -1
- package/dist/select/select-option.mjs +1 -1
- package/dist/select/select-option.mjs.map +1 -1
- package/dist/select/select-root.d.mts.map +1 -1
- package/dist/select/select-root.mjs +7 -7
- package/dist/select/select-root.mjs.map +1 -1
- package/dist/select/select-trigger.d.mts.map +1 -1
- package/dist/select/select-trigger.mjs +3 -1
- package/dist/select/select-trigger.mjs.map +1 -1
- package/dist/select/select-value.mjs +3 -6
- package/dist/select/select-value.mjs.map +1 -1
- package/dist/slider/slider-root.d.mts.map +1 -1
- package/dist/slider/slider-root.mjs +38 -104
- package/dist/slider/slider-root.mjs.map +1 -1
- package/dist/slider/use-thumb-registry.mjs.map +1 -1
- package/dist/switch/switch.mjs +1 -1
- package/dist/switch/switch.mjs.map +1 -1
- package/dist/tabs/tabs-panel.mjs +1 -1
- package/dist/tabs/tabs-panel.mjs.map +1 -1
- package/dist/tabs/tabs-root.d.mts.map +1 -1
- package/dist/tabs/tabs-root.mjs +4 -4
- package/dist/tabs/tabs-root.mjs.map +1 -1
- package/dist/{internal → tabs}/use-until-found.mjs +1 -1
- package/dist/tabs/use-until-found.mjs.map +1 -0
- package/dist/toast/toast-action.d.mts +13 -3
- package/dist/toast/toast-action.d.mts.map +1 -1
- package/dist/toast/toast-action.mjs +23 -13
- package/dist/toast/toast-action.mjs.map +1 -1
- package/dist/toast/toast-close.d.mts +13 -2
- package/dist/toast/toast-close.d.mts.map +1 -1
- package/dist/toast/toast-close.mjs +16 -6
- package/dist/toast/toast-close.mjs.map +1 -1
- package/dist/toast/toast-root.mjs +1 -1
- package/dist/toast/toast-root.mjs.map +1 -1
- package/dist/toast/toast-viewport.d.mts.map +1 -1
- package/dist/toast/toast-viewport.mjs +48 -143
- package/dist/toast/toast-viewport.mjs.map +1 -1
- package/dist/toast/use-modal-portal-host.mjs +1 -1
- package/dist/toast/use-modal-portal-host.mjs.map +1 -1
- package/dist/toast/use-toast-announcements.mjs +46 -0
- package/dist/toast/use-toast-announcements.mjs.map +1 -0
- package/dist/toast/use-toast-focus.mjs +75 -0
- package/dist/toast/use-toast-focus.mjs.map +1 -0
- package/dist/toast/use-toast-pauses.mjs +58 -0
- package/dist/toast/use-toast-pauses.mjs.map +1 -0
- package/dist/toggle/toggle.mjs +2 -2
- package/dist/toggle/toggle.mjs.map +1 -1
- package/dist/toggle-group/toggle-group-root.d.mts.map +1 -1
- package/dist/toggle-group/toggle-group-root.mjs +5 -5
- package/dist/toggle-group/toggle-group-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-context.d.mts +1 -1
- package/dist/tooltip/tooltip-context.mjs.map +1 -1
- package/dist/tooltip/tooltip-popup.mjs +1 -1
- package/dist/tooltip/tooltip-popup.mjs.map +1 -1
- package/dist/tooltip/tooltip-root.d.mts.map +1 -1
- package/dist/tooltip/tooltip-root.mjs +9 -4
- package/dist/tooltip/tooltip-root.mjs.map +1 -1
- package/dist/tooltip/tooltip-trigger.mjs +1 -1
- package/dist/tooltip/tooltip-trigger.mjs.map +1 -1
- package/dist/{internal → tooltip}/tooltip-warm.mjs +1 -1
- package/dist/tooltip/tooltip-warm.mjs.map +1 -0
- package/dist/tooltip/use-tooltip-interaction.mjs +2 -2
- package/dist/tooltip/use-tooltip-interaction.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/funstack-ui-knowledge/SKILL.md +1 -1
- package/dist/internal/action-details.mjs.map +0 -1
- package/dist/internal/anchor-position.d.mts.map +0 -1
- package/dist/internal/anchor-position.mjs.map +0 -1
- package/dist/internal/call-urgent-handler.mjs.map +0 -1
- package/dist/internal/content-focus-probe.mjs.map +0 -1
- package/dist/internal/css-transition-cut.mjs.map +0 -1
- package/dist/internal/field-context.d.mts.map +0 -1
- package/dist/internal/field-context.mjs.map +0 -1
- package/dist/internal/focus-first-invalid.mjs.map +0 -1
- package/dist/internal/focus-visible.mjs.map +0 -1
- package/dist/internal/form-status-watcher.mjs.map +0 -1
- package/dist/internal/group-member.mjs.map +0 -1
- package/dist/internal/invokers.mjs.map +0 -1
- package/dist/internal/modal-registry.mjs.map +0 -1
- package/dist/internal/overlay-popup.mjs.map +0 -1
- package/dist/internal/popover-open.mjs.map +0 -1
- package/dist/internal/report-dropped.mjs.map +0 -1
- package/dist/internal/sync-presence.mjs.map +0 -1
- package/dist/internal/tooltip-warm.mjs.map +0 -1
- package/dist/internal/trigger-ref.mjs.map +0 -1
- package/dist/internal/use-action-trigger.mjs.map +0 -1
- package/dist/internal/use-checkable-input.mjs.map +0 -1
- package/dist/internal/use-controllable-action.mjs.map +0 -1
- package/dist/internal/use-exit-animation.mjs.map +0 -1
- package/dist/internal/use-field-control.mjs.map +0 -1
- package/dist/internal/use-fieldset-group.mjs.map +0 -1
- package/dist/internal/use-form-owner-event.mjs.map +0 -1
- package/dist/internal/use-form-reset.mjs.map +0 -1
- package/dist/internal/use-interest-dismiss.mjs.map +0 -1
- package/dist/internal/use-modal-registration.mjs.map +0 -1
- package/dist/internal/use-native-checked.mjs.map +0 -1
- package/dist/internal/use-native-group-reconciliation.mjs.map +0 -1
- package/dist/internal/use-native-select-value.mjs.map +0 -1
- package/dist/internal/use-overlay-close.mjs.map +0 -1
- package/dist/internal/use-overlay-root.d.mts +0 -2
- package/dist/internal/use-overlay-root.mjs.map +0 -1
- package/dist/internal/use-popover-popup.mjs.map +0 -1
- package/dist/internal/use-popover-trigger.d.mts.map +0 -1
- package/dist/internal/use-popover-trigger.mjs.map +0 -1
- package/dist/internal/use-resolved-placement.mjs.map +0 -1
- package/dist/internal/use-until-found.mjs.map +0 -1
- package/dist/internal/validity.d.mts.map +0 -1
- package/dist/internal/validity.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-trigger.mjs","names":[],"sources":["../../src/dialog/dialog-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogTriggerState {\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly open: boolean;\n /**\n * The Root's transition is pending: an open in flight, or a close a part asked for in flight\n * (`openChangeAction(false)` awaited while the dialog is still open). A dismissal is a fact and\n * is never pending.\n */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Dialog.Trigger`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Never dispatches. Native `disabled` on a `<button>` (no longer an invoker); with a link or\n * component `render` where the Trigger handles the click (library mode, or a non-modal\n * dialog), `aria-disabled=\"true\"` instead: the element stays focusable.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, DialogTriggerState>;\n /** Should render a `<button>`; another element works only in library mode (click handler). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, DialogTriggerState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The opener: `<button type=\"button\" commandfor command=\"show-modal\">`. In JS-free mode the\n * browser runs the command. In library mode the click is cancelled (so the command does not run)\n * and dispatched through the Root's transition; the button shows optimistic `data-open` and\n * `data-pending` until the dialog has opened. Non-modal dialogs have no command and always use a\n * click handler (`show()`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled` (a\n * link or component `render` with the click handler installed), `commandfor`, `command`,\n * `onClick`, `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogTriggerProps) {\n const ctx = useDialogContext(\"Dialog.Trigger\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, triggerRef, popupRef } = ctx;\n\n const state: DialogTriggerState = {\n open: ctx.optimistic,\n // Every Root dispatch is an open or a part-initiated close, and both belong to the Trigger\n // (design 4.2). Not `optimistic !== committed`: a request superseded by a fact still runs\n // and is pending with both `false`.\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n !isLibrary && modal && element.tagName !== \"BUTTON\"\n ? `Dialog.Trigger: rendered a <${element.tagName.toLowerCase()}> in JS-free mode. Only a ` +\n '<button> runs `command=\"show-modal\"`; this trigger will not open the dialog. Render ' +\n \"a <button>, or put the Dialog in library mode (`defaultOpen={false}`).\"\n : null),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n return registerTrigger(triggerRef, element, \"Dialog.Trigger\");\n },\n [checkElement, triggerRef],\n );\n\n // A Trigger without a Popup opens nothing (design 14, dev warnings).\n useEffect(() => {\n if (!isDev) return;\n if (document.getElementById(ids.popup) === null) {\n console.error(\n \"Dialog.Trigger: no Dialog.Popup is rendered for this Dialog.Root; the trigger opens nothing.\",\n );\n }\n }, [ids.popup]);\n\n // Library mode (both modal and non-modal) and non-modal JS-free mode need a click handler;\n // modal JS-free mode is the browser's command.\n const installClick = isLibrary || !modal;\n // The modal JS-free command needs native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });\n // Only on a button (or a component, assumed to render one): another element is no invoker.\n const invoker = modal && disabledProps.invoker && rendersButton(render);\n // Non-modal JS-free mode: whether the dialog was open when the press began. A press on the\n // Trigger of an open `lightDismiss` dialog is a dismissal (the JS listeners or native\n // `closedby=\"any\"` close it before the click), so that click must not `show()` it again.\n // Pointer clicks only (`detail > 0`): a keyboard click has no press, and a press that never\n // became a click must not swallow a later one.\n const pressedOpen = useRef(false);\n const installPress = !isLibrary && !modal;\n const onPointerDown = () => {\n pressedOpen.current = popupRef.current?.open ?? false;\n };\n const onClick = (event: MouseEvent<HTMLElement>) => {\n if (isLibrary) {\n // Cancelling the click cancels the command (it runs as the button's activation\n // behaviour, only if the click was not cancelled).\n event.preventDefault();\n if (disabled) return;\n ctx.requestOpen(event.nativeEvent, \"activate\");\n return;\n }\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n const wasOpen = event.detail > 0 && pressedOpen.current;\n pressedOpen.current = false;\n const dialog = popupRef.current;\n if (dialog !== null && !dialog.open && !wasOpen && dialog.isConnected) dialog.show();\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the\n // browser would run its command).\n ...disabledProps.props,\n commandfor: invoker ? ids.popup : undefined,\n command: invoker ? \"show-modal\" : undefined,\n // Only owned when installed, so a render element keeps its own `onClick` in modal JS-free\n // mode (Accordion's rule).\n ...(installClick && { onClick }),\n ...(installPress && { onPointerDown }),\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, DialogTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n}\n\nDialogTrigger.displayName = \"DialogTrigger\";\n"],"mappings":";;;;;;;;;AAuDA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAgBvC,SAAgB,cAAc,EAC5B,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,iBAAiB,gBAAgB;CAC7C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,YAAY,aAAa;CAE7C,MAAM,QAA4B;EAChC,MAAM,IAAI;EAIV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YACA,CAAC,aAAa,SAAS,QAAQ,YAAY,WACvC,+BAA+B,QAAQ,QAAQ,YAAY,EAAE,4LAG7D,KACV;CACA,MAAM,aAAa,aAChB,YAAyB;EACxB,eAAe,OAAO;EACtB,OAAO,gBAAgB,YAAY,SAAS,gBAAgB;CAC9D,GACA,CAAC,cAAc,UAAU,CAC3B;CAGA,gBAAgB;EACd,IAAI,CAAC,OAAO;EACZ,IAAI,SAAS,eAAe,IAAI,KAAK,MAAM,MACzC,QAAQ,MACN,8FACF;CAEJ,GAAG,CAAC,IAAI,KAAK,CAAC;CAId,MAAM,eAAe,aAAa,CAAC;CAEnC,MAAM,gBAAgB,eAAe,QAAQ,UAAU,EAAE,cAAc,aAAa,CAAC;CAErF,MAAM,UAAU,SAAS,cAAc,WAAW,cAAc,MAAM;CAMtE,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,eAAe,CAAC,aAAa,CAAC;CACpC,MAAM,sBAAsB;EAC1B,YAAY,UAAU,SAAS,SAAS,QAAQ;CAClD;CACA,MAAM,WAAW,UAAmC;EAClD,IAAI,WAAW;GAGb,MAAM,eAAe;GACrB,IAAI,UAAU;GACd,IAAI,YAAY,MAAM,aAAa,UAAU;GAC7C;EACF;EACA,IAAI,UAAU;GAEZ,MAAM,eAAe;GACrB;EACF;EACA,MAAM,UAAU,MAAM,SAAS,KAAK,YAAY;EAChD,YAAY,UAAU;EACtB,MAAM,SAAS,SAAS;EACxB,IAAI,WAAW,QAAQ,CAAC,OAAO,QAAQ,CAAC,WAAW,OAAO,aAAa,OAAO,KAAK;CACrF;CAEA,MAAM,eAAiE;EAErE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAGvD,GAAG,cAAc;EACjB,YAAY,UAAU,IAAI,QAAQ,KAAA;EAClC,SAAS,UAAU,eAAe,KAAA;EAGlC,GAAI,gBAAgB,EAAE,QAAQ;EAC9B,GAAI,gBAAgB,EAAE,cAAc;EACpC,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EAGtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"dialog-trigger.mjs","names":[],"sources":["../../src/dialog/dialog-trigger.tsx"],"sourcesContent":["\"use client\";\nimport { useCallback, useRef } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, MouseEvent, ReactNode } from \"react\";\nimport { dataAttr } from \"../internal/data-attr.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { registerTrigger } from \"../internal/overlay/trigger-ref.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { cancelClick, disabledButton, rendersButton, useRender } from \"../internal/use-render.js\";\nimport type { DataAttributes } from \"../internal/use-render.js\";\nimport { useDialogContext } from \"./dialog-context.js\";\n\n/**\n * State of `Dialog.Trigger`, passed to the function forms of `className`, `style`, `children` and\n * `render`.\n */\nexport interface DialogTriggerState {\n /** Optimistic open state (library mode); `false` in JS-free mode. */\n readonly open: boolean;\n /**\n * The Root's transition is pending: an open in flight, or a close a part asked for in flight\n * (`openChangeAction(false)` awaited while the dialog is still open). A dismissal is a fact and\n * is never pending.\n */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/**\n * Props of `Dialog.Trigger`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport interface DialogTriggerProps extends Omit<\n ComponentPropsWithRef<\"button\">,\n \"onClick\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Never dispatches. Native `disabled` on a `<button>` (no longer an invoker); with a link or\n * component `render` where the Trigger handles the click (library mode, or a non-modal\n * dialog), `aria-disabled=\"true\"` instead: the element stays focusable.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, DialogTriggerState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, DialogTriggerState>;\n /** Rendered from optimistic state; must not suspend. */\n children?: StateValue<ReactNode, DialogTriggerState>;\n /** Should render a `<button>`; another element works only in library mode (click handler). */\n render?: RenderProp<ComponentPropsWithRef<\"button\">, DialogTriggerState>;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The opener: `<button type=\"button\" commandfor command=\"show-modal\">`. In JS-free mode the\n * browser runs the command. In library mode the click is cancelled (so the command does not run)\n * and dispatched through the Root's transition; the button shows optimistic `data-open` and\n * `data-pending` until the dialog has opened. Non-modal dialogs have no command and always use a\n * click handler (`show()`).\n *\n * Owned keys (conventions 1.2): `type` (on a `<button>` only), `disabled`, `aria-disabled` (a\n * link or component `render` with the click handler installed), `commandfor`, `command`,\n * `onClick`, `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`,\n * `data-disabled`.\n *\n * @see https://ui.funstack.work/components/dialog\n */\nexport function DialogTrigger({\n disabled = false,\n className,\n style,\n children,\n render,\n ...rest\n}: DialogTriggerProps) {\n const ctx = useDialogContext(\"Dialog.Trigger\");\n const isLibrary = ctx.mode === \"library\";\n const { modal, ids, triggerRef, popupRef } = ctx;\n\n const state: DialogTriggerState = {\n open: ctx.optimistic,\n // Every Root dispatch is an open or a part-initiated close, and both belong to the Trigger\n // (design 4.2). Not `optimistic !== committed`: a request superseded by a fact still runs\n // and is pending with both `false`.\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n !isLibrary && modal && element.tagName !== \"BUTTON\"\n ? `Dialog.Trigger: rendered a <${element.tagName.toLowerCase()}> in JS-free mode. Only a ` +\n '<button> runs `command=\"show-modal\"`; this trigger will not open the dialog. Render ' +\n \"a <button>, or put the Dialog in library mode (`defaultOpen={false}`).\"\n : null),\n );\n // A Trigger without a Popup opens nothing (design 14, dev warnings). Checked when the Trigger's\n // element attaches: the commit's DOM is complete by then, Popup included.\n const checkPopup = useElementCheck(\n isDev &&\n (() =>\n document.getElementById(ids.popup) === null\n ? \"Dialog.Trigger: no Dialog.Popup is rendered for this Dialog.Root; the trigger opens nothing.\"\n : null),\n );\n const libraryRef = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n checkPopup?.(element);\n return registerTrigger(triggerRef, element, \"Dialog.Trigger\");\n },\n [checkElement, checkPopup, triggerRef],\n );\n\n // Library mode (both modal and non-modal) and non-modal JS-free mode need a click handler;\n // modal JS-free mode is the browser's command.\n const installClick = isLibrary || !modal;\n // The modal JS-free command needs native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, { handlesClick: installClick });\n // Only on a button (or a component, assumed to render one): another element is no invoker.\n const invoker = modal && disabledProps.invoker && rendersButton(render);\n // Non-modal JS-free mode: whether the dialog was open when the press began. A press on the\n // Trigger of an open `lightDismiss` dialog is a dismissal (the JS listeners or native\n // `closedby=\"any\"` close it before the click), so that click must not `show()` it again.\n // Pointer clicks only (`detail > 0`): a keyboard click has no press, and a press that never\n // became a click must not swallow a later one.\n const pressedOpen = useRef(false);\n const installPress = !isLibrary && !modal;\n const onPointerDown = () => {\n pressedOpen.current = popupRef.current?.open ?? false;\n };\n const onClick = (event: MouseEvent<HTMLElement>) => {\n if (isLibrary) {\n // Cancelling the click cancels the command (it runs as the button's activation\n // behaviour, only if the click was not cancelled).\n event.preventDefault();\n if (disabled) return;\n ctx.requestOpen(event.nativeEvent, \"activate\");\n return;\n }\n if (disabled) {\n // A disabled link must not navigate either.\n event.preventDefault();\n return;\n }\n const wasOpen = event.detail > 0 && pressedOpen.current;\n pressedOpen.current = false;\n const dialog = popupRef.current;\n if (dialog !== null && !dialog.open && !wasOpen && dialog.isConnected) dialog.show();\n };\n\n const libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes = {\n // `type` only applies to a <button>; on any other element the key is not owned.\n ...(rendersButton(render) && { type: \"button\" as const }),\n // Owned: a render element must not re-enable a disabled Trigger (in JS-free mode the\n // browser would run its command).\n ...disabledProps.props,\n commandfor: invoker ? ids.popup : undefined,\n command: invoker ? \"show-modal\" : undefined,\n // Only owned when installed, so a render element keeps its own `onClick` in modal JS-free\n // mode (Accordion's rule).\n ...(installClick && { onClick }),\n // Modal JS-free mode, disabled in the `aria-disabled` branch (a host link): nothing native\n // stops the click, so it is cancelled (a disabled link must not navigate).\n ...(!installClick && !disabledProps.invoker && { onClick: cancelClick }),\n ...(installPress && { onPointerDown }),\n \"data-open\": dataAttr(state.open),\n \"data-pending\": dataAttr(state.pending),\n // Every mode: the styling hook agrees with the rendered `disabled` / `aria-disabled`\n // (conventions 1.2).\n \"data-disabled\": dataAttr(disabled),\n };\n\n return useRender<ComponentPropsWithRef<\"button\">, DialogTriggerState>({\n defaultElement: \"button\",\n render,\n state,\n className,\n style,\n children,\n props: rest,\n libraryProps,\n ref: libraryRef,\n });\n}\n\nDialogTrigger.displayName = \"DialogTrigger\";\n"],"mappings":";;;;;;;;;AAuDA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;AAgBvC,SAAgB,cAAc,EAC5B,WAAW,OACX,WACA,OACA,UACA,QACA,GAAG,QACkB;CACrB,MAAM,MAAM,iBAAiB,gBAAgB;CAC7C,MAAM,YAAY,IAAI,SAAS;CAC/B,MAAM,EAAE,OAAO,KAAK,YAAY,aAAa;CAE7C,MAAM,QAA4B;EAChC,MAAM,IAAI;EAIV,SAAS,IAAI;EACb;CACF;CAEA,MAAM,eAAe,gBACnB,WACI,YACA,CAAC,aAAa,SAAS,QAAQ,YAAY,WACvC,+BAA+B,QAAQ,QAAQ,YAAY,EAAE,4LAG7D,KACV;CAGA,MAAM,aAAa,gBACjB,gBAEI,SAAS,eAAe,IAAI,KAAK,MAAM,OACnC,iGACA,KACV;CACA,MAAM,aAAa,aAChB,YAAyB;EACxB,eAAe,OAAO;EACtB,aAAa,OAAO;EACpB,OAAO,gBAAgB,YAAY,SAAS,gBAAgB;CAC9D,GACA;EAAC;EAAc;EAAY;CAAU,CACvC;CAIA,MAAM,eAAe,aAAa,CAAC;CAEnC,MAAM,gBAAgB,eAAe,QAAQ,UAAU,EAAE,cAAc,aAAa,CAAC;CAErF,MAAM,UAAU,SAAS,cAAc,WAAW,cAAc,MAAM;CAMtE,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,eAAe,CAAC,aAAa,CAAC;CACpC,MAAM,sBAAsB;EAC1B,YAAY,UAAU,SAAS,SAAS,QAAQ;CAClD;CACA,MAAM,WAAW,UAAmC;EAClD,IAAI,WAAW;GAGb,MAAM,eAAe;GACrB,IAAI,UAAU;GACd,IAAI,YAAY,MAAM,aAAa,UAAU;GAC7C;EACF;EACA,IAAI,UAAU;GAEZ,MAAM,eAAe;GACrB;EACF;EACA,MAAM,UAAU,MAAM,SAAS,KAAK,YAAY;EAChD,YAAY,UAAU;EACtB,MAAM,SAAS,SAAS;EACxB,IAAI,WAAW,QAAQ,CAAC,OAAO,QAAQ,CAAC,WAAW,OAAO,aAAa,OAAO,KAAK;CACrF;CAEA,MAAM,eAAiE;EAErE,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;EAGvD,GAAG,cAAc;EACjB,YAAY,UAAU,IAAI,QAAQ,KAAA;EAClC,SAAS,UAAU,eAAe,KAAA;EAGlC,GAAI,gBAAgB,EAAE,QAAQ;EAG9B,GAAI,CAAC,gBAAgB,CAAC,cAAc,WAAW,EAAE,SAAS,YAAY;EACtE,GAAI,gBAAgB,EAAE,cAAc;EACpC,aAAa,SAAS,MAAM,IAAI;EAChC,gBAAgB,SAAS,MAAM,OAAO;EAGtC,iBAAiB,SAAS,QAAQ;CACpC;CAEA,OAAO,UAA+D;EACpE,gBAAgB;EAChB;EACA;EACA;EACA;EACA;EACA,OAAO;EACP;EACA,KAAK;CACP,CAAC;AACH;AAEA,cAAc,cAAc"}
|
|
@@ -186,7 +186,7 @@ See [Browser-owned state](../concepts/browser-owned-state.md) for the reasoning.
|
|
|
186
186
|
|
|
187
187
|
| Prop | Type | Default | Description |
|
|
188
188
|
| - | - | - | - |
|
|
189
|
-
| `exclusive` | `boolean` | `false` | At most one item open. Also decides the value type: string \| null when exclusive, string\[] otherwise. |
|
|
189
|
+
| `exclusive` | `boolean` | `false` | At most one item open. Also decides the value type: string \| null when exclusive, string\[] otherwise. Fixed at mount: a later change is ignored (development warning). |
|
|
190
190
|
| `value` | `string[] \| string \| null (exclusive)` | – | Controlled open items. undefined means uncontrolled; \[] or null means none open. Selects library mode. |
|
|
191
191
|
| `defaultValue` | `string[] \| string \| null (exclusive)` | – | Initial open items in uncontrolled library mode. Selects library mode. |
|
|
192
192
|
| `valueChangeAction` | `ChangeAction<string[] \| string \| null, AccordionValueChangeDetails>` | – | Called with the next open items on every change, inside the Root's transition. Sync, async or a Server Function. `details`: `reason` (a `ChangeReason`; Accordion dispatches `"activate"` or `"platform"`), `item` (the item that changed) and `open` (its new state). In multiple mode the array lists items in the order they mounted. Selects library mode. |
|
|
@@ -199,11 +199,11 @@ One element, no parts. It renders `<button type="button">`; `render` substitutes
|
|
|
199
199
|
| Prop | Type | Default | Description |
|
|
200
200
|
| - | - | - | - |
|
|
201
201
|
| `action` | `Action<[details: ButtonActionDetails]>` | – | Runs inside the Button's own transition on click, Enter or Space. Sync or async; may be a Server Function (`details` carries only the virtual `event`). A rejection reaches the nearest Error Boundary above the Button. A click while it is pending runs it again, unless `whilePending` is `"ignore"`. Not combinable with `formAction` (development error). |
|
|
202
|
-
| `formAction` | `string \| ((formData: FormData) => void \| Promise<void>)` | – | React's `formAction`: run by React instead of the form's `action` when this Button submits the form. With a function the Button is pending
|
|
202
|
+
| `formAction` | `string \| ((formData: FormData) => void \| Promise<void>)` | – | React's `formAction`: run by React instead of the form's `action` when this Button submits the form. With a function the Button is pending from its own submission until the form's submissions have all finished (never for another submitter's alone) and defaults to `type="submit"`; a click meanwhile submits again unless `whilePending` is `"ignore"` (see [Forms](#forms)). Prefer a stable function (a Server Function, a `useActionState` dispatch, `useCallback`) when the form is also submitted from script with `requestSubmit(button)`; an inline function works for clicks and Enter. The match is by function identity (React reports no submitter), so Buttons that share one function (one dispatch, different `name` / `value`) all show pending while either submits; give each its own function (`dispatch.bind(null, "draft")`) to tell them apart. |
|
|
203
203
|
| `whilePending` | `"run" \| "ignore"` | `"run"` | What a click, Enter or Space does while this Button's own `action` (or its own function `formAction` submission) is pending. `"run"`: it runs as well; the Button shows `data-pending` until every run has settled. `"ignore"`: it starts nothing, its default action is cancelled (no second submission, navigation or command), and the Button is `aria-disabled="true"` while pending. Use `"ignore"` for an action that must not run twice (Save, Pay, Delete). No effect on a Button with neither `action` nor a function `formAction`. Type `WhilePending`. |
|
|
204
204
|
| `type` | `"button" \| "submit" \| "reset"` | `"button", or "submit" with formAction` | Owned on a `<button>` and on a component `render` element (assumed to render a `<button>`; it should spread the prop): set it here, not on the element. Omitted for a host element of another tag (`<a>`). `action` together with `submit` / `reset` warns in development (one click would do two things). |
|
|
205
|
-
| `disabled` | `boolean` | `false` | Native `disabled` and `data-disabled`; never dispatches, and a disabled link does not navigate. With `focusableWhenDisabled
|
|
206
|
-
| `focusableWhenDisabled` | `boolean` | `false (true inside a Toolbar.Root)` | Keep a disabled Button focusable: `aria-disabled="true"` instead of native `disabled`, so keyboard and screen-reader users still find it and a Tooltip on it still opens. |
|
|
205
|
+
| `disabled` | `boolean` | `false` | Native `disabled` and `data-disabled`; never dispatches, and a disabled link does not navigate. With `focusableWhenDisabled` or inside a [Toolbar](toolbar.md), renders `aria-disabled="true"` instead and cancels the click. So does a `render` element of another tag (a link, where native `disabled` means nothing), and a component `render` whose click only the Button acts on. A component or `<input>` `render` whose click the browser also acts on (`type="submit"` or `"reset"`, the `formAction` default, `commandfor` / `popoverTarget`; with or without `action`) keeps native `disabled`, the only thing that stops a submission or a command before hydration. Native `disabled` wins over the pending `aria-disabled`. |
|
|
206
|
+
| `focusableWhenDisabled` | `boolean` | `false (true inside a Toolbar.Root)` | Keep a disabled Button focusable: `aria-disabled="true"` instead of native `disabled`, so keyboard and screen-reader users still find it and a Tooltip on it still opens. Before hydration a focusable disabled submitter still submits: nothing native stops it. |
|
|
207
207
|
| `transition` | `ViewTransitionClass` | – | Forwarded to the Button's `<ViewTransition default>`: animates the commit that ends the action (content keyed on `pending`), not the click. |
|
|
208
208
|
| `className` | `string \| ((state: ButtonState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
209
209
|
| `style` | `CSSProperties \| ((state: ButtonState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
@@ -219,9 +219,9 @@ Every other `<button>` prop passes through, including `name`, `value`, `form`, `
|
|
|
219
219
|
|
|
220
220
|
| Hook | Meaning |
|
|
221
221
|
| - | - |
|
|
222
|
-
| `data-pending` | The Button's own `action` is in flight (until the commit that ends it, including a Suspense wait), or
|
|
222
|
+
| `data-pending` | The Button's own `action` is in flight (until the commit that ends it, including a Suspense wait), or it submitted the form with its own function `formAction` and the form's submissions have not all finished. |
|
|
223
223
|
| `data-disabled` | The `disabled` prop. Not set by pending. |
|
|
224
|
-
| `aria-disabled` | `"true"` while pending with `whilePending="ignore"
|
|
224
|
+
| `aria-disabled` | `"true"` while pending with `whilePending="ignore"` (unless natively disabled), and while `disabled` with `focusableWhenDisabled`, inside a Toolbar, on a `render` element of another tag (a link), or on a component `render` whose click only the Button acts on. Never set by pending in the default `"run"` mode. |
|
|
225
225
|
|
|
226
226
|
Pending is not disabled: `[data-disabled]` and `state.disabled` are your `disabled` only, so the two states never have to look alike.
|
|
227
227
|
|
|
@@ -245,7 +245,7 @@ None: the Button adds no transition types. Its `transition` prop animates the co
|
|
|
245
245
|
|
|
246
246
|
Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)
|
|
247
247
|
|
|
248
|
-
A [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): no optimistic state. `data-pending` while its own action
|
|
248
|
+
A [pure trigger](../concepts/pending-and-optimistic.md#pure-trigger): no optimistic state. `data-pending` while its own action is in flight, or from a submission started by its own function `formAction` until the form's submissions have all finished. A second click, Enter or Space meanwhile runs again by default; with `whilePending="ignore"` it is ignored and the Button is `aria-disabled="true"`.
|
|
249
249
|
|
|
250
250
|
### A click while pending
|
|
251
251
|
|
|
@@ -348,8 +348,9 @@ import { fakeSave } from "./fake-api.js";
|
|
|
348
348
|
|
|
349
349
|
// One form, three submitters. Form.Submit runs the form's own action and is pending for every
|
|
350
350
|
// submission of the form (the form channel). Each Button formAction runs its own function instead
|
|
351
|
-
// and is pending
|
|
352
|
-
//
|
|
351
|
+
// and is pending from its own submission until the form's submissions have all finished (never
|
|
352
|
+
// for another submitter's alone); with whilePending="ignore" a second click on a pending one is
|
|
353
|
+
// ignored (by default it would submit again).
|
|
353
354
|
export function ButtonFormActions() {
|
|
354
355
|
const [log, setLog] = useState<string[]>([]);
|
|
355
356
|
const record = (line: string) => startTransition(() => setLog((l) => [line, ...l].slice(0, 4)));
|
|
@@ -400,16 +401,18 @@ export function ButtonFormActions() {
|
|
|
400
401
|
}
|
|
401
402
|
```
|
|
402
403
|
|
|
403
|
-
A Button is `type="button"` by default, so an `action` Button never submits the form it sits in. With `formAction` it is a submit button that runs its own function instead of the form's `action`: constraint validation, `FormData` and React's automatic form reset all apply. It is pending
|
|
404
|
+
A Button is `type="button"` by default, so an `action` Button never submits the form it sits in. With `formAction` it is a submit button that runs its own function instead of the form's `action`: constraint validation, `FormData` and React's automatic form reset all apply. It is pending from its own submission until the form's submissions have all finished, and never for another submitter's alone (React reports the latest submitter's function through `useFormStatus().action`).
|
|
404
405
|
|
|
405
406
|
> **Overlapping submissions**
|
|
406
407
|
>
|
|
407
408
|
> By default a second click on a pending `Button formAction` submits the form again, as React's own `<button formAction>` does. Those submissions are React's form channel, and React drops the rejection of an older overlapping submission: it reaches no Error Boundary and no `reportError`, and the library cannot see it. For a submission that must not overlap, use `whilePending="ignore"` (as in the example above), or pass a `useActionState` dispatch, which React runs in order.
|
|
409
|
+
>
|
|
410
|
+
> When another submitter (a second `Button formAction`, `Form.Submit`, Enter in a field) submits while a Button's own submission runs, the Button stays pending until every overlapping submission has settled, also when its own finished first (a second `Button formAction` likewise): React holds the form's status, and the results of the actions, until every overlapping submission has finished, as it does for two overlapping `Button action`s. A `whilePending="ignore"` Button therefore keeps ignoring clicks through the overlap. One case cannot be seen: two submissions started by script in the same task (`requestSubmit(a)` then `requestSubmit(b)`) never let React render the status of the first, so its Button is not pending.
|
|
408
411
|
|
|
409
412
|
| | Form.Submit | Button formAction | Button type="submit" |
|
|
410
413
|
| - | - | - | - |
|
|
411
414
|
| Submits | the form's own `action` | its own function instead | the form's own `action` |
|
|
412
|
-
| `pending` | the form channel: any submitter | its own submissions
|
|
415
|
+
| `pending` | the form channel: any submitter | from its own submission until the form's submissions have all finished | none |
|
|
413
416
|
| A click while pending | not blocked (a `useActionState` dispatch queues it, in order) | submits again; ignored with `whilePending="ignore"` | none |
|
|
414
417
|
| Use | the one primary submit button | secondary submitters | rarely; `Form.Submit` is the documented spelling |
|
|
415
418
|
|
|
@@ -257,14 +257,14 @@ One per Root: focus returns to the Trigger that mounted last, and a non-modal di
|
|
|
257
257
|
|
|
258
258
|
| Prop | Type | Default | Description |
|
|
259
259
|
| - | - | - | - |
|
|
260
|
-
| `disabled` | `boolean` | `false` | Native `disabled`: a disabled button is not an invoker and never opens. With a link or component `render` where the Trigger handles the click (library mode, or a non-modal dialog), `aria-disabled="true"` instead (the element stays focusable). |
|
|
260
|
+
| `disabled` | `boolean` | `false` | Native `disabled`: a disabled button is not an invoker and never opens. With a link or component `render` where the Trigger handles the click (library mode, or a non-modal dialog), `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. |
|
|
261
261
|
| `className` | `string \| ((state: DialogTriggerState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
262
262
|
| `style` | `CSSProperties \| ((state: DialogTriggerState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
263
263
|
| `children` | `ReactNode \| ((state: DialogTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
|
|
264
264
|
| `render` | `ReactElement \| ((props, state: DialogTriggerState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
265
265
|
|
|
266
266
|
- **State**: `DialogTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open in flight, or a part's close waiting for `openChangeAction(false)`. A dismissal never pends, but a request still running when a dismissal superseded it keeps `pending` until that request settles.
|
|
267
|
-
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled` (a link or component `render` with the click handler installed), `commandfor`, `command` (not on a link or other non-button host element), `onClick` (when it installs one), `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`, `data-disabled`.
|
|
267
|
+
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled` (a host link, or a component `render` with the click handler installed), `commandfor`, `command` (not on a link or other non-button host element), `onClick` (when it installs one), `onPointerDown` (non-modal JS-free mode), `data-open`, `data-pending`, `data-disabled`.
|
|
268
268
|
|
|
269
269
|
### `Dialog.Popup`
|
|
270
270
|
|
|
@@ -292,7 +292,7 @@ Other props, such as `role="alertdialog"` or `onCancel`, pass through.
|
|
|
292
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`. |
|
|
293
293
|
| `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
294
|
| `value` | `string` | – | Becomes `dialog.returnValue`, and `details.returnValue` of `openChangeAction(false)`. |
|
|
295
|
-
| `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). |
|
|
295
|
+
| `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. |
|
|
296
296
|
| `className` | `string \| ((state: DialogCloseState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
297
297
|
| `style` | `CSSProperties \| ((state: DialogCloseState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
298
298
|
| `children` | `ReactNode \| ((state: DialogCloseState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
@@ -536,7 +536,7 @@ To open now and show a skeleton instead, put a `<Suspense>` boundary inside the
|
|
|
536
536
|
|
|
537
537
|
> **A part's close is yours to refuse; a dismissal's is not**
|
|
538
538
|
>
|
|
539
|
-
> A close a part asks for waits for `openChangeAction(false)`: a controlled parent that keeps `open` gets a plain snap-back, and the dialog never blinks (for example "the save failed, keep editing", checked through `details.returnValue`). A dismissal is already done when `onOpenChange` runs: a parent that does not adopt `false` gets the dialog re-opened at once, and the user sees it close and come back. Adopt a dismissal's `false` directly in `onOpenChange` (not in `startTransition`, not after an `await`). If the user dismisses the dialog while a part's close is still running, `onOpenChange` hears it at once and that close is superseded: a later veto of it changes nothing. Neither is a way to ask the user first: an action must never await input, so build confirmation inside the dialog (see the callout above).
|
|
539
|
+
> A close a part asks for waits for `openChangeAction(false)`: a controlled parent that keeps `open` gets a plain snap-back, and the dialog never blinks (for example "the save failed, keep editing", checked through `details.returnValue`). A dismissal is already done when `onOpenChange` runs: a parent that does not adopt `false` gets the dialog re-opened at once, and the user sees it close and come back (a modal dialog takes focus back; a non-modal one leaves focus where the dismissal put it). Adopt a dismissal's `false` directly in `onOpenChange` (not in `startTransition`, not after an `await`). If the user dismisses the dialog while a part's close is still running, `onOpenChange` hears it at once and that close is superseded: a later veto of it changes nothing. Neither is a way to ask the user first: an action must never await input, so build confirmation inside the dialog (see the callout above).
|
|
540
540
|
|
|
541
541
|
## Suspense
|
|
542
542
|
|
|
@@ -268,7 +268,7 @@ With a function `action` (a Server Function, a `useActionState` dispatch, or a c
|
|
|
268
268
|
- After a submission with errors, the first field with an error is focused (its message is announced with `ariaNotify()` when focus is already on it). Errors present at mount (a progressive-enhancement post-back, a Server Component prop) are shown without moving focus.
|
|
269
269
|
- An error about a value the user changed while the submission was in flight is not shown: it is about a value they already replaced.
|
|
270
270
|
- **Reset only on success.** React resets a form after every successful action, including one that returned field errors, which wipes what the user typed. The Form resets (`form.reset()`) only when the submission settles with no error in `errors`; pass `autoReset={false}` to keep the values (a settings form).
|
|
271
|
-
- An action that throws reaches the nearest Error Boundary above `Form.Root`; nothing is reset. Return errors from the action to keep the form.
|
|
271
|
+
- An action that throws reaches the nearest Error Boundary above `Form.Root`; nothing is reset. Return errors from the action to keep the form. The rejection of a submission a later one superseded, or of one that settles after the form unmounted or was hidden, goes to `reportError` instead, like every other action (see [Action props](../concepts/action-props.md)).
|
|
272
272
|
- A second submit while one is pending is not dropped: a `useActionState` dispatch queues it. Block repeat clicks with CSS on `Form.Submit[data-pending]` if you need to; the button is never disabled.
|
|
273
273
|
|
|
274
274
|
#### <a id="dialog-form"></a>In a Dialog: `Dialog.Form` rendered as `Form.Root`
|
|
@@ -379,14 +379,14 @@ No `role` and no live region: after a submission focus moves to the field and re
|
|
|
379
379
|
|
|
380
380
|
| Prop | Type | Default | Description |
|
|
381
381
|
| - | - | - | - |
|
|
382
|
-
| `disabled` | `boolean` | `false` | Native `disabled
|
|
382
|
+
| `disabled` | `boolean` | `false` | Native `disabled`; owned, so a `render` element cannot re-enable it. Never set by the library while pending. Native also with a component `render` (assumed to render a submit button: only native `disabled` stops a submitter before hydration). With a host element of another tag (`render={<a />}`), `aria-disabled="true"` instead and the click is cancelled. |
|
|
383
383
|
| `className` | `string \| ((state: FormSubmitState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
384
384
|
| `style` | `CSSProperties \| ((state: FormSubmitState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
385
385
|
| `children` | `ReactNode \| ((state: FormSubmitState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
386
386
|
| `render` | `ReactElement \| ((props, state: FormSubmitState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
387
387
|
|
|
388
388
|
- **State**: `FormSubmitState` is `{ pending, disabled }`; `pending` is `useFormStatus().pending` of the enclosing form, so it works in any React form (`Dialog.Form`, a plain `<form action>`).
|
|
389
|
-
- **Owned**: `type` (`"submit"`, on a `<button>`), `disabled`, `data-pending`, `data-disabled`.
|
|
389
|
+
- **Owned**: `type` (`"submit"`, on a `<button>`), `disabled`, `aria-disabled` (a host element other than `<button>` / `<input>`), `onClick` (while disabled), `data-pending`, `data-disabled`.
|
|
390
390
|
|
|
391
391
|
`name`, `value` and `formAction` pass through.
|
|
392
392
|
|
|
@@ -397,6 +397,7 @@ No `role` and no live region: after a submission focus moves to the field and re
|
|
|
397
397
|
| `data-invalid` | every Field part | An error is shown (`FieldState.invalid`). |
|
|
398
398
|
| `data-required` | every Field part | `Field.Root required` or the control's own `required`. |
|
|
399
399
|
| `data-disabled` | every Field part, Form.Submit | Disabled by prop. |
|
|
400
|
+
| `aria-disabled` | Form.Submit | `disabled` with a `render` element that cannot be natively disabled (`<a>`). |
|
|
400
401
|
| `data-pending` | every Field part, Form.Root, Form.Submit | The form's submission is in flight. A FUNSTACK control inside keeps its own `data-pending` for its own action. |
|
|
401
402
|
| `:user-invalid`, `:user-valid` | the control | The platform's; work before hydration. `data-invalid` adds server errors and the parts that are not the control. |
|
|
402
403
|
|
|
@@ -245,14 +245,14 @@ A `<button popovertarget>`: see [Triggers of a popup](../concepts/browser-owned-
|
|
|
245
245
|
|
|
246
246
|
| Prop | Type | Default | Description |
|
|
247
247
|
| - | - | - | - |
|
|
248
|
-
| `disabled` | `boolean` | `false` | Native `disabled`: a disabled button is not an invoker and never dispatches. Owned, so a `render` element cannot re-enable it. In library mode with a link or component `render`, `aria-disabled="true"` instead (the element stays focusable). |
|
|
248
|
+
| `disabled` | `boolean` | `false` | Native `disabled`: a disabled button is not an invoker and never dispatches. Owned, so a `render` element cannot re-enable it. In library mode with a link or component `render`, `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. |
|
|
249
249
|
| `className` | `string \| ((state: PopoverTriggerState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
250
250
|
| `style` | `CSSProperties \| ((state: PopoverTriggerState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
251
251
|
| `children` | `ReactNode \| ((state: PopoverTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
|
|
252
252
|
| `render` | `ReactElement \| ((props, state: PopoverTriggerState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
253
253
|
|
|
254
254
|
- **State**: `PopoverTriggerState` is `{ open, pending, disabled }`; `pending` is true while the Root is pending: an open or a part's close, never a dismissal (a request still running when a dismissal superseded it keeps `pending` until that request settles).
|
|
255
|
-
- **Owned**: `type` (only on a `<button>`), `disabled`, `aria-disabled` (library mode
|
|
255
|
+
- **Owned**: `type` (only on a `<button>`), `disabled`, `aria-disabled` (a host link; in library mode also a component `render`), `popoverTarget` (only on an invoker), `aria-expanded` (only on a Trigger that is no invoker), `onClick` (library mode), `data-open`, `data-pending`, `data-disabled`. Owned and never written: `popoverTargetAction`, `commandfor`, `command`. Not in the props type: these three, `popoverTarget` and `aria-expanded`.
|
|
256
256
|
|
|
257
257
|
A click on a `<button>` Trigger while open is a part's close; a second click during a pending open cancels it (the latest intent wins). A Trigger rendered as another element (library mode only) is light-dismissed before its click; that close is a fact, `onOpenChange(false)` with `"activate"` and the click. `aria-haspopup` and `aria-controls` pass through.
|
|
258
258
|
|
|
@@ -281,7 +281,7 @@ A click on a `<button>` Trigger while open is a part's close; a second click dur
|
|
|
281
281
|
| - | - | - | - |
|
|
282
282
|
| `action` | `Action<[details: ActionDetails]>` | – | Runs in this button's own transition (`data-pending` on it), then closes the popover: in library mode through the Root (`openChangeAction(false)` awaited, view transition if set), in JS-free mode with `hidePopover()`. A rejection reaches the nearest Error Boundary above the button and leaves the popover open. A second click while it is pending is ignored, and the button is `aria-disabled="true"` meanwhile, unless `whilePending` is `"run"`. Without `action` in JS-free mode the button is a native `command="hide-popover"` invoker. |
|
|
283
283
|
| `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 popover 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). |
|
|
284
|
-
| `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). |
|
|
284
|
+
| `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. |
|
|
285
285
|
| `className` | `string \| ((state: PopoverCloseState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
286
286
|
| `style` | `CSSProperties \| ((state: PopoverCloseState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
287
287
|
| `children` | `ReactNode \| ((state: PopoverCloseState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
@@ -472,7 +472,7 @@ export function PopoverActions() {
|
|
|
472
472
|
|
|
473
473
|
> **Refusing a close**
|
|
474
474
|
>
|
|
475
|
-
> A controlled parent that keeps `open` after a **part-initiated** close vetoes it: nothing was hidden, the Trigger's `data-open` snaps back. After a **dismissal** the popover is already hidden; a parent that keeps `open` gets it re-opened at once, which the user sees as a blink
|
|
475
|
+
> A controlled parent that keeps `open` after a **part-initiated** close vetoes it: nothing was hidden, the Trigger's `data-open` snaps back. After a **dismissal** the popover is already hidden; a parent that keeps `open` gets it re-opened at once, which the user sees as a blink. The re-open never moves focus: it stays where the dismissal put it (the Trigger after Escape, the element clicked outside), for the default `<dialog>` popup as for a `<div>` one. Adopt `false` in `onOpenChange`, directly (`onOpenChange={setOpen}`), not in `startTransition` and not after an `await`.
|
|
476
476
|
|
|
477
477
|
### A slow `openChangeAction`
|
|
478
478
|
|
|
@@ -493,13 +493,14 @@ On the server every method is a no-op with a development warning, and nothing is
|
|
|
493
493
|
| `action` | `Action<[ToastActionDetails]>` | `toast.action.action` | Runs in this part's transition. The part renders nothing when neither it nor the toast has an action. |
|
|
494
494
|
| `closeOnSettle` | `boolean` | `true` | Close the toast (`reason: "activate"`) when the action resolves. |
|
|
495
495
|
| `whilePending` | `"run" \| "ignore"` | `"ignore", or "run" with closeOnSettle={false}` | What a click does while this part's action is pending. `"ignore"`: nothing (the click is cancelled, `aria-disabled="true"` meanwhile). `"run"`: the action runs again; the Action and the Root stay `data-pending` and the timer paused until every run has settled; with `closeOnSettle` the toast then closes once, if the latest run resolved (a rejection keeps it, in both modes). Set it on the part: `toast({ action })` has no such option. See [A second click while pending](../concepts/pending-and-optimistic.md#second-click). |
|
|
496
|
+
| `disabled` | `boolean` | `false` | Never runs the action. Native `disabled`; owned, so a `render` element cannot re-enable it. With a link or component `render`, `aria-disabled="true"` instead and the click is cancelled (a link does not navigate). |
|
|
496
497
|
| `className` | `string \| ((state: ToastActionState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
497
498
|
| `style` | `CSSProperties \| ((state: ToastActionState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
498
499
|
| `children` | `ReactNode \| ((state: ToastActionState) => ReactNode)` | – | Default: `toast.action.label`. |
|
|
499
500
|
| `render` | `ReactElement \| ((props, state: ToastActionState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
500
501
|
|
|
501
|
-
- **State**: `ToastActionState` is `{ pending, toast }
|
|
502
|
-
- **Owned**: `type` (on a `<button>` only), `onClick`, `aria-disabled`, `data-pending`.
|
|
502
|
+
- **State**: `ToastActionState` is `{ pending, disabled, toast }`; `disabled` is the prop, never set by pending.
|
|
503
|
+
- **Owned**: `type` (on a `<button>` only), `disabled`, `onClick`, `aria-disabled`, `data-pending`, `data-disabled`.
|
|
503
504
|
|
|
504
505
|
By default (`whilePending="ignore"` unless `closeOnSettle={false}`) a second click while the action is pending is ignored (and cancelled): one Undo, one Retry. The Action is then `aria-disabled="true"` while it shows `data-pending`; it is never natively disabled, so it keeps focus.
|
|
505
506
|
|
|
@@ -507,13 +508,14 @@ By default (`whilePending="ignore"` unless `closeOnSettle={false}`) a second cli
|
|
|
507
508
|
|
|
508
509
|
| Prop | Type | Default | Description |
|
|
509
510
|
| - | - | - | - |
|
|
511
|
+
| `disabled` | `boolean` | `false` | Never closes. Native `disabled`; owned, so a `render` element cannot re-enable it. With a link or component `render`, `aria-disabled="true"` instead and the click is cancelled (a link does not navigate). |
|
|
510
512
|
| `className` | `string \| ((state: ToastCloseState) => string \| undefined)` | – | A class name, or a function of the part's state. |
|
|
511
513
|
| `style` | `CSSProperties \| ((state: ToastCloseState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
|
|
512
514
|
| `children` | `ReactNode \| ((state: ToastCloseState) => ReactNode)` | – | Content, or a function of the part's state. |
|
|
513
515
|
| `render` | `ReactElement \| ((props, state: ToastCloseState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). |
|
|
514
516
|
|
|
515
|
-
- **State**: `ToastCloseState` is `{ toast }`.
|
|
516
|
-
- **Owned**: `type` (on a `<button>` only), `onClick`.
|
|
517
|
+
- **State**: `ToastCloseState` is `{ disabled, toast }`.
|
|
518
|
+
- **Owned**: `type` (on a `<button>` only), `disabled`, `aria-disabled` (link or component `render`), `onClick`, `data-disabled`.
|
|
517
519
|
|
|
518
520
|
Closes the toast with `reason: "dismiss"`, like Escape. Give it a name (text or `aria-label`); development warns otherwise.
|
|
519
521
|
|
|
@@ -522,7 +524,8 @@ Closes the toast with `reason: "dismiss"`, like Escape. Give it a name (text or
|
|
|
522
524
|
| Hook | On | Meaning |
|
|
523
525
|
| - | - | - |
|
|
524
526
|
| `data-pending` | Root, Action | The toast's promise is unsettled, or its Action's action runs (not set while its content merely suspends) |
|
|
525
|
-
| `aria-disabled` | Action | `"true"` while `data-pending` with `whilePending="ignore"` (the default unless `closeOnSettle={false}`): a second click is ignored |
|
|
527
|
+
| `aria-disabled` | Action, Close | `"true"` on the Action while `data-pending` with `whilePending="ignore"` (the default unless `closeOnSettle={false}`): a second click is ignored. Also on either part when `disabled` with a link or component `render` |
|
|
528
|
+
| `data-disabled` | Action, Close | The part's `disabled` prop (never set by pending) |
|
|
526
529
|
| `data-ending` | Root | Closed, kept (and `inert`) until the animations the ending state started finish |
|
|
527
530
|
| `data-type` | Root | The toast's `type` |
|
|
528
531
|
| `data-paused` | Viewport | A viewport-wide timer pause holds; pause a progress bar with it |
|
|
@@ -68,7 +68,7 @@ A popup the browser opened before hydration is still a request (`openChangeActio
|
|
|
68
68
|
|
|
69
69
|
**Controlled mode needs both props.** Pass the same setter to both: `openChangeAction` adopts a request (in a transition), `onOpenChange` adopts a fact (an [urgent update](action-props.md#urgent-update)). Set state directly in `onOpenChange`, never in `startTransition` and never after an `await`: a parent that still says `open={true}` once the browser's event has been handled gets the element shown again at once, and a late `false` then closes it a second time. A controlled Root without `onOpenChange` warns in development.
|
|
70
70
|
|
|
71
|
-
A parent that keeps `open={true}` after a dismissal on purpose gets the same re-open. This is not a veto: the user sees the element close and come back, possibly for a frame. A popup that must not be dismissed is set up on the platform side instead, where the component offers it. The re-open
|
|
71
|
+
A parent that keeps `open={true}` after a dismissal on purpose gets the same re-open. This is not a veto: the user sees the element close and come back, possibly for a frame. A popup that must not be dismissed is set up on the platform side instead, where the component offers it. The re-open never moves focus: a Menu, a Combobox, a Popover (its default `<dialog>` as well as a `<div>`) or a non-modal Dialog shown again this way leaves focus where the dismissal put it (the Trigger after Escape, the field the user clicked, the next field after Tab). So a parent that never adopts `false` cannot trap the keyboard in the popup, and the re-open does not take focus away from the field the user just clicked. A modal Dialog (the default) is the exception: it must hold focus, so its re-open moves focus inside as on any open.
|
|
72
72
|
|
|
73
73
|
**Uncontrolled, pass what you need.** `openChangeAction` for work an open or a part's close must wait for (loading data on open); `onOpenChange` to observe a dismissal (logging it, remembering it). To hear every close, pass one function to both props and check its first argument: the action is called with `true` for an open too.
|
|
74
74
|
|
package/dist/docs/roadmap.md
CHANGED
|
@@ -10,6 +10,14 @@ Alpha releases (`0.1.0-alpha.N`) are published on npm under the `alpha` dist-tag
|
|
|
10
10
|
|
|
11
11
|
Changes an upgrade may notice, newest first. Each component page documents the current behaviour.
|
|
12
12
|
|
|
13
|
+
- A disabled `Button` whose click the browser acts on (`type="submit"` or `"reset"`, the `formAction` default, `commandfor` / `popoverTarget`, with or without `action`) keeps native `disabled` also with a component or `<input>` `render`, as `Form.Submit` does; it used to render `aria-disabled`, which does not stop a submission or command before hydration ([#158](https://github.com/uhyo/funstack-ui/issues/158)). Inside a `Toolbar.Root` or with `focusableWhenDisabled` nothing changes. A natively disabled `Button`, `Dialog.Close`, `Popover.Close` or `Toast.Action` that is also pending no longer adds `aria-disabled`: native `disabled` wins. A disabled JS-free Trigger or Close of a Dialog or Popover rendered as a host link renders `aria-disabled` instead of a meaningless `disabled` attribute, and its click is cancelled (the link no longer navigates after hydration).
|
|
14
|
+
|
|
15
|
+
- Three alignments with the library-wide rules ([#157](https://github.com/uhyo/funstack-ui/issues/157)):
|
|
16
|
+
|
|
17
|
+
- Accordion in multiple mode passes `valueChangeAction` its open items in document order also when an Item mounted later (inserted between others, or behind a Suspense boundary); such an Item used to sort last. In exclusive mode, of several items opened before hydration the first in the document wins.
|
|
18
|
+
- `Toast.Action` and `Toast.Close` render `data-disabled` when `disabled`, and on a link or component `render` `aria-disabled="true"` with a cancelled click (a disabled link no longer navigates); their state has a new `disabled` field. `Form.Submit` with a host element that is not a `<button>` or `<input>` (`render={<a />}`) renders `aria-disabled` with a cancelled click instead of a meaningless `disabled` attribute.
|
|
19
|
+
- `Form.Root` passes the rejection of a submission that a later one superseded, or of one that settles after the form unmounted or was hidden, to `reportError` (a window `error` event) instead of dropping it. The latest submission's rejection still reaches the Error Boundary.
|
|
20
|
+
|
|
13
21
|
- A popup with both a CSS exit and `transition` no longer needs the rule `html:active-view-transition .my-popup { transition: none; }` ([#147](https://github.com/uhyo/funstack-ui/issues/147); [A popup with a CSS exit and a view transition](concepts/transitions.md#css-exit)). While a view transition runs, the library turns the popup's CSS transitions off for the moment of its own show or hide, with an inline `transition: none !important` that it removes right after. The rule is not needed: remove it. Keeping it breaks nothing, but an unrelated view transition of the page then still cuts a dismissal's CSS fade.
|
|
14
22
|
|
|
15
23
|
- **Breaking:** requests and facts ([#148](https://github.com/uhyo/funstack-ui/issues/148); [Requests and facts](concepts/browser-owned-state.md#requests-and-facts)). On `Popover.Root`, `Menu.Root`, `Combobox.Root` and `Dialog.Root`:
|
|
@@ -83,7 +91,7 @@ Changes an upgrade may notice, newest first. Each component page documents the c
|
|
|
83
91
|
|
|
84
92
|
- Every Menu closes on a right- or middle-click outside; a wheel over a menu never scrolls the page ([#45](https://github.com/uhyo/funstack-ui/issues/45), [#88](https://github.com/uhyo/funstack-ui/issues/88)).
|
|
85
93
|
|
|
86
|
-
- `disabled` on a link or component `render` renders `aria-disabled="true"` instead of native `disabled` on Toggle, ToggleGroup.Item, Menu.Trigger, Combobox.Trigger and Clear, NumberField.Increment and Decrement, and the Dialog and Popover Trigger and Close parts where they handle the click; a disabled link ToggleGroup.Item is reached by the arrow keys. Form.Submit keeps native `disabled` ([#83](https://github.com/uhyo/funstack-ui/issues/83)).
|
|
94
|
+
- `disabled` on a link or component `render` renders `aria-disabled="true"` instead of native `disabled` on Toggle, ToggleGroup.Item, Menu.Trigger, Combobox.Trigger and Clear, NumberField.Increment and Decrement, and the Dialog and Popover Trigger and Close parts where they handle the click; a disabled link ToggleGroup.Item is reached by the arrow keys. Form.Submit keeps native `disabled` ([#83](https://github.com/uhyo/funstack-ui/issues/83); since [#157](https://github.com/uhyo/funstack-ui/issues/157) except on a host element that is not a `<button>` or `<input>`).
|
|
87
95
|
|
|
88
96
|
- `Dialog.Close`, `Popover.Close`, `Menu.Item` and `Toast.Action` ignore a second click while their own action is pending, with `aria-disabled` meanwhile; before, a second click ran the action again ([#81](https://github.com/uhyo/funstack-ui/issues/81)).
|
|
89
97
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { FieldState } from "../internal/field-context.mjs";
|
|
2
|
+
import { FieldState } from "../internal/form/field-context.mjs";
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef } from "react";
|
|
4
4
|
//#region src/field/field-control.d.ts
|
|
5
5
|
/**
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { useRender } from "../internal/use-render.mjs";
|
|
3
3
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
4
4
|
import { useMergedRefs } from "../internal/use-merged-refs.mjs";
|
|
5
|
-
import { fieldDataAttributes, useFieldContext } from "../internal/field-context.mjs";
|
|
6
|
-
import { useFieldControl } from "../internal/use-field-control.mjs";
|
|
5
|
+
import { fieldDataAttributes, useFieldContext } from "../internal/form/field-context.mjs";
|
|
6
|
+
import { useFieldControl } from "../internal/form/use-field-control.mjs";
|
|
7
7
|
//#region src/field/field-control.tsx
|
|
8
8
|
const isDev = process.env.NODE_ENV !== "production";
|
|
9
9
|
const CONTROL_TAGS = /* @__PURE__ */ new Set([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-control.mjs","names":[],"sources":["../../src/field/field-control.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/field-context.js\";\nimport type { FieldState } from \"../internal/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `Field.Control`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldControlProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n \"id\" | \"aria-invalid\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Native `name`.\n *\n * @defaultValue the Field's `name`\n */\n name?: string;\n /**\n * Native `disabled`. Owned. Also `true` when the Field is disabled: an explicit `false` does not\n * override the Field.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Native `required`. Owned. Also `true` when the Field is required: an explicit `false` does not\n * override the Field.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Must render an `<input>`, `<textarea>` or `<select>`: `render={<textarea rows={3} />}`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, FieldState>;\n}\n\nconst CONTROL_TAGS = new Set([\"INPUT\", \"TEXTAREA\", \"SELECT\"]);\n\n/**\n * The field's native control: an `<input>` (or a `<textarea>` / `<select>` through `render`)\n * wired to the Field: `id` for the Label, `aria-describedby` (the consumer's tokens, the\n * description, the error while shown), an explicit `aria-invalid`, and `name` / `disabled` /\n * `required` from the Field unless given. Everything else passes through, including `onChange`\n * / `value` for a controlled input; the Field's listeners are native and run independently.\n *\n * Owned keys (conventions 1.2): `id`, `name`, `disabled`, `required`, `aria-invalid`,\n * `aria-describedby` (token-merged), `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldControl({\n name,\n disabled,\n required,\n className,\n style,\n render,\n ...rest\n}: FieldControlProps) {\n const ctx = useFieldContext(\"Field.Control\");\n // `id` is not in the props type (the Field owns it); a JS caller's is ignored with a warning.\n const { id: consumerId, ...props } = rest as typeof rest & { id?: string };\n const field = useFieldControl({\n labelable: true,\n name,\n disabled,\n required,\n id: consumerId,\n component: \"Field.Control\",\n });\n const checkElement = useElementCheck(\n isDev &&\n ((el) =>\n !CONTROL_TAGS.has(el.tagName)\n ? \"Field.Control: expected to render an <input>, <textarea> or <select> but got \" +\n `<${el.tagName.toLowerCase()}>. Validation, labelling and form participation need a ` +\n \"native form control.\"\n : null),\n );\n const ref = useMergedRefs<HTMLElement>(checkElement, field.ref);\n\n return useRender<ComponentPropsWithRef<\"input\">, FieldState>({\n defaultElement: \"input\",\n render,\n state: ctx.state,\n className,\n style,\n children: undefined,\n props,\n libraryProps: {\n id: field.id,\n name: field.name,\n disabled: field.disabled,\n required: field.required,\n ...field.attributes,\n ...fieldDataAttributes(ctx.state),\n },\n ref,\n });\n}\n\nFieldControl.displayName = \"FieldControl\";\n"],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuCvC,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAS;CAAY;AAAQ,CAAC;;;;;;;;;;;;;;AAe5D,SAAgB,aAAa,EAC3B,MACA,UACA,UACA,WACA,OACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,gBAAgB,eAAe;CAE3C,MAAM,EAAE,IAAI,YAAY,GAAG,UAAU;CACrC,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX;EACA;EACA;EACA,IAAI;EACJ,WAAW;CACb,CAAC;CACD,MAAM,eAAe,gBACnB,WACI,OACA,CAAC,aAAa,IAAI,GAAG,OAAO,IACxB,iFACI,GAAG,QAAQ,YAAY,EAAE,+EAE7B,KACV;CACA,MAAM,MAAM,cAA2B,cAAc,MAAM,GAAG;CAE9D,OAAO,UAAsD;EAC3D,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA,UAAU,KAAA;EACV;EACA,cAAc;GACZ,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,UAAU,MAAM;GAChB,UAAU,MAAM;GAChB,GAAG,MAAM;GACT,GAAG,oBAAoB,IAAI,KAAK;EAClC;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
|
|
1
|
+
{"version":3,"file":"field-control.mjs","names":[],"sources":["../../src/field/field-control.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/form/field-context.js\";\nimport type { FieldState } from \"../internal/form/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useFieldControl } from \"../internal/form/use-field-control.js\";\nimport { useMergedRefs } from \"../internal/use-merged-refs.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `Field.Control`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldControlProps extends Omit<\n ComponentPropsWithRef<\"input\">,\n \"id\" | \"aria-invalid\" | \"className\" | \"style\" | \"children\"\n> {\n /**\n * Native `name`.\n *\n * @defaultValue the Field's `name`\n */\n name?: string;\n /**\n * Native `disabled`. Owned. Also `true` when the Field is disabled: an explicit `false` does not\n * override the Field.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n /**\n * Native `required`. Owned. Also `true` when the Field is required: an explicit `false` does not\n * override the Field.\n *\n * @defaultValue `false`\n */\n required?: boolean;\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Must render an `<input>`, `<textarea>` or `<select>`: `render={<textarea rows={3} />}`. */\n render?: RenderProp<ComponentPropsWithRef<\"input\">, FieldState>;\n}\n\nconst CONTROL_TAGS = new Set([\"INPUT\", \"TEXTAREA\", \"SELECT\"]);\n\n/**\n * The field's native control: an `<input>` (or a `<textarea>` / `<select>` through `render`)\n * wired to the Field: `id` for the Label, `aria-describedby` (the consumer's tokens, the\n * description, the error while shown), an explicit `aria-invalid`, and `name` / `disabled` /\n * `required` from the Field unless given. Everything else passes through, including `onChange`\n * / `value` for a controlled input; the Field's listeners are native and run independently.\n *\n * Owned keys (conventions 1.2): `id`, `name`, `disabled`, `required`, `aria-invalid`,\n * `aria-describedby` (token-merged), `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldControl({\n name,\n disabled,\n required,\n className,\n style,\n render,\n ...rest\n}: FieldControlProps) {\n const ctx = useFieldContext(\"Field.Control\");\n // `id` is not in the props type (the Field owns it); a JS caller's is ignored with a warning.\n const { id: consumerId, ...props } = rest as typeof rest & { id?: string };\n const field = useFieldControl({\n labelable: true,\n name,\n disabled,\n required,\n id: consumerId,\n component: \"Field.Control\",\n });\n const checkElement = useElementCheck(\n isDev &&\n ((el) =>\n !CONTROL_TAGS.has(el.tagName)\n ? \"Field.Control: expected to render an <input>, <textarea> or <select> but got \" +\n `<${el.tagName.toLowerCase()}>. Validation, labelling and form participation need a ` +\n \"native form control.\"\n : null),\n );\n const ref = useMergedRefs<HTMLElement>(checkElement, field.ref);\n\n return useRender<ComponentPropsWithRef<\"input\">, FieldState>({\n defaultElement: \"input\",\n render,\n state: ctx.state,\n className,\n style,\n children: undefined,\n props,\n libraryProps: {\n id: field.id,\n name: field.name,\n disabled: field.disabled,\n required: field.required,\n ...field.attributes,\n ...fieldDataAttributes(ctx.state),\n },\n ref,\n });\n}\n\nFieldControl.displayName = \"FieldControl\";\n"],"mappings":";;;;;;;AAUA,MAAM,QAAQ,QAAQ,IAAI,aAAa;AAuCvC,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAS;CAAY;AAAQ,CAAC;;;;;;;;;;;;;;AAe5D,SAAgB,aAAa,EAC3B,MACA,UACA,UACA,WACA,OACA,QACA,GAAG,QACiB;CACpB,MAAM,MAAM,gBAAgB,eAAe;CAE3C,MAAM,EAAE,IAAI,YAAY,GAAG,UAAU;CACrC,MAAM,QAAQ,gBAAgB;EAC5B,WAAW;EACX;EACA;EACA;EACA,IAAI;EACJ,WAAW;CACb,CAAC;CACD,MAAM,eAAe,gBACnB,WACI,OACA,CAAC,aAAa,IAAI,GAAG,OAAO,IACxB,iFACI,GAAG,QAAQ,YAAY,EAAE,+EAE7B,KACV;CACA,MAAM,MAAM,cAA2B,cAAc,MAAM,GAAG;CAE9D,OAAO,UAAsD;EAC3D,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA,UAAU,KAAA;EACV;EACA,cAAc;GACZ,IAAI,MAAM;GACV,MAAM,MAAM;GACZ,UAAU,MAAM;GAChB,UAAU,MAAM;GAChB,GAAG,MAAM;GACT,GAAG,oBAAoB,IAAI,KAAK;EAClC;EACA;CACF,CAAC;AACH;AAEA,aAAa,cAAc"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { FieldState } from "../internal/field-context.mjs";
|
|
2
|
+
import { FieldState } from "../internal/form/field-context.mjs";
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
4
4
|
//#region src/field/field-description.d.ts
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
-
import { fieldDataAttributes, useFieldContext } from "../internal/field-context.mjs";
|
|
3
|
+
import { fieldDataAttributes, useFieldContext } from "../internal/form/field-context.mjs";
|
|
4
4
|
//#region src/field/field-description.tsx
|
|
5
5
|
/**
|
|
6
6
|
* Help text for the field: a `<p>` whose id the control always lists in `aria-describedby`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-description.mjs","names":[],"sources":["../../src/field/field-description.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/field-context.js\";\nimport type { FieldState } from \"../internal/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/**\n * Props of `Field.Description`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldDescriptionProps extends Omit<\n ComponentPropsWithRef<\"p\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<p>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"p\">, FieldState>;\n}\n\n/**\n * Help text for the field: a `<p>` whose id the control always lists in `aria-describedby`\n * (a dangling reference when no Description is rendered is skipped by assistive technology, so\n * nothing registers and the server HTML is exact).\n *\n * Owned keys (conventions 1.2): `id`, `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldDescription({\n className,\n style,\n children,\n render,\n ...rest\n}: FieldDescriptionProps) {\n const ctx = useFieldContext(\"Field.Description\");\n return useRender<ComponentPropsWithRef<\"p\">, FieldState>({\n defaultElement: \"p\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.description, ...fieldDataAttributes(ctx.state) },\n });\n}\n\nFieldDescription.displayName = \"FieldDescription\";\n"],"mappings":";;;;;;;;;;;;;;AAoCA,SAAgB,iBAAiB,EAC/B,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,MAAM,gBAAgB,mBAAmB;CAC/C,OAAO,UAAkD;EACvD,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GAAE,IAAI,IAAI,IAAI;GAAa,GAAG,oBAAoB,IAAI,KAAK;EAAE;CAC7E,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
1
|
+
{"version":3,"file":"field-description.mjs","names":[],"sources":["../../src/field/field-description.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/form/field-context.js\";\nimport type { FieldState } from \"../internal/form/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/**\n * Props of `Field.Description`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldDescriptionProps extends Omit<\n ComponentPropsWithRef<\"p\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<p>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"p\">, FieldState>;\n}\n\n/**\n * Help text for the field: a `<p>` whose id the control always lists in `aria-describedby`\n * (a dangling reference when no Description is rendered is skipped by assistive technology, so\n * nothing registers and the server HTML is exact).\n *\n * Owned keys (conventions 1.2): `id`, `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldDescription({\n className,\n style,\n children,\n render,\n ...rest\n}: FieldDescriptionProps) {\n const ctx = useFieldContext(\"Field.Description\");\n return useRender<ComponentPropsWithRef<\"p\">, FieldState>({\n defaultElement: \"p\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.description, ...fieldDataAttributes(ctx.state) },\n });\n}\n\nFieldDescription.displayName = \"FieldDescription\";\n"],"mappings":";;;;;;;;;;;;;;AAoCA,SAAgB,iBAAiB,EAC/B,WACA,OACA,UACA,QACA,GAAG,QACqB;CACxB,MAAM,MAAM,gBAAgB,mBAAmB;CAC/C,OAAO,UAAkD;EACvD,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GAAE,IAAI,IAAI,IAAI;GAAa,GAAG,oBAAoB,IAAI,KAAK;EAAE;CAC7E,CAAC;AACH;AAEA,iBAAiB,cAAc"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { FieldState } from "../internal/field-context.mjs";
|
|
2
|
+
import { FieldState } from "../internal/form/field-context.mjs";
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
4
4
|
//#region src/field/field-error.d.ts
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRender } from "../internal/use-render.mjs";
|
|
3
|
-
import { fieldDataAttributes, useFieldContext } from "../internal/field-context.mjs";
|
|
3
|
+
import { fieldDataAttributes, useFieldContext } from "../internal/form/field-context.mjs";
|
|
4
4
|
import { useLayoutEffect } from "react";
|
|
5
5
|
//#region src/field/field-error.tsx
|
|
6
6
|
function defaultChildren(state) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-error.mjs","names":[],"sources":["../../src/field/field-error.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/field-context.js\";\nimport type { FieldState } from \"../internal/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/**\n * Props of `Field.Error`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldErrorProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /**\n * Rendered only while `state.invalid`. A function gets the state:\n * `({ validity, messages }) => validity.valueMissing ? \"Enter your email\" : messages.join(\" \")`.\n * Must not suspend (urgent render, design 2.4).\n *\n * @defaultValue `state.messages` joined by a space\n */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, FieldState>;\n}\n\nfunction defaultChildren(state: FieldState): ReactNode {\n return state.messages.join(\" \");\n}\n\n/**\n * The field's error message: a `div` rendered only while an error is shown, whose id the control\n * then lists in `aria-describedby`. No role and no live region: the library focuses the first\n * invalid control after a submission attempt, and focus reads the description (design 4.2).\n * Its presence lets the Field cancel the platform's validation bubble.\n *\n * Owned keys (conventions 1.2): `id`, `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldError({\n className,\n style,\n children = defaultChildren,\n render,\n ...rest\n}: FieldErrorProps) {\n const ctx = useFieldContext(\"Field.Error\");\n const { registerError } = ctx;\n useLayoutEffect(registerError, [registerError]);\n const element = useRender<ComponentPropsWithRef<\"div\">, FieldState>({\n defaultElement: \"div\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.error, ...fieldDataAttributes(ctx.state) },\n });\n return ctx.state.invalid ? element : null;\n}\n\nFieldError.displayName = \"FieldError\";\n"],"mappings":";;;;;AAiCA,SAAS,gBAAgB,OAA8B;CACrD,OAAO,MAAM,SAAS,KAAK,GAAG;AAChC;;;;;;;;;;;;AAaA,SAAgB,WAAW,EACzB,WACA,OACA,WAAW,iBACX,QACA,GAAG,QACe;CAClB,MAAM,MAAM,gBAAgB,aAAa;CACzC,MAAM,EAAE,kBAAkB;CAC1B,gBAAgB,eAAe,CAAC,aAAa,CAAC;CAC9C,MAAM,UAAU,UAAoD;EAClE,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GAAE,IAAI,IAAI,IAAI;GAAO,GAAG,oBAAoB,IAAI,KAAK;EAAE;CACvE,CAAC;CACD,OAAO,IAAI,MAAM,UAAU,UAAU;AACvC;AAEA,WAAW,cAAc"}
|
|
1
|
+
{"version":3,"file":"field-error.mjs","names":[],"sources":["../../src/field/field-error.tsx"],"sourcesContent":["\"use client\";\nimport { useLayoutEffect } from \"react\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/form/field-context.js\";\nimport type { FieldState } from \"../internal/form/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\n/**\n * Props of `Field.Error`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldErrorProps extends Omit<\n ComponentPropsWithRef<\"div\">,\n \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /**\n * Rendered only while `state.invalid`. A function gets the state:\n * `({ validity, messages }) => validity.valueMissing ? \"Enter your email\" : messages.join(\" \")`.\n * Must not suspend (urgent render, design 2.4).\n *\n * @defaultValue `state.messages` joined by a space\n */\n children?: StateValue<ReactNode, FieldState>;\n /** Replace the default `<div>` (element form) or take over rendering (function form). */\n render?: RenderProp<ComponentPropsWithRef<\"div\">, FieldState>;\n}\n\nfunction defaultChildren(state: FieldState): ReactNode {\n return state.messages.join(\" \");\n}\n\n/**\n * The field's error message: a `div` rendered only while an error is shown, whose id the control\n * then lists in `aria-describedby`. No role and no live region: the library focuses the first\n * invalid control after a submission attempt, and focus reads the description (design 4.2).\n * Its presence lets the Field cancel the platform's validation bubble.\n *\n * Owned keys (conventions 1.2): `id`, `data-invalid`, `data-disabled`, `data-required`,\n * `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldError({\n className,\n style,\n children = defaultChildren,\n render,\n ...rest\n}: FieldErrorProps) {\n const ctx = useFieldContext(\"Field.Error\");\n const { registerError } = ctx;\n useLayoutEffect(registerError, [registerError]);\n const element = useRender<ComponentPropsWithRef<\"div\">, FieldState>({\n defaultElement: \"div\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: { id: ctx.ids.error, ...fieldDataAttributes(ctx.state) },\n });\n return ctx.state.invalid ? element : null;\n}\n\nFieldError.displayName = \"FieldError\";\n"],"mappings":";;;;;AAiCA,SAAS,gBAAgB,OAA8B;CACrD,OAAO,MAAM,SAAS,KAAK,GAAG;AAChC;;;;;;;;;;;;AAaA,SAAgB,WAAW,EACzB,WACA,OACA,WAAW,iBACX,QACA,GAAG,QACe;CAClB,MAAM,MAAM,gBAAgB,aAAa;CACzC,MAAM,EAAE,kBAAkB;CAC1B,gBAAgB,eAAe,CAAC,aAAa,CAAC;CAC9C,MAAM,UAAU,UAAoD;EAClE,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GAAE,IAAI,IAAI,IAAI;GAAO,GAAG,oBAAoB,IAAI,KAAK;EAAE;CACvE,CAAC;CACD,OAAO,IAAI,MAAM,UAAU,UAAU;AACvC;AAEA,WAAW,cAAc"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { FieldState } from "../internal/field-context.mjs";
|
|
2
|
+
import { FieldState } from "../internal/form/field-context.mjs";
|
|
3
3
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
4
4
|
//#region src/field/field-label.d.ts
|
|
5
5
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useRender } from "../internal/use-render.mjs";
|
|
3
3
|
import { useElementCheck } from "../internal/use-element-check.mjs";
|
|
4
|
-
import { fieldDataAttributes, useFieldContext } from "../internal/field-context.mjs";
|
|
4
|
+
import { fieldDataAttributes, useFieldContext } from "../internal/form/field-context.mjs";
|
|
5
5
|
//#region src/field/field-label.tsx
|
|
6
6
|
const isDev = process.env.NODE_ENV !== "production";
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-label.mjs","names":[],"sources":["../../src/field/field-label.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/field-context.js\";\nimport type { FieldState } from \"../internal/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `Field.Label`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldLabelProps extends Omit<\n ComponentPropsWithRef<\"label\">,\n \"htmlFor\" | \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Must render a `<label>`. */\n render?: RenderProp<ComponentPropsWithRef<\"label\">, FieldState>;\n}\n\n/**\n * The field's visible name: `<label for>` pointing at the control. For a group control (a\n * RadioGroup or CheckboxGroup `<fieldset>`) it renders no `for` once the group registered, and\n * the group names itself with `aria-labelledby` → this id (design 4.2).\n *\n * Owned keys (conventions 1.2): `id`, `htmlFor`, `data-invalid`, `data-disabled`,\n * `data-required`, `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldLabel({ className, style, children, render, ...rest }: FieldLabelProps) {\n const ctx = useFieldContext(\"Field.Label\");\n const ref = useElementCheck(\n isDev &&\n ((el) =>\n el.tagName !== \"LABEL\"\n ? `Field.Label: expected to render a <label> element but got <${el.tagName.toLowerCase()}>. ` +\n \"Label activation and the control's accessible name need a real <label>.\"\n : null),\n );\n return useRender<ComponentPropsWithRef<\"label\">, FieldState>({\n defaultElement: \"label\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n id: ctx.ids.label,\n htmlFor: ctx.labelable ? ctx.ids.control : undefined,\n ...fieldDataAttributes(ctx.state),\n },\n ref,\n });\n}\n\nFieldLabel.displayName = \"FieldLabel\";\n"],"mappings":";;;;;AAQA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;AA+BvC,SAAgB,WAAW,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAAyB;CAC3F,MAAM,MAAM,gBAAgB,aAAa;CACzC,MAAM,MAAM,gBACV,WACI,OACA,GAAG,YAAY,UACX,8DAA8D,GAAG,QAAQ,YAAY,EAAE,8EAEvF,KACV;CACA,OAAO,UAAsD;EAC3D,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,IAAI,IAAI,IAAI;GACZ,SAAS,IAAI,YAAY,IAAI,IAAI,UAAU,KAAA;GAC3C,GAAG,oBAAoB,IAAI,KAAK;EAClC;EACA;CACF,CAAC;AACH;AAEA,WAAW,cAAc"}
|
|
1
|
+
{"version":3,"file":"field-label.mjs","names":[],"sources":["../../src/field/field-label.tsx"],"sourcesContent":["\"use client\";\nimport type { ComponentPropsWithRef, CSSProperties, ReactNode } from \"react\";\nimport { fieldDataAttributes, useFieldContext } from \"../internal/form/field-context.js\";\nimport type { FieldState } from \"../internal/form/field-context.js\";\nimport type { RenderProp, StateValue } from \"../internal/types.js\";\nimport { useElementCheck } from \"../internal/use-element-check.js\";\nimport { useRender } from \"../internal/use-render.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * Props of `Field.Label`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport interface FieldLabelProps extends Omit<\n ComponentPropsWithRef<\"label\">,\n \"htmlFor\" | \"id\" | \"className\" | \"style\" | \"children\"\n> {\n /** Class name, or a function of the part's state that returns one. */\n className?: StateValue<string | undefined, FieldState>;\n /** Inline style, or a function of the part's state that returns one. */\n style?: StateValue<CSSProperties | undefined, FieldState>;\n /** Content, or a function of the part's state. */\n children?: StateValue<ReactNode, FieldState>;\n /** Must render a `<label>`. */\n render?: RenderProp<ComponentPropsWithRef<\"label\">, FieldState>;\n}\n\n/**\n * The field's visible name: `<label for>` pointing at the control. For a group control (a\n * RadioGroup or CheckboxGroup `<fieldset>`) it renders no `for` once the group registered, and\n * the group names itself with `aria-labelledby` → this id (design 4.2).\n *\n * Owned keys (conventions 1.2): `id`, `htmlFor`, `data-invalid`, `data-disabled`,\n * `data-required`, `data-pending`.\n *\n * @see https://ui.funstack.work/components/field\n */\nexport function FieldLabel({ className, style, children, render, ...rest }: FieldLabelProps) {\n const ctx = useFieldContext(\"Field.Label\");\n const ref = useElementCheck(\n isDev &&\n ((el) =>\n el.tagName !== \"LABEL\"\n ? `Field.Label: expected to render a <label> element but got <${el.tagName.toLowerCase()}>. ` +\n \"Label activation and the control's accessible name need a real <label>.\"\n : null),\n );\n return useRender<ComponentPropsWithRef<\"label\">, FieldState>({\n defaultElement: \"label\",\n render,\n state: ctx.state,\n className,\n style,\n children,\n props: rest,\n libraryProps: {\n id: ctx.ids.label,\n htmlFor: ctx.labelable ? ctx.ids.control : undefined,\n ...fieldDataAttributes(ctx.state),\n },\n ref,\n });\n}\n\nFieldLabel.displayName = \"FieldLabel\";\n"],"mappings":";;;;;AAQA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;AA+BvC,SAAgB,WAAW,EAAE,WAAW,OAAO,UAAU,QAAQ,GAAG,QAAyB;CAC3F,MAAM,MAAM,gBAAgB,aAAa;CACzC,MAAM,MAAM,gBACV,WACI,OACA,GAAG,YAAY,UACX,8DAA8D,GAAG,QAAQ,YAAY,EAAE,8EAEvF,KACV;CACA,OAAO,UAAsD;EAC3D,gBAAgB;EAChB;EACA,OAAO,IAAI;EACX;EACA;EACA;EACA,OAAO;EACP,cAAc;GACZ,IAAI,IAAI,IAAI;GACZ,SAAS,IAAI,YAAY,IAAI,IAAI,UAAU,KAAA;GAC3C,GAAG,oBAAoB,IAAI,KAAK;EAClC;EACA;CACF,CAAC;AACH;AAEA,WAAW,cAAc"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RenderProp, StateValue } from "../internal/types.mjs";
|
|
2
|
-
import { FieldErrorValue, FieldValidity } from "../internal/validity.mjs";
|
|
3
|
-
import { FieldState } from "../internal/field-context.mjs";
|
|
2
|
+
import { FieldErrorValue, FieldValidity } from "../internal/form/validity.mjs";
|
|
3
|
+
import { FieldState } from "../internal/form/field-context.mjs";
|
|
4
4
|
import { CSSProperties, ComponentPropsWithRef, ReactNode } from "react";
|
|
5
5
|
//#region src/field/field-root.d.ts
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-root.d.mts","names":[],"sources":["../../src/field/field-root.tsx"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"field-root.d.mts","names":[],"sources":["../../src/field/field-root.tsx"],"mappings":";;;;;;;;;;YAqDY,iBAAiB,eAAe,UAAU,aAAa;;;;;;iBAOlD,uBAAuB,KACtC;;EAIA;;;;;;EAMA;;;;;;EAMA;;;;;;;;;;;;;;EAcA,WAAW;;EAEX,YAAY,+BAA+B;;EAE3C,QAAQ,WAAW,2BAA2B;;EAE9C,WAAW,WAAW,WAAW;;EAEjC,SAAS,WAAW,8BAA8B;;;;;;;;;;;;;wBA4CpC,YACd,MACA,UACA,UACA,UACA,WACA,OACA,UACA,WACG,QACF,iCAAc,IAAA;yBAVD"}
|
|
@@ -3,10 +3,10 @@ import { useDevWarning } from "../internal/use-dev-warning.mjs";
|
|
|
3
3
|
import { useRender } from "../internal/use-render.mjs";
|
|
4
4
|
import { useLatest } from "../internal/use-latest.mjs";
|
|
5
5
|
import { arraysEqual } from "../internal/value-set.mjs";
|
|
6
|
-
import { FieldContext, FormContext, fieldDataAttributes } from "../internal/field-context.mjs";
|
|
7
|
-
import { useFormOwnerEvent } from "../internal/use-form-owner-event.mjs";
|
|
8
|
-
import { VALID, focusTargetOf, normaliseErrorValue, snapshotValidity, supportsUserInvalid, validityElementOf, validityEquals } from "../internal/validity.mjs";
|
|
9
|
-
import { collectInvalid } from "../internal/focus-first-invalid.mjs";
|
|
6
|
+
import { FieldContext, FormContext, fieldDataAttributes } from "../internal/form/field-context.mjs";
|
|
7
|
+
import { useFormOwnerEvent } from "../internal/form/use-form-owner-event.mjs";
|
|
8
|
+
import { VALID, focusTargetOf, normaliseErrorValue, snapshotValidity, supportsUserInvalid, validityElementOf, validityEquals } from "../internal/form/validity.mjs";
|
|
9
|
+
import { collectInvalid } from "../internal/form/focus-first-invalid.mjs";
|
|
10
10
|
import { useServerErrorVisibility } from "./use-server-error-visibility.mjs";
|
|
11
11
|
import { use, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
12
12
|
import { useFormStatus } from "react-dom";
|