@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,16 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useLatest } from "
|
|
3
|
-
import { useElementCheck } from "
|
|
2
|
+
import { useLatest } from "../use-latest.mjs";
|
|
3
|
+
import { useElementCheck } from "../use-element-check.mjs";
|
|
4
4
|
import { isPopoverOpen } from "./popover-open.mjs";
|
|
5
5
|
import { useContentFocusProbe } from "./content-focus-probe.mjs";
|
|
6
6
|
import { withCssTransitionCut } from "./css-transition-cut.mjs";
|
|
7
7
|
import { commandOf, renderOverlayContent, resolveInitialFocus, returnFocusToTrigger, useCloseHold, useInitialFocusTarget } from "./overlay-popup.mjs";
|
|
8
|
+
import { createPopupFlags, showWithFocus } from "./overlay-show.mjs";
|
|
9
|
+
import { useApplyOpenState } from "./use-apply-open-state.mjs";
|
|
8
10
|
import { closedByPopoverTarget } from "./invokers.mjs";
|
|
9
|
-
import { useShownNameWarning } from "
|
|
11
|
+
import { useShownNameWarning } from "../use-name-warning.mjs";
|
|
10
12
|
import { supportsFocusVisibleOption } from "./focus-visible.mjs";
|
|
11
13
|
import { useInterestDismiss } from "./use-interest-dismiss.mjs";
|
|
12
|
-
import { useCallback, useEffectEvent, useLayoutEffect, useRef } from "react";
|
|
13
|
-
//#region src/internal/use-popover-popup.ts
|
|
14
|
+
import { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
|
|
15
|
+
//#region src/internal/overlay/use-popover-popup.ts
|
|
14
16
|
const isDev = process.env.NODE_ENV !== "production";
|
|
15
17
|
/** The popup roles that require a name (a listbox's name is checked on the List). */
|
|
16
18
|
function needsName(element) {
|
|
@@ -31,15 +33,14 @@ function insideHiddenPopover(element) {
|
|
|
31
33
|
*/
|
|
32
34
|
function usePopoverPopup(ctx, options) {
|
|
33
35
|
const { part, initialFocus, transition } = options;
|
|
36
|
+
const staticFocus = typeof initialFocus === "function" ? void 0 : initialFocus;
|
|
34
37
|
const isLibrary = ctx.mode === "library";
|
|
35
38
|
const hasTransition = transition !== void 0;
|
|
36
39
|
const { popupRef, triggerRef, setShown } = ctx;
|
|
37
40
|
const opening = useRef(false);
|
|
38
41
|
const reshowing = useRef(false);
|
|
39
|
-
const
|
|
40
|
-
const libraryHide = useRef(false);
|
|
42
|
+
const [flags] = useState(createPopupFlags);
|
|
41
43
|
const focusWasInside = useRef(false);
|
|
42
|
-
const refusedFact = useRef(false);
|
|
43
44
|
const initialFocusTarget = useInitialFocusTarget(part, "popup");
|
|
44
45
|
const interest = useInterestDismiss(ctx);
|
|
45
46
|
const stopWhileShown = useRef(null);
|
|
@@ -55,9 +56,9 @@ function usePopoverPopup(ctx, options) {
|
|
|
55
56
|
};
|
|
56
57
|
const returnFocus = (element) => returnFocusToTrigger(element, triggerRef.current, (trigger) => !insideHiddenPopover(trigger));
|
|
57
58
|
const resolveFocusTarget = (element) => {
|
|
58
|
-
if (
|
|
59
|
-
const resolved =
|
|
60
|
-
if (resolved
|
|
59
|
+
if (typeof initialFocus === "function") {
|
|
60
|
+
const resolved = initialFocus(element);
|
|
61
|
+
if (resolved == null) return null;
|
|
61
62
|
const target = resolved instanceof HTMLElement ? resolved : resolved.element;
|
|
62
63
|
if (!element.contains(target)) return null;
|
|
63
64
|
return {
|
|
@@ -65,26 +66,28 @@ function usePopoverPopup(ctx, options) {
|
|
|
65
66
|
quiet: !(resolved instanceof HTMLElement) && supportsFocusVisibleOption(element.ownerDocument)
|
|
66
67
|
};
|
|
67
68
|
}
|
|
68
|
-
const target = initialFocusTarget(element,
|
|
69
|
+
const target = initialFocusTarget(element, staticFocus);
|
|
69
70
|
return target === null ? null : {
|
|
70
71
|
target,
|
|
71
72
|
quiet: false
|
|
72
73
|
};
|
|
73
74
|
};
|
|
74
75
|
const showPopup = (element) => {
|
|
75
|
-
const refused =
|
|
76
|
-
refusedFact.current = false;
|
|
76
|
+
const refused = flags.takeRefusedFact();
|
|
77
77
|
const focus = refused ? null : resolveFocusTarget(element);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
showWithFocus(element, {
|
|
79
|
+
refused,
|
|
80
|
+
autofocus: focus !== null && !focus.quiet ? focus.target : null,
|
|
81
|
+
show: () => {
|
|
82
|
+
opening.current = true;
|
|
83
|
+
try {
|
|
84
|
+
const source = options.source !== void 0 ? options.source() : triggerRef.current;
|
|
85
|
+
withCssTransitionCut(element, hasTransition, () => element.showPopover(source != null && source.isConnected ? { source } : void 0));
|
|
86
|
+
} finally {
|
|
87
|
+
opening.current = false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
88
91
|
if (focus?.quiet === true && isPopoverOpen(element) && element.contains(focus.target)) focus.target.focus({ focusVisible: false });
|
|
89
92
|
};
|
|
90
93
|
const reshow = () => {
|
|
@@ -99,7 +102,7 @@ function usePopoverPopup(ctx, options) {
|
|
|
99
102
|
} finally {
|
|
100
103
|
reshowing.current = false;
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
flags.endClose();
|
|
103
106
|
focusWasInside.current = false;
|
|
104
107
|
return isPopoverOpen(element);
|
|
105
108
|
};
|
|
@@ -115,24 +118,16 @@ function usePopoverPopup(ctx, options) {
|
|
|
115
118
|
useLayoutEffect(() => {
|
|
116
119
|
reconcileOnMount();
|
|
117
120
|
}, []);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
} else if (!ctx.committed && shown) {
|
|
128
|
-
ctx.recordCloseIntent(void 0);
|
|
129
|
-
libraryHide.current = true;
|
|
130
|
-
withCssTransitionCut(element, hasTransition, () => element.hidePopover());
|
|
131
|
-
if (focusWasInside.current) returnFocus(element);
|
|
132
|
-
}
|
|
121
|
+
useApplyOpenState(ctx, {
|
|
122
|
+
flags,
|
|
123
|
+
exit,
|
|
124
|
+
probe: contentProbe,
|
|
125
|
+
isShown: isPopoverOpen,
|
|
126
|
+
show: showPopup,
|
|
127
|
+
hide: (element) => {
|
|
128
|
+
withCssTransitionCut(element, hasTransition, () => element.hidePopover());
|
|
129
|
+
if (focusWasInside.current) returnFocus(element);
|
|
133
130
|
}
|
|
134
|
-
if (ctx.committed && isPopoverOpen(element)) contentProbe.forget();
|
|
135
|
-
exit.releaseIfIdle(ctx.committed, awaitingClose.current, isPopoverOpen(element));
|
|
136
131
|
});
|
|
137
132
|
const onBeforeToggle = (event) => {
|
|
138
133
|
const element = popupRef.current;
|
|
@@ -150,36 +145,47 @@ function usePopoverPopup(ctx, options) {
|
|
|
150
145
|
reason: "activate",
|
|
151
146
|
event
|
|
152
147
|
}, { unlessRecorded: true });
|
|
153
|
-
|
|
148
|
+
flags.beginClose();
|
|
154
149
|
exit.recordBaseline(element);
|
|
155
150
|
const active = element.ownerDocument.activeElement;
|
|
156
151
|
focusWasInside.current = active !== null && element.contains(active) || contentProbe.hadFocus();
|
|
157
152
|
contentProbe.forget();
|
|
158
153
|
}
|
|
159
154
|
};
|
|
155
|
+
const handleHidden = (element, event, echo, lostInterest) => {
|
|
156
|
+
interest.noteClosed();
|
|
157
|
+
const wasInside = focusWasInside.current;
|
|
158
|
+
focusWasInside.current = false;
|
|
159
|
+
if (wasInside && !lostInterest) returnFocus(element);
|
|
160
|
+
const intent = ctx.takeCloseIntent();
|
|
161
|
+
if (isLibrary) {
|
|
162
|
+
exit.afterClose(element, echo);
|
|
163
|
+
if (!echo) {
|
|
164
|
+
flags.markFact();
|
|
165
|
+
ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? "dismiss");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const replayLostHide = (element) => {
|
|
170
|
+
flags.endClose();
|
|
171
|
+
handleHidden(element, void 0, false, false);
|
|
172
|
+
};
|
|
173
|
+
const mounted = useRef(false);
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
mounted.current = true;
|
|
176
|
+
return () => {
|
|
177
|
+
mounted.current = false;
|
|
178
|
+
};
|
|
179
|
+
}, []);
|
|
160
180
|
const onToggle = (event) => {
|
|
161
181
|
const element = popupRef.current;
|
|
162
182
|
if (element === null || event.target !== element) return;
|
|
163
|
-
|
|
164
|
-
const echo =
|
|
165
|
-
libraryHide.current = false;
|
|
183
|
+
flags.endClose();
|
|
184
|
+
const echo = flags.takeLibraryClose();
|
|
166
185
|
const lostInterest = interest.takeLostInterest();
|
|
167
186
|
if (isLibrary) setShown(isPopoverOpen(element));
|
|
168
187
|
else syncOpen(element);
|
|
169
|
-
if (!isPopoverOpen(element))
|
|
170
|
-
interest.noteClosed();
|
|
171
|
-
const wasInside = focusWasInside.current;
|
|
172
|
-
focusWasInside.current = false;
|
|
173
|
-
if (wasInside && !lostInterest) returnFocus(element);
|
|
174
|
-
const intent = ctx.takeCloseIntent();
|
|
175
|
-
if (isLibrary) {
|
|
176
|
-
exit.afterClose(element, echo);
|
|
177
|
-
if (!echo) {
|
|
178
|
-
refusedFact.current = true;
|
|
179
|
-
ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? "dismiss");
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
188
|
+
if (!isPopoverOpen(element)) handleHidden(element, event, echo, lostInterest);
|
|
183
189
|
const { newState } = event;
|
|
184
190
|
if (newState === "open" && isPopoverOpen(element)) stopWhileShown.current ??= options.whileShown?.(element) ?? null;
|
|
185
191
|
else if (newState === "closed") stopListeningWhileShown();
|
|
@@ -197,6 +203,7 @@ function usePopoverPopup(ctx, options) {
|
|
|
197
203
|
onBeforeToggle,
|
|
198
204
|
onToggle,
|
|
199
205
|
onCommand,
|
|
206
|
+
replayLostHide,
|
|
200
207
|
onInterest: interest.onInterest,
|
|
201
208
|
onLoseInterest: interest.onLoseInterest
|
|
202
209
|
});
|
|
@@ -206,6 +213,9 @@ function usePopoverPopup(ctx, options) {
|
|
|
206
213
|
const setElement = useCallback((element) => {
|
|
207
214
|
checkElement?.(element);
|
|
208
215
|
popupRef.current = element;
|
|
216
|
+
flags.attach(element, (lost) => {
|
|
217
|
+
if (mounted.current) handlers.current.replayLostHide(lost);
|
|
218
|
+
});
|
|
209
219
|
const listeners = [
|
|
210
220
|
["beforetoggle", (event) => handlers.current.onBeforeToggle(event)],
|
|
211
221
|
["toggle", (event) => handlers.current.onToggle(event)],
|
|
@@ -217,8 +227,8 @@ function usePopoverPopup(ctx, options) {
|
|
|
217
227
|
if (isLibrary) setShown(isPopoverOpen(element));
|
|
218
228
|
if (isPopoverOpen(element)) stopWhileShown.current ??= latestWhileShown.current?.(element) ?? null;
|
|
219
229
|
let autofocused = null;
|
|
220
|
-
if (!isLibrary &&
|
|
221
|
-
const target = resolveInitialFocus(element,
|
|
230
|
+
if (!isLibrary && staticFocus !== void 0) {
|
|
231
|
+
const target = resolveInitialFocus(element, staticFocus);
|
|
222
232
|
if (target !== null && element.contains(target) && !target.hasAttribute("autofocus")) {
|
|
223
233
|
target.setAttribute("autofocus", "");
|
|
224
234
|
autofocused = target;
|
|
@@ -235,11 +245,12 @@ function usePopoverPopup(ctx, options) {
|
|
|
235
245
|
}, [
|
|
236
246
|
checkElement,
|
|
237
247
|
popupRef,
|
|
248
|
+
flags,
|
|
238
249
|
setShown,
|
|
239
250
|
handlers,
|
|
240
251
|
latestWhileShown,
|
|
241
252
|
isLibrary,
|
|
242
|
-
|
|
253
|
+
staticFocus,
|
|
243
254
|
resetInterest
|
|
244
255
|
]);
|
|
245
256
|
useShownNameWarning(popupRef, !isLibrary || ctx.committed, isDev && `${part}: the popup has no accessible name. Render a Title, or give the Popup an \`aria-label\`.`, needsName);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-popover-popup.mjs","names":[],"sources":["../../../src/internal/overlay/use-popover-popup.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from \"react\";\nimport type { ReactNode, RefObject, ViewTransitionClass } from \"react\";\nimport { useContentFocusProbe } from \"./content-focus-probe.js\";\nimport { withCssTransitionCut } from \"./css-transition-cut.js\";\nimport { closedByPopoverTarget } from \"./invokers.js\";\nimport { supportsFocusVisibleOption } from \"./focus-visible.js\";\nimport type { QuietFocusTarget } from \"./focus-visible.js\";\nimport {\n commandOf,\n renderOverlayContent,\n resolveInitialFocus,\n returnFocusToTrigger,\n useCloseHold,\n useInitialFocusTarget,\n} from \"./overlay-popup.js\";\nimport { createPopupFlags, showWithFocus } from \"./overlay-show.js\";\nimport { useApplyOpenState } from \"./use-apply-open-state.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { useInterestDismiss } from \"./use-interest-dismiss.js\";\nimport { useLatest } from \"../use-latest.js\";\nimport { useShownNameWarning } from \"../use-name-warning.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nexport interface UsePopoverPopupOptions {\n /** Public name of the part for development warnings (`\"Popover.Popup\"`). */\n readonly part: string;\n /**\n * Element to focus on open (design 6.1): a ref, or a selector resolved inside the popup (the\n * consumer's `initialFocus`, also written as `autofocus` in JS-free mode); or a function called\n * right before each library open (Menu: the first or last item by open cause; Combobox: none).\n * The function's `null` leaves the choice to the platform, and a `QuietFocusTarget` asks for\n * focus without the focus ring (a pointer-opened menu).\n */\n readonly initialFocus?:\n | RefObject<HTMLElement | null>\n | string\n | ((popup: HTMLElement) => HTMLElement | QuietFocusTarget | null)\n | undefined;\n /** The consumer's `keepMounted`: `renderContent` keeps the children in an `<Activity>`. */\n readonly keepMounted?: boolean | undefined;\n /** The consumer's `transition`; decides how a library-driven close keeps its content (4.4). */\n readonly transition: ViewTransitionClass | undefined;\n /**\n * Installs listeners that live while the popup is shown (Menu: the outside right-click\n * listeners; Menu and Combobox: the foreign invoker press guard) and returns their cleanup.\n * Called at the `toggle` that finds the popup shown, and again when the ref attaches to a\n * shown popup; the cleanup runs at the `toggle` of the close and when the element detaches.\n */\n readonly whileShown?: ((popup: HTMLElement) => () => void) | undefined;\n /**\n * The `source` of each library `showPopover({ source })`, read right before the call. Default:\n * the registered Trigger. Menu passes the ContextTrigger region for a point open\n * (design/components/context-menu.md 14).\n */\n readonly source?: () => HTMLElement | null;\n}\n\nexport interface PopoverPopupHook {\n /** Callback ref for the popup element; pass as `useRender`'s `ref`. */\n readonly setElement: (element: HTMLElement) => () => void;\n /**\n * Whether the children are shown: committed open, or held while the hide animates (4.4).\n * Library mode only; JS-free mode always renders them.\n */\n readonly visible: boolean;\n /**\n * The popup's children by mode, `visible` and `keepMounted` (`renderOverlayContent`), inside\n * the focus probe: when a close commit unmounts the content while it holds focus (a\n * library-driven close with `transition`), the hide that follows returns focus to the Trigger\n * (design 6.2).\n */\n readonly renderContent: (children: () => ReactNode) => ReactNode;\n /**\n * Re-shows a shown popup in place (`hidePopover()` + `showPopover({ source })` under the\n * opening flag, initial focus resolved again): Menu's move to a new point\n * (design/components/context-menu.md 4.3). The platform coalesces the two toggles into one\n * `toggle` (`open` to `open`), so nothing is dispatched. No-op (`false`) when the popup is not\n * shown.\n */\n readonly reshow: () => boolean;\n}\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/** The popup roles that require a name (a listbox's name is checked on the List). */\nfunction needsName(element: Element): boolean {\n const role = element.getAttribute(\"role\");\n return role === \"dialog\" || role === \"alertdialog\" || role === \"menu\";\n}\n\n/** Whether `element` sits inside a popover that is not shown (an outer popup that closed). */\nfunction insideHiddenPopover(element: Element): boolean {\n for (let node = element.parentElement; node !== null; node = node.parentElement) {\n if (node.hasAttribute(\"popover\") && !isPopoverOpen(node)) return true;\n }\n return false;\n}\n\n/**\n * Everything in a popover-like Popup except rendering (design/components/popover.md 14.2): mount\n * reconciliation, the apply effect, the native `beforetoggle` / `toggle` / `command` listeners\n * (and `interest` / `loseinterest`), close intents, the focus-return fallback, the JS-free\n * `data-open` sync, the deferred unmount while a hide animates, and `initialFocus`. Shared by\n * Popover, Menu and Combobox.\n */\nexport function usePopoverPopup(\n ctx: PopoverRootValue,\n options: UsePopoverPopupOptions,\n): PopoverPopupHook {\n const { part, initialFocus, transition } = options;\n // The consumer's ref or selector; a resolver function is read at each open only.\n const staticFocus = typeof initialFocus === \"function\" ? undefined : initialFocus;\n const isLibrary = ctx.mode === \"library\";\n // The library's own shows and hides cut the popup's CSS transitions while a view transition\n // runs (conventions 5.1).\n const hasTransition = transition !== undefined;\n const { popupRef, triggerRef, setShown } = ctx;\n\n // The opening `beforetoggle` lets this one through: the library's own `showPopover()`.\n const opening = useRef(false);\n // Set across `reshow()`: the show is not a new open.\n const reshowing = useRef(false);\n // `awaitingClose` (design 2.5), the library echo `libraryHide` (conventions 3.9.2) and\n // `refusedFact` (3.9.4; #155: otherwise Tab and Escape could never leave a menu whose parent\n // keeps `open={true}`), as Dialog's.\n const [flags] = useState(createPopupFlags);\n // Whether focus was inside the popup when its last close began (design 6.2 rule 1).\n const focusWasInside = useRef(false);\n const initialFocusTarget = useInitialFocusTarget(part, \"popup\");\n // `interestfor` (library mode, popover.md lost-interest amendment).\n const interest = useInterestDismiss(ctx);\n // The cleanup of `whileShown` while the popup is shown.\n const stopWhileShown = useRef<(() => void) | null>(null);\n const stopListeningWhileShown = (): void => {\n stopWhileShown.current?.();\n stopWhileShown.current = null;\n };\n\n // `held`: children stay mounted while the hide animates (design 4.4).\n const exit = useCloseHold(ctx.committed, isLibrary, transition);\n\n // Whether the content unmounted while holding focus since the popup was last shown.\n const contentProbe = useContentFocusProbe(popupRef);\n const { wrapContent } = contentProbe;\n\n const syncOpen = (element: HTMLElement): void => {\n // JS-free mode only (design 9): read the DOM, not `newState`, so a stale task cannot\n // lie.\n triggerRef.current?.toggleAttribute(\"data-open\", isPopoverOpen(element));\n };\n\n // Design 6.2 rule 2, for a close that began with focus inside; not to a Trigger inside a\n // hidden popover.\n const returnFocus = (element: HTMLElement): void =>\n returnFocusToTrigger(element, triggerRef.current, (trigger) => !insideHiddenPopover(trigger));\n\n // --- Opening ------------------------------------------------------------------------------\n\n // The initial focus target inside the popup, and whether it is focused without the focus ring.\n const resolveFocusTarget = (\n element: HTMLElement,\n ): { readonly target: HTMLElement; readonly quiet: boolean } | null => {\n if (typeof initialFocus === \"function\") {\n const resolved = initialFocus(element);\n // `== null`: a resolver that returns `undefined` leaves the choice to the platform too.\n if (resolved == null) return null;\n const target = resolved instanceof HTMLElement ? resolved : resolved.element;\n if (!element.contains(target)) return null;\n // A pointer open asks for no focus ring: `focus({ focusVisible: false })` after the show,\n // where the engine reads that option (QuietFocusTarget).\n const quiet =\n !(resolved instanceof HTMLElement) && supportsFocusVisibleOption(element.ownerDocument);\n return { target, quiet };\n }\n const target = initialFocusTarget(element, staticFocus);\n return target === null ? null : { target, quiet: false };\n };\n\n const showPopup = (element: HTMLElement): void => {\n // A refused re-open never moves focus (#155, #156): no initial focus target, and the popup is\n // `inert` for the call (showWithFocus), whether the focusing steps are the dialog focusing\n // steps of a `<dialog>` (Popover's default) or a consumer's own `autofocus` in any popup.\n const refused = flags.takeRefusedFact();\n const focus = refused ? null : resolveFocusTarget(element);\n // Otherwise the popover focusing steps honour `autofocus` (and run the dialog focusing steps\n // for a <dialog>, in every engine). Never `.focus()` (6.1) except for the quiet target above.\n showWithFocus(element, {\n refused,\n autofocus: focus !== null && !focus.quiet ? focus.target : null,\n show: () => {\n opening.current = true;\n try {\n const source = options.source !== undefined ? options.source() : triggerRef.current;\n withCssTransitionCut(element, hasTransition, () =>\n element.showPopover(source != null && source.isConnected ? { source } : undefined),\n );\n } finally {\n opening.current = false;\n }\n },\n });\n if (focus?.quiet === true && isPopoverOpen(element) && element.contains(focus.target)) {\n focus.target.focus({ focusVisible: false } as FocusOptions);\n }\n };\n\n const reshow = (): boolean => {\n const element = popupRef.current;\n if (!isLibrary || element === null || !isPopoverOpen(element)) return false;\n // The hide half's `beforetoggle` records `awaitingClose` / `focusWasInside`; the coalesced\n // `toggle` finds the popup open again, so it clears `awaitingClose`, returns no focus and\n // notifies nothing. The show half runs under `showPopup`'s opening flag (conventions 3.5, the\n // move); the hide half needs none, only an opening `beforetoggle` reads it.\n reshowing.current = true;\n try {\n // One cut around both halves (the show's own cut, nested, does nothing).\n withCssTransitionCut(element, hasTransition, () => {\n element.hidePopover();\n showPopup(element);\n });\n } finally {\n reshowing.current = false;\n }\n // Whether or not the engine fires the coalesced `toggle`, the close bookkeeping of the hide\n // half is void: the popup is open again.\n flags.endClose();\n focusWasInside.current = false;\n return isPopoverOpen(element);\n };\n\n // Mount reconciliation (design 2.4): a click before hydration opened the popover natively.\n // Runs before the apply effect; the dispatch makes the apply effect wait for it.\n const reconcileOnMount = useEffectEvent(() => {\n const element = popupRef.current;\n if (element === null) return;\n if (!isLibrary) {\n syncOpen(element);\n return;\n }\n if (isPopoverOpen(element)) ctx.requestOpen(undefined, \"platform\");\n });\n useLayoutEffect(() => {\n reconcileOnMount();\n }, []);\n\n // The apply effect (design 2.5). Keep this call right after mount reconciliation (as in\n // Dialog.Popup): layout effects run in call order, and at mount the reconciliation's dispatch\n // must come first, so that the first apply sees it in flight and waits.\n useApplyOpenState(ctx, {\n flags,\n exit,\n probe: contentProbe,\n isShown: isPopoverOpen,\n show: showPopup,\n hide: (element) => {\n withCssTransitionCut(element, hasTransition, () => element.hidePopover());\n // The close commit may have unmounted the focused content before the hide: the platform\n // restores focus only from inside the popover, so do it now.\n if (focusWasInside.current) returnFocus(element);\n },\n });\n\n // --- Native listeners (conventions 7.4; filtered on target: React 19.3.1 emulates bubbling\n // of `toggle`, and a nested popover's events reach this element through the real DOM too) ---\n\n const onBeforeToggle = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n const toggle = event as ToggleEvent;\n if (toggle.newState === \"open\") {\n // Every open the library did not start itself is routed through the Root (design 2.2):\n // a foreign `show-popover` / `toggle-popover` invoker, a script `showPopover()`.\n if (isLibrary && !opening.current) {\n event.preventDefault();\n interest.noteOpen(toggle);\n ctx.requestOpen(event, \"activate\");\n } else if (!reshowing.current) {\n // A Close action that resolves after this open must not close it (design 3.4). A re-show\n // (Menu's move) is the same open: an item action pending across it still closes.\n ctx.nextOpenGeneration();\n }\n contentProbe.forget();\n } else {\n // A foreign `popovertarget` invoker closing the popup (design 2.3): `source` is the\n // button, and `null` for Escape, light dismiss and script. The library's own parts never\n // get here with a source (their clicks are cancelled; their closes are `hidePopover()`). A\n // button with `commandfor` as well runs its command, whose intent comes first and stays.\n if (isLibrary && closedByPopoverTarget(toggle, element)) {\n ctx.recordCloseIntent({ reason: \"activate\", event }, { unlessRecorded: true });\n }\n flags.beginClose();\n exit.recordBaseline(element);\n const active = element.ownerDocument.activeElement;\n focusWasInside.current =\n (active !== null && element.contains(active)) || contentProbe.hadFocus();\n contentProbe.forget();\n }\n };\n\n // The work of a `toggle` that finds the popup hidden; also replayed for an element that remounted\n // before its `toggle` (#159; `event` is `undefined` there: no event fired).\n const handleHidden = (\n element: HTMLElement,\n event: Event | undefined,\n echo: boolean,\n lostInterest: boolean,\n ): void => {\n interest.noteClosed();\n // Focus return for what the platform leaves out (design 6.2): a nested popover restores\n // nothing, and an opener that is gone leaves focus inside the hidden popup. Not after a\n // lost-interest hide: the platform never focuses the invoker there, and focusing a Trigger\n // with `interestfor` would give it interest again and re-open the popup.\n const wasInside = focusWasInside.current;\n focusWasInside.current = false;\n if (wasInside && !lostInterest) returnFocus(element);\n\n const intent = ctx.takeCloseIntent();\n if (isLibrary) {\n exit.afterClose(element, echo);\n // Anything but the library's own hide is a fact: committed `false` now (urgent, this\n // event's commit) and `onOpenChange(false)` (conventions 3.9.3).\n if (!echo) {\n flags.markFact();\n ctx.notifyClosed(intent?.event ?? event, intent?.reason ?? \"dismiss\");\n }\n }\n };\n\n // A fact whose element remounted before its `toggle` (#159), in a timer task: the work that\n // `toggle` would have done. The lost element is hidden; its shown mirror and `whileShown` listeners went at detach.\n const replayLostHide = (element: HTMLElement): void => {\n flags.endClose();\n // Echo `false`: only facts are replayed. `lostInterest` `false`: the detach's `interest.reset()`\n // dropped the mark, as `takeLostInterest()` would read now; a lost-interest hide never has\n // focus inside (interest is lost once focus left), so no focus return follows from it.\n handleHidden(element, undefined, false, false);\n };\n\n // Whether the Popup is mounted, for the #159 replay. A passive effect: a Suspense hide detaches\n // the element's ref (and runs layout cleanups) but keeps passive effects, so a hidden Popup\n // still counts as mounted.\n const mounted = useRef(false);\n useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n const onToggle = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element) return;\n flags.endClose();\n // Consumed by every `toggle`, whatever it reports: a hide the engine coalesced with a show\n // must not mark a later dismissal as the library's.\n const echo = flags.takeLibraryClose();\n const lostInterest = interest.takeLostInterest();\n // JS-free mode writes the Trigger's `data-open`; library mode mirrors into the Root, which\n // non-button Triggers and the Combobox Input render as `aria-expanded`.\n if (isLibrary) setShown(isPopoverOpen(element));\n else syncOpen(element);\n\n if (!isPopoverOpen(element)) handleHidden(element, event, echo, lostInterest);\n const { newState } = event as ToggleEvent;\n if (newState === \"open\" && isPopoverOpen(element)) {\n stopWhileShown.current ??= options.whileShown?.(element) ?? null;\n } else if (newState === \"closed\") {\n stopListeningWhileShown();\n }\n };\n\n const onCommand = (event: Event): void => {\n const element = popupRef.current;\n if (element === null || event.target !== element || event.defaultPrevented) return;\n const command = commandOf(event);\n // A foreign `commandfor` invoker closing the popup (design 2.3). Opens are caught at\n // `beforetoggle`.\n // The `command` event fires whatever the popover's state (HTML): a `hide-popover` at a\n // hidden popup closes nothing and must leave no intent for a later close.\n if ((command === \"hide-popover\" || command === \"toggle-popover\") && isPopoverOpen(element)) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n }\n };\n\n // The listeners the callback ref attaches call the latest render's handlers. An insertion\n // effect publishes them before refs attach and before any layout effect (whose\n // `hidePopover()` dispatches `beforetoggle` synchronously).\n const handlers = useLatest({\n onBeforeToggle,\n onToggle,\n onCommand,\n replayLostHide,\n onInterest: interest.onInterest,\n onLoseInterest: interest.onLoseInterest,\n });\n const latestWhileShown = useLatest(options.whileShown);\n\n // --- Element ------------------------------------------------------------------------------\n\n // The listeners attach in the callback ref, so they are in place from the commit that mounts\n // the element (no passive-effect window, no extra render). JS-free mode: there is no \"right\n // before showPopover()\" (the browser runs the command), so the `autofocus` attribute stays on\n // the `initialFocus` target while it is mounted (as Dialog).\n const checkElement = useElementCheck(\n isDev &&\n ((element) =>\n element.tagName !== \"DIALOG\" && element.tagName !== \"DIV\"\n ? `${part}: expected to render a <dialog> or a <div> but got ` +\n `<${element.tagName.toLowerCase()}>.`\n : null),\n );\n const resetInterest = interest.reset;\n const setElement = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n popupRef.current = element;\n // A new element (a remount mid-hide): the old one's `toggle` never comes (#159). A lost\n // fact is replayed a timer task later, unless the Popup unmounted meanwhile; also while a\n // Suspense boundary hides it (the fact happened before the hide).\n flags.attach(element, (lost) => {\n if (mounted.current) handlers.current.replayLostHide(lost as HTMLElement);\n });\n const listeners: [string, EventListener][] = [\n [\"beforetoggle\", (event) => handlers.current.onBeforeToggle(event)],\n [\"toggle\", (event) => handlers.current.onToggle(event)],\n [\"command\", (event) => handlers.current.onCommand(event)],\n // Fired only where `interestfor` exists (Chromium).\n [\"interest\", (event) => handlers.current.onInterest(event)],\n [\"loseinterest\", (event) => handlers.current.onLoseInterest(event)],\n ];\n for (const [type, listener] of listeners) element.addEventListener(type, listener);\n // A pre-hydration open is shown from the first commit; a popup removed while open fires no\n // `toggle`, so the detach clears the mirror.\n if (isLibrary) setShown(isPopoverOpen(element));\n // The ref re-runs whenever the merged ref changes (an inline consumer `ref`), and its detach\n // stopped the listeners: a popup that is still shown gets them back, as no `toggle` comes.\n if (isPopoverOpen(element)) {\n stopWhileShown.current ??= latestWhileShown.current?.(element) ?? null;\n }\n\n let autofocused: HTMLElement | null = null;\n if (!isLibrary && staticFocus !== undefined) {\n const target = resolveInitialFocus(element, staticFocus);\n if (target !== null && element.contains(target) && !target.hasAttribute(\"autofocus\")) {\n target.setAttribute(\"autofocus\", \"\");\n autofocused = target;\n }\n }\n\n return () => {\n for (const [type, listener] of listeners) element.removeEventListener(type, listener);\n resetInterest();\n stopListeningWhileShown();\n if (isLibrary) setShown(false);\n autofocused?.removeAttribute(\"autofocus\");\n if (popupRef.current === element) popupRef.current = null;\n };\n },\n [\n checkElement,\n popupRef,\n flags,\n setShown,\n handlers,\n latestWhileShown,\n isLibrary,\n staticFocus,\n resetInterest,\n ],\n );\n\n // Development check (design 9): a `dialog`, `alertdialog` or `menu` role needs a name once the\n // popup is (or can be) shown.\n useShownNameWarning(\n popupRef,\n !isLibrary || ctx.committed,\n isDev &&\n `${part}: the popup has no accessible name. Render a Title, or give the Popup an ` +\n \"`aria-label`.\",\n needsName,\n );\n\n const visible = ctx.committed || exit.held;\n const renderContent = (children: () => ReactNode): ReactNode =>\n renderOverlayContent(\n { isLibrary, keepMounted: options.keepMounted, visible, wrapContent },\n children,\n );\n return { setElement, visible, renderContent, reshow };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAoFA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;AAGvC,SAAS,UAAU,SAA2B;CAC5C,MAAM,OAAO,QAAQ,aAAa,MAAM;CACxC,OAAO,SAAS,YAAY,SAAS,iBAAiB,SAAS;AACjE;;AAGA,SAAS,oBAAoB,SAA2B;CACtD,KAAK,IAAI,OAAO,QAAQ,eAAe,SAAS,MAAM,OAAO,KAAK,eAChE,IAAI,KAAK,aAAa,SAAS,KAAK,CAAC,cAAc,IAAI,GAAG,OAAO;CAEnE,OAAO;AACT;;;;;;;;AASA,SAAgB,gBACd,KACA,SACkB;CAClB,MAAM,EAAE,MAAM,cAAc,eAAe;CAE3C,MAAM,cAAc,OAAO,iBAAiB,aAAa,KAAA,IAAY;CACrE,MAAM,YAAY,IAAI,SAAS;CAG/B,MAAM,gBAAgB,eAAe,KAAA;CACrC,MAAM,EAAE,UAAU,YAAY,aAAa;CAG3C,MAAM,UAAU,OAAO,KAAK;CAE5B,MAAM,YAAY,OAAO,KAAK;CAI9B,MAAM,CAAC,SAAS,SAAS,gBAAgB;CAEzC,MAAM,iBAAiB,OAAO,KAAK;CACnC,MAAM,qBAAqB,sBAAsB,MAAM,OAAO;CAE9D,MAAM,WAAW,mBAAmB,GAAG;CAEvC,MAAM,iBAAiB,OAA4B,IAAI;CACvD,MAAM,gCAAsC;EAC1C,eAAe,UAAU;EACzB,eAAe,UAAU;CAC3B;CAGA,MAAM,OAAO,aAAa,IAAI,WAAW,WAAW,UAAU;CAG9D,MAAM,eAAe,qBAAqB,Q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AAO,aAAa,WAAW,GAAG;IACpF,OAAO,aAAa,aAAa,EAAE;IACnC,cAAc;GAChB;EACF;EAEA,aAAa;GACX,KAAK,MAAM,CAAC,MAAM,aAAa,WAAW,QAAQ,oBAAoB,MAAM,QAAQ;GACpF,cAAc;GACd,wBAAwB;GACxB,IAAI,WAAW,SAAS,KAAK;GAC7B,aAAa,gBAAgB,WAAW;GACxC,IAAI,SAAS,YAAY,SAAS,SAAS,UAAU;EACvD;CACF,GACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;CAIA,oBACE,UACA,CAAC,aAAa,IAAI,WAClB,SACE,GAAG,KAAK,2FAEV,SACF;CAEA,MAAM,UAAU,IAAI,aAAa,KAAK;CACtC,MAAM,iBAAiB,aACrB,qBACE;EAAE;EAAW,aAAa,QAAQ;EAAa;EAAS;CAAY,GACpE,QACF;CACF,OAAO;EAAE;EAAY;EAAS;EAAe;CAAO;AACtD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
1
|
+
import "../types.mjs";
|
|
2
|
+
import "../use-render.mjs";
|
|
3
3
|
import "./use-overlay-root.mjs";
|
|
4
4
|
import { ComponentPropsWithRef } from "react";
|
|
5
|
-
//#region src/internal/use-popover-trigger.d.ts
|
|
5
|
+
//#region src/internal/overlay/use-popover-trigger.d.ts
|
|
6
6
|
/** The state of an overlay Trigger (Popover.Trigger, Menu.Trigger and its siblings). */
|
|
7
7
|
export interface PopoverTriggerHookState {
|
|
8
8
|
/** Optimistic open state. A Popover in JS-free mode (the browser owns it) reports `false`. */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-popover-trigger.d.mts","names":[],"sources":["../../../src/internal/overlay/use-popover-trigger.ts"],"mappings":";;;;;;iBA8EiB;;WAEN;;WAEA;;WAEA"}
|
|
@@ -1,13 +1,43 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { dataAttr } from "
|
|
3
|
-
import { disabledButton, rendersButton } from "
|
|
4
|
-
import { useElementCheck } from "
|
|
2
|
+
import { dataAttr } from "../data-attr.mjs";
|
|
3
|
+
import { cancelClick, disabledButton, rendersButton } from "../render-element.mjs";
|
|
4
|
+
import { useElementCheck } from "../use-element-check.mjs";
|
|
5
5
|
import { isPopoverOpen } from "./popover-open.mjs";
|
|
6
6
|
import { registerTrigger } from "./trigger-ref.mjs";
|
|
7
7
|
import { useCallback } from "react";
|
|
8
|
-
//#region src/internal/use-popover-trigger.ts
|
|
8
|
+
//#region src/internal/overlay/use-popover-trigger.ts
|
|
9
9
|
const isDev = process.env.NODE_ENV !== "production";
|
|
10
10
|
/**
|
|
11
|
+
* The click rule of a Trigger that toggles a popover-kind Root (popover.md 2.8): Popover.Trigger,
|
|
12
|
+
* Menu.Trigger, Menu.SubmenuTrigger (through `usePopoverTrigger`) and Combobox.Trigger. It toggles
|
|
13
|
+
* against what the user already intends (`intended()`, conventions 3.8 rule 1), not the DOM:
|
|
14
|
+
*
|
|
15
|
+
* - intended open, and the browser already hid the popup (a non-button Trigger, #115: light
|
|
16
|
+
* dismiss hid it at `pointerup`, before this click): the hide is a fact, reported by its pending
|
|
17
|
+
* `toggle`; the click only names its cause, an `"activate"` close intent;
|
|
18
|
+
* - intended open otherwise: `requestClose(event, "activate")`;
|
|
19
|
+
* - intended closed: `beforeOpen()`, then `requestOpen(event, "activate")`. First, because what
|
|
20
|
+
* it records (Menu's open cause) must be in place before anything can show the popup. Today the
|
|
21
|
+
* show waits for the apply effect, so the order is not observable.
|
|
22
|
+
*
|
|
23
|
+
* The caller cancels the click and checks `disabled` first. Handlers only.
|
|
24
|
+
*/
|
|
25
|
+
function toggleFromTrigger(ctx, event, beforeOpen) {
|
|
26
|
+
if (ctx.intended()) {
|
|
27
|
+
if (ctx.hiddenBeforeToggle()) {
|
|
28
|
+
ctx.recordCloseIntent({
|
|
29
|
+
reason: "activate",
|
|
30
|
+
event
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
ctx.requestClose(event, "activate");
|
|
35
|
+
} else {
|
|
36
|
+
beforeOpen?.();
|
|
37
|
+
ctx.requestOpen(event, "activate");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
11
41
|
* Owned and never written on an overlay Trigger (Popover, Menu, Combobox): the default
|
|
12
42
|
* `popovertarget` action, which a render element must not change, and an Invoker Command, which
|
|
13
43
|
* would take precedence over `popovertarget` and act on another element.
|
|
@@ -38,7 +68,7 @@ function nonInvokerMessage(part, tag, popover, popup) {
|
|
|
38
68
|
* Menu adds `aria-haspopup="menu"` and its own key handling on top.
|
|
39
69
|
*/
|
|
40
70
|
function usePopoverTrigger(ctx, options) {
|
|
41
|
-
const { part, disabled, render, handlers,
|
|
71
|
+
const { part, disabled, render, handlers, onActivate, submenuItem = false } = options;
|
|
42
72
|
const isLibrary = ctx.mode === "library";
|
|
43
73
|
const { ids, triggerRef, popupRef } = ctx;
|
|
44
74
|
const state = {
|
|
@@ -49,7 +79,7 @@ function usePopoverTrigger(ctx, options) {
|
|
|
49
79
|
const checkElement = useElementCheck(isDev && ((element) => {
|
|
50
80
|
if (element.tagName === "BUTTON") return null;
|
|
51
81
|
const tag = element.tagName.toLowerCase();
|
|
52
|
-
if (isLibrary &&
|
|
82
|
+
if (isLibrary && submenuItem) return `${part}: rendered a <${tag}>. Only a <button> is the popover's invoker: a press on this element while its popup is open dismisses the popup through light dismiss instead of moving focus into it. Render a <button>.`;
|
|
53
83
|
return isLibrary ? nonInvokerMessage(part, tag, "popover", "popup") : `${part}: rendered a <${tag}> in JS-free mode. Only a <button> is a \`popovertarget\` invoker; this trigger will not open the popover. Render a <button>, or put the component in library mode (\`defaultOpen={false}\`).`;
|
|
54
84
|
}));
|
|
55
85
|
const ref = useCallback((element) => {
|
|
@@ -67,24 +97,8 @@ function usePopoverTrigger(ctx, options) {
|
|
|
67
97
|
const onClick = (event) => {
|
|
68
98
|
event.preventDefault();
|
|
69
99
|
if (disabled) return;
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const native = event.nativeEvent;
|
|
75
|
-
if (ctx.intended()) {
|
|
76
|
-
if (ctx.hiddenBeforeToggle()) {
|
|
77
|
-
ctx.recordCloseIntent({
|
|
78
|
-
reason: "activate",
|
|
79
|
-
event: native
|
|
80
|
-
});
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
ctx.requestClose(native, "activate");
|
|
84
|
-
} else {
|
|
85
|
-
beforeOpen?.(event);
|
|
86
|
-
ctx.requestOpen(native, "activate");
|
|
87
|
-
}
|
|
100
|
+
if (onActivate !== void 0) onActivate(event);
|
|
101
|
+
else toggleFromTrigger(ctx, event.nativeEvent);
|
|
88
102
|
};
|
|
89
103
|
const merged = { ...handlers };
|
|
90
104
|
if (isLibrary) {
|
|
@@ -96,8 +110,15 @@ function usePopoverTrigger(ctx, options) {
|
|
|
96
110
|
}
|
|
97
111
|
const disabledProps = disabledButton(render, disabled, {
|
|
98
112
|
handlesClick: isLibrary,
|
|
99
|
-
alwaysFocusable:
|
|
113
|
+
alwaysFocusable: submenuItem
|
|
100
114
|
});
|
|
115
|
+
if (!isLibrary && !disabledProps.invoker) {
|
|
116
|
+
const extra = handlers?.onClick;
|
|
117
|
+
merged.onClick = extra === void 0 ? cancelClick : (event) => {
|
|
118
|
+
extra(event);
|
|
119
|
+
cancelClick(event);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
101
122
|
const invoker = disabledProps.invoker && rendersButton(render);
|
|
102
123
|
return {
|
|
103
124
|
state,
|
|
@@ -116,6 +137,6 @@ function usePopoverTrigger(ctx, options) {
|
|
|
116
137
|
};
|
|
117
138
|
}
|
|
118
139
|
//#endregion
|
|
119
|
-
export { RESERVED_INVOKER_KEYS, nonInvokerMessage, usePopoverTrigger };
|
|
140
|
+
export { RESERVED_INVOKER_KEYS, nonInvokerMessage, toggleFromTrigger, usePopoverTrigger };
|
|
120
141
|
|
|
121
142
|
//# sourceMappingURL=use-popover-trigger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-popover-trigger.mjs","names":[],"sources":["../../../src/internal/overlay/use-popover-trigger.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\nimport type { ComponentPropsWithRef, DOMAttributes, MouseEvent } from \"react\";\nimport { dataAttr } from \"../data-attr.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { registerTrigger } from \"./trigger-ref.js\";\nimport type { RenderProp } from \"../types.js\";\nimport { useElementCheck } from \"../use-element-check.js\";\nimport { cancelClick, disabledButton, rendersButton } from \"../use-render.js\";\nimport type { DataAttributes } from \"../use-render.js\";\nimport type { PopoverRootValue } from \"./use-overlay-root.js\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\n\n/**\n * The click rule of a Trigger that toggles a popover-kind Root (popover.md 2.8): Popover.Trigger,\n * Menu.Trigger, Menu.SubmenuTrigger (through `usePopoverTrigger`) and Combobox.Trigger. It toggles\n * against what the user already intends (`intended()`, conventions 3.8 rule 1), not the DOM:\n *\n * - intended open, and the browser already hid the popup (a non-button Trigger, #115: light\n * dismiss hid it at `pointerup`, before this click): the hide is a fact, reported by its pending\n * `toggle`; the click only names its cause, an `\"activate\"` close intent;\n * - intended open otherwise: `requestClose(event, \"activate\")`;\n * - intended closed: `beforeOpen()`, then `requestOpen(event, \"activate\")`. First, because what\n * it records (Menu's open cause) must be in place before anything can show the popup. Today the\n * show waits for the apply effect, so the order is not observable.\n *\n * The caller cancels the click and checks `disabled` first. Handlers only.\n */\nexport function toggleFromTrigger(\n ctx: PopoverRootValue,\n event: Event,\n beforeOpen?: () => void,\n): void {\n if (ctx.intended()) {\n if (ctx.hiddenBeforeToggle()) {\n ctx.recordCloseIntent({ reason: \"activate\", event });\n return;\n }\n ctx.requestClose(event, \"activate\");\n } else {\n beforeOpen?.();\n ctx.requestOpen(event, \"activate\");\n }\n}\n\n/**\n * Owned and never written on an overlay Trigger (Popover, Menu, Combobox): the default\n * `popovertarget` action, which a render element must not change, and an Invoker Command, which\n * would take precedence over `popovertarget` and act on another element.\n */\nexport const RESERVED_INVOKER_KEYS = {\n popoverTargetAction: undefined,\n commandfor: undefined,\n command: undefined,\n} as const;\n\n/**\n * The library-mode dev warning for a Trigger rendered as another element than a `<button>`: only\n * an invoker button is spared by the popover's light dismiss, so a press while the popup is open\n * hides it before the click. `popover` and `popup` are the nouns the text uses for it.\n */\nexport function nonInvokerMessage(\n part: string,\n tag: string,\n popover: string,\n popup: string,\n): string {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the ${popover}'s invoker: a press on ` +\n `this element while the ${popup} is open closes it through light dismiss before the ` +\n \"click, so the close is a dismissal (reported to onOpenChange) rather than a request: \" +\n \"openChangeAction(false) is not called, cannot veto it and there is no view transition. \" +\n \"Render a <button>.\"\n );\n}\n\n/** The state of an overlay Trigger (Popover.Trigger, Menu.Trigger and its siblings). */\nexport interface PopoverTriggerHookState {\n /** Optimistic open state. A Popover in JS-free mode (the browser owns it) reports `false`. */\n readonly open: boolean;\n /** The Root's transition is pending: an open or a part-initiated close (never a dismissal). */\n readonly pending: boolean;\n /** The `disabled` prop. */\n readonly disabled: boolean;\n}\n\n/** Event handlers a component layers onto the Trigger's own (Menu's keys and hover intent). */\nexport type PopoverTriggerHandlers = Pick<\n DOMAttributes<HTMLButtonElement>,\n \"onClick\" | \"onKeyDown\" | \"onMouseDown\" | \"onPointerMove\" | \"onPointerEnter\" | \"onPointerLeave\"\n>;\n\nexport interface UsePopoverTriggerOptions<State> {\n /** Public name of the part for development warnings (`\"Popover.Trigger\"`). */\n readonly part: string;\n readonly disabled: boolean;\n readonly render: RenderProp<ComponentPropsWithRef<\"button\">, State> | undefined;\n /**\n * Extra handlers, merged in front of the Trigger's own: for a key both define, the extra one\n * runs first (the consumer's pass-through handler still runs before both, conventions 1.2).\n */\n readonly handlers?: PopoverTriggerHandlers;\n /**\n * What a click does in library mode, after the command has been cancelled and `disabled`\n * checked. Default: `toggleFromTrigger(ctx, event.nativeEvent)`, the toggle against\n * `intended()` (`requestOpen` / `requestClose`). Menu.Trigger toggles with its open cause;\n * Menu.SubmenuTrigger opens, or moves focus into an already open submenu.\n */\n readonly onActivate?: (event: MouseEvent<HTMLElement>) => void;\n /**\n * Menu.SubmenuTrigger: the Trigger is also an item of the parent menu, whose click\n * (`onActivate`) never closes the popup. `disabled` renders `aria-disabled=\"true\"` and no\n * `disabled` attribute, so the item stays focusable (the click handler still refuses); without\n * it `disabled` is the native attribute, so the button is no invoker at all (in library mode a\n * link or component `render` still gets `aria-disabled`, because native `disabled` means\n * nothing on a link and the installed click handler is what refuses). And the library-mode\n * non-button warning says a press while open dismisses the popup instead of moving focus into\n * it.\n */\n readonly submenuItem?: boolean;\n}\n\nexport interface PopoverTriggerHook {\n readonly state: PopoverTriggerHookState;\n /** Owned props (conventions 1.2) for `useRender`'s `libraryProps`. */\n readonly libraryProps: ComponentPropsWithRef<\"button\"> & DataAttributes;\n /** Registers the element as the Root's Trigger; pass as `useRender`'s `ref`. */\n readonly ref: (element: HTMLElement) => () => void;\n}\n\n/**\n * The Trigger of a popover-like component (design/components/popover.md 14.3):\n * `button[popoverTarget]`, with no `aria-expanded` on an invoker: every engine exposes the\n * popover's shown state from the invoker relationship. In JS-free mode the browser toggles\n * the popover and the Popup keeps `data-open` current on the element. In library mode the click\n * is cancelled (so the activation does not run) and toggles against what the user already\n * intends: an open through `requestOpen`, a library-owned close through `requestClose`. There\n * `data-open` and `state.open` are optimistic; a non-button `render` (no invoker) renders\n * `aria-expanded` from whether the popup is shown (in the top layer).\n *\n * Menu adds `aria-haspopup=\"menu\"` and its own key handling on top.\n */\nexport function usePopoverTrigger<State>(\n ctx: PopoverRootValue,\n options: UsePopoverTriggerOptions<State>,\n): PopoverTriggerHook {\n const { part, disabled, render, handlers, onActivate, submenuItem = false } = options;\n const isLibrary = ctx.mode === \"library\";\n const { ids, triggerRef, popupRef } = ctx;\n\n const state: PopoverTriggerHookState = {\n open: ctx.optimistic,\n // Opens and part-initiated closes belong to the Trigger (4.2); a dismissal is a fact and\n // pends nothing (conventions 3.9.7).\n pending: ctx.pending,\n disabled,\n };\n\n const checkElement = useElementCheck(\n isDev &&\n ((element) => {\n if (element.tagName === \"BUTTON\") return null;\n const tag = element.tagName.toLowerCase();\n // Library mode: the click handler works, but only an invoker button is spared by the\n // popover's light dismiss, so a press while open hides the popup before the click.\n if (isLibrary && submenuItem) {\n return (\n `${part}: rendered a <${tag}>. Only a <button> is the popover's invoker: a press on ` +\n \"this element while its popup is open dismisses the popup through light dismiss \" +\n \"instead of moving focus into it. Render a <button>.\"\n );\n }\n return isLibrary\n ? nonInvokerMessage(part, tag, \"popover\", \"popup\")\n : `${part}: rendered a <${tag}> in JS-free mode. Only a <button> is a ` +\n \"`popovertarget` invoker; this trigger will not open the popover. Render a \" +\n \"<button>, or put the component in library mode (`defaultOpen={false}`).\";\n }),\n );\n const ref = useCallback(\n (element: HTMLElement) => {\n checkElement?.(element);\n const unregister = registerTrigger(triggerRef, element, part);\n // JS-free mode: the DOM owns `data-open` (design 9). A Trigger that mounts after the\n // Popup (or is re-created) picks up the current state here.\n if (!isLibrary && popupRef.current !== null) {\n element.toggleAttribute(\"data-open\", isPopoverOpen(popupRef.current));\n }\n return unregister;\n },\n [isLibrary, checkElement, triggerRef, popupRef, part],\n );\n\n const onClick = (event: MouseEvent<HTMLElement>) => {\n // Cancelling the click cancels the popover toggle (it runs as the button's activation\n // behaviour, only if the click was not cancelled). Enter and Space synthesise the same click.\n event.preventDefault();\n if (disabled) return;\n if (onActivate !== undefined) onActivate(event);\n else toggleFromTrigger(ctx, event.nativeEvent);\n };\n\n // The component's handlers first, then the Trigger's (design/components/menu.md 14). The click\n // handler is only owned when installed, so a render element keeps its own `onClick` in JS-free\n // mode.\n const merged: PopoverTriggerHandlers = { ...handlers };\n if (isLibrary) {\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? onClick\n : (event) => {\n extra(event);\n onClick(event);\n };\n }\n // The click handler is installed in library mode only; in JS-free mode the activation needs\n // native `disabled` to stop it.\n const disabledProps = disabledButton(render, disabled, {\n handlesClick: isLibrary,\n alwaysFocusable: submenuItem,\n });\n if (!isLibrary && !disabledProps.invoker) {\n // JS-free mode, disabled in the `aria-disabled` branch (a host link): nothing native stops the\n // click, so cancel it (a disabled link must not navigate). Only while disabled, after the\n // component's own handler.\n const extra = handlers?.onClick;\n merged.onClick =\n extra === undefined\n ? cancelClick\n : (event) => {\n extra(event);\n cancelClick(event);\n };\n }\n\n const invoker = disabledProps.invoker && rendersButton(render);\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 browser\n // would toggle the popover).\n ...disabledProps.props,\n // Only on a button (or a component, assumed to render one): another element is no invoker,\n // and the attribute would claim otherwise.\n popoverTarget: invoker ? ids.popup : undefined,\n ...RESERVED_INVOKER_KEYS,\n // No `aria-expanded` on an invoker: every engine exposes the popover's shown state from\n // `popovertarget`, and ARIA in HTML forbids the attribute there. Otherwise nothing else\n // exposes the state: library mode renders shown (the popup is in the top layer; `data-open`\n // is the optimistic one), JS-free mode cannot know it and renders \"false\".\n \"aria-expanded\": invoker ? undefined : isLibrary ? ctx.shown : false,\n ...merged,\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 { state, libraryProps, ref };\n}\n"],"mappings":";;;;;;;;AAYA,MAAM,QAAQ,QAAQ,IAAI,aAAa;;;;;;;;;;;;;;;;AAiBvC,SAAgB,kBACd,KACA,OACA,YACM;CACN,IAAI,IAAI,SAAS,GAAG;EAClB,IAAI,IAAI,mBAAmB,GAAG;GAC5B,IAAI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AAW;CAC/C;CAKA,MAAM,SAAiC,EAAE,GAAG,SAAS;CACrD,IAAI,WAAW;EACb,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,WACC,UAAU;GACT,MAAM,KAAK;GACX,QAAQ,KAAK;EACf;CACR;CAGA,MAAM,gBAAgB,eAAe,QAAQ,UAAU;EACrD,cAAc;EACd,iBAAiB;CACnB,CAAC;CACD,IAAI,CAAC,aAAa,CAAC,cAAc,SAAS;EAIxC,MAAM,QAAQ,UAAU;EACxB,OAAO,UACL,UAAU,KAAA,IACN,eACC,UAAU;GACT,MAAM,KAAK;GACX,YAAY,KAAK;EACnB;CACR;CAEA,MAAM,UAAU,cAAc,WAAW,cAAc,MAAM;CAyB7D,OAAO;EAAE;EAAO,cAAA;GArBd,GAAI,cAAc,MAAM,KAAK,EAAE,MAAM,SAAkB;GAGvD,GAAG,cAAc;GAGjB,eAAe,UAAU,IAAI,QAAQ,KAAA;GACrC,GAAG;GAKH,iBAAiB,UAAU,KAAA,IAAY,YAAY,IAAI,QAAQ;GAC/D,GAAG;GACH,aAAa,SAAS,MAAM,IAAI;GAChC,gBAAgB,SAAS,MAAM,OAAO;GAGtC,iBAAiB,SAAS,QAAQ;EAGT;EAAG;CAAI;AACpC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { resolveStateValue } from "
|
|
2
|
+
import { resolveStateValue } from "../render-element.mjs";
|
|
3
3
|
import { POSITION_TRY_FALLBACKS, parsePositionArea, positionArea } from "./anchor-position.mjs";
|
|
4
4
|
import { isPopoverOpen } from "./popover-open.mjs";
|
|
5
5
|
import { useCallback, useLayoutEffect, useRef, useState } from "react";
|
|
6
6
|
import { flushSync } from "react-dom";
|
|
7
|
-
//#region src/internal/use-resolved-placement.ts
|
|
7
|
+
//#region src/internal/overlay/use-resolved-placement.ts
|
|
8
8
|
const toDirection = (value) => value === "rtl" ? "rtl" : "ltr";
|
|
9
9
|
/**
|
|
10
10
|
* Where the browser actually placed an anchored popup (design/conventions.md 13.2): the
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-resolved-placement.mjs","names":[],"sources":["../../../src/internal/overlay/use-resolved-placement.ts"],"sourcesContent":["\"use client\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, RefCallback } from \"react\";\nimport { flushSync } from \"react-dom\";\nimport { parsePositionArea, POSITION_TRY_FALLBACKS, positionArea } from \"./anchor-position.js\";\nimport type {\n AnchorAlign,\n AnchorSide,\n Direction,\n PhysicalSide,\n ResolvedPlacement,\n} from \"./anchor-position.js\";\nimport { isPopoverOpen } from \"./popover-open.js\";\nimport { resolveStateValue } from \"../render-element.js\";\nimport type { DataAttributes } from \"../render-element.js\";\nimport type { StateValue } from \"../types.js\";\n\nexport interface PlacementRequest<Side extends AnchorSide> {\n /** The requested side; `null` when the stylesheet owns placement (the hook is idle). */\n readonly side: Side | null;\n readonly align: AnchorAlign;\n}\n\nexport interface PlacementResult<Side extends AnchorSide> {\n /** The resolved physical side while the popup is shown, else the requested side. */\n readonly side: Side | PhysicalSide | null;\n /** The resolved alignment while shown, else the requested one. */\n readonly align: AnchorAlign;\n /** Merge into the popup element's ref. Stable. */\n readonly ref: RefCallback<HTMLElement>;\n}\n\nconst toDirection = (value: string): Direction => (value === \"rtl\" ? \"rtl\" : \"ltr\");\n\n/**\n * Where the browser actually placed an anchored popup (design/conventions.md 13.2): the\n * `position-try-fallbacks` option it applied, read from the computed `position-area` while the\n * popup is shown. Observation only; runs whatever opened the popup (`interestfor`, `popovertarget` and\n * `commandfor` included). Read on a `ResizeObserver` (hidden to shown is a resize, delivered\n * before paint), `toggle`, and while shown document `scroll` and window `resize` plus the next\n * two frames. Written urgently (`flushSync`), and only when the rendered pair changes: an open\n * where it was asked costs no render. Hidden again, it resets once the popup no longer renders\n * (an exit animation keeps the resolved side). Idle with `side: null`.\n */\nexport function useResolvedPlacement<Side extends AnchorSide>(\n request: PlacementRequest<Side>,\n): PlacementResult<Side> {\n const { side, align } = request;\n const [resolved, setResolved] = useState<ResolvedPlacement | null>(null);\n // What the state holds (or is about to hold), so an unchanged read schedules nothing.\n const written = useRef<ResolvedPlacement | null>(null);\n // The request the element is rendered with (kept by the layout effect below).\n const requested = useRef<PlacementRequest<Side>>(request);\n // The mounted element's read, for the layout effect below.\n const sync = useRef<((urgent: boolean) => void) | null>(null);\n\n const ref = useCallback((element: HTMLElement | null) => {\n if (element === null) return;\n const doc = element.ownerDocument;\n const win = doc.defaultView ?? window;\n\n const write = (value: ResolvedPlacement | null, urgent: boolean) => {\n // Where it was asked to be: the requested values say so already, no state needed.\n const next =\n value !== null &&\n value.side === requested.current.side &&\n value.align === requested.current.align\n ? null\n : value;\n const previous = written.current;\n if (\n previous === next ||\n (previous !== null &&\n next !== null &&\n previous.side === next.side &&\n previous.align === next.align)\n ) {\n return;\n }\n written.current = next;\n if (urgent) flushSync(() => setResolved(next));\n else setResolved(next);\n };\n\n let listening = false;\n const listen = (on: boolean) => {\n if (on === listening) return;\n listening = on;\n if (on) {\n doc.addEventListener(\"scroll\", onMove, { capture: true, passive: true });\n win.addEventListener(\"resize\", onMove);\n } else {\n doc.removeEventListener(\"scroll\", onMove, { capture: true });\n win.removeEventListener(\"resize\", onMove);\n cancelFrames();\n }\n };\n\n // Both engines (Chromium 156, Firefox 157) apply the scroll-dependent anchoring state, the\n // option and the scroll-compensated geometry alike, in the layout of the frame after the\n // `scroll` event: a read in the handler, or in a rAF registered from it (which runs before\n // that layout), sees the old option even after a forced layout. The timing is unspecified\n // (css-anchor-position-1 §3.3 issue), so read again in the next two frames; a scroll that\n // arrives while that is pending restarts it at the end, so the last scroll is always followed.\n // Separately, Chromium 156 keeps an overflowing option for a top-layer popover once the first\n // frames after the show have passed (a bug, §6.5; upstream item #92): then no frame reads a\n // new option, and `data-side` correctly keeps reporting the applied one. Do not drop the\n // frame reads \"because Chromium does not re-choose\": when it does, it lags like Firefox.\n let frame = 0;\n let again = false;\n const cancelFrames = () => {\n if (frame !== 0) win.cancelAnimationFrame(frame);\n frame = 0;\n again = false;\n };\n const readLater = () => {\n if (frame !== 0) {\n again = true;\n return;\n }\n frame = win.requestAnimationFrame(() => {\n read(true);\n // The popup was found hidden (or `side` turned null): `listen(false)` ended the pair.\n if (!listening) return;\n frame = win.requestAnimationFrame(() => {\n frame = 0;\n read(true);\n if (again && listening) {\n again = false;\n readLater();\n }\n });\n });\n };\n\n const read = (urgent: boolean) => {\n if (requested.current.side === null) {\n listen(false);\n write(null, urgent);\n return;\n }\n if (element.isConnected && isPopoverOpen(element)) {\n listen(true);\n const style = getComputedStyle(element);\n const placement = parsePositionArea(\n style.positionArea,\n toDirection(style.direction),\n () => toDirection(getComputedStyle(doc.documentElement).direction),\n style.writingMode || \"horizontal-tb\",\n );\n write(placement, urgent);\n return;\n }\n listen(false);\n // Hidden, but still rendered while an exit animation runs: keep the resolved side to the\n // end of it. The ResizeObserver sees the box go and resets then.\n // Nothing written, nothing to reset: skip the forced layout (every mount and request change\n // of a hidden popup comes through here).\n if (\n written.current !== null &&\n (!element.isConnected || element.getClientRects().length === 0)\n ) {\n write(null, urgent);\n }\n };\n\n function onEvent() {\n read(true);\n }\n function onMove() {\n // In every Chromium 156 / Firefox 157 probe this read still saw the old option (see the\n // frame reads above); kept as cover for WebKit, which was not probed, at the cost of one\n // style read per scroll event.\n read(true);\n if (listening) readLater();\n }\n\n sync.current = read;\n const observer = typeof ResizeObserver === \"function\" ? new ResizeObserver(onEvent) : null;\n observer?.observe(element);\n element.addEventListener(\"toggle\", onEvent);\n return () => {\n observer?.disconnect();\n element.removeEventListener(\"toggle\", onEvent);\n listen(false);\n if (sync.current === read) sync.current = null;\n };\n }, []);\n\n // A changed request while shown places the popup differently: read again (a layout effect, so\n // the corrected attribute is in the same frame). Also how `side={null}` turns the hook off.\n useLayoutEffect(() => {\n requested.current = { side, align };\n sync.current?.(false);\n }, [side, align]);\n\n if (side === null) return { side: null, align, ref };\n return resolved === null ? { side, align, ref } : { ...resolved, ref };\n}\n\nexport interface AnchoredPlacementRequest<Side extends AnchorSide> extends PlacementRequest<Side> {\n /** `position-try-fallbacks`. Default: flip on both axes. */\n readonly fallbacks?: string;\n}\n\nexport interface AnchoredPlacement<Side extends AnchorSide> extends PlacementResult<Side> {\n /** `data-side` / `data-align` (resolved); no keys when the side is `null` (not owned then). */\n readonly dataAttributes: DataAttributes;\n /**\n * The popup's `style`: the requested inline placement (the browser keeps choosing from it)\n * under the consumer's style, so the consumer wins. The consumer's style alone for `side: null`.\n */\n readonly style: <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ) => StateValue<CSSProperties | undefined, State>;\n}\n\n/**\n * An anchored popup's placement (Popover, Tooltip and Menu Popup): `useResolvedPlacement` plus\n * the data attributes and the inline `position-area` / `position-try-fallbacks` it renders.\n */\nexport function useAnchoredPlacement<Side extends AnchorSide>(\n request: AnchoredPlacementRequest<Side>,\n): AnchoredPlacement<Side> {\n const {\n side: requestedSide,\n align: requestedAlign,\n fallbacks = POSITION_TRY_FALLBACKS,\n } = request;\n const placement = useResolvedPlacement({ side: requestedSide, align: requestedAlign });\n const { side, align } = placement;\n const dataAttributes: DataAttributes =\n side !== null ? { \"data-side\": side, \"data-align\": align } : {};\n const style = <State>(\n consumer: StateValue<CSSProperties | undefined, State>,\n ): StateValue<CSSProperties | undefined, State> =>\n requestedSide === null\n ? consumer\n : (s: State) => ({\n positionArea: positionArea(requestedSide, requestedAlign),\n positionTryFallbacks: fallbacks,\n ...resolveStateValue(consumer, s),\n });\n return { ...placement, dataAttributes, style };\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,eAAe,UAA8B,UAAU,QAAQ,QAAQ;;;;;;;;;;;AAY7E,SAAgB,qBACd,SACuB;CACvB,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,CAAC,UAAU,eAAe,SAAmC,IAAI;CAEvE,MAAM,UAAU,OAAiC,IAAI;CAErD,MAAM,YAAY,OAA+B,OA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MAAM,YAAY,qBAAqB;EAAE,MAAM;EAAe,OAAO;CAAe,CAAC;CACrF,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM,iBACJ,SAAS,OAAO;EAAE,aAAa;EAAM,cAAc;CAAM,IAAI,CAAC;CAChE,MAAM,SACJ,aAEA,kBAAkB,OACd,YACC,OAAc;EACb,cAAc,aAAa,eAAe,cAAc;EACxD,sBAAsB;EACtB,GAAG,kBAAkB,UAAU,CAAC;CAClC;CACN,OAAO;EAAE,GAAG;EAAW;EAAgB;CAAM;AAC/C"}
|
|
@@ -28,15 +28,33 @@ function isHostButton(render) {
|
|
|
28
28
|
return isValidElement(render) && render.type === "button";
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
* Whether the rendered element certainly cannot be natively disabled: a host element of a tag
|
|
32
|
+
* other than `<button>` / `<input>` (an `<a>`, a `<div>`). No `render`, the function form and a
|
|
33
|
+
* component element may render a button.
|
|
34
|
+
*/
|
|
35
|
+
function certainlyNotDisableable(render) {
|
|
36
|
+
if (rendersButton(render)) return false;
|
|
37
|
+
return !(isValidElement(render) && render.type === "input");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The disabled rule of a button-like part that accepts an arbitrary `render` (conventions 1.2,
|
|
41
|
+
* design/components/button.md 17). Native `disabled` on a host `<button>` (the function form
|
|
42
|
+
* included), and wherever the element may be a button and the click's effect is the browser's
|
|
43
|
+
* own (`handlesClick: false`: a submitter, a reset button, a JS-free invoker; only native
|
|
44
|
+
* `disabled` stops those before hydration). `aria-disabled`, which the part's click handler
|
|
45
|
+
* honours by cancelling the click, otherwise: on an element that certainly cannot be natively
|
|
46
|
+
* disabled (a host `<a>`, `<div>`), on a component or other non-button render whose own handler
|
|
47
|
+
* is the action (`handlesClick: true`, the default), and with `alwaysFocusable` (an opt-in
|
|
48
|
+
* focusable disabled control: a menu item, a Toolbar or `focusableWhenDisabled` Button). A part
|
|
49
|
+
* that installs no click handler of its own (`Form.Submit`, a JS-free command part on a host
|
|
50
|
+
* link) installs `cancelClick` while `invoker` is `false`, so the click is cancelled there too.
|
|
51
|
+
*
|
|
52
|
+
* When `disabled` and the part's pending `aria-disabled` meet, the native `disabled` wins:
|
|
53
|
+
* `pendingAriaDisabled` below.
|
|
36
54
|
*/
|
|
37
55
|
function disabledButton(render, disabled, options = {}) {
|
|
38
56
|
const { handlesClick = true, alwaysFocusable = false } = options;
|
|
39
|
-
const focusable = alwaysFocusable || handlesClick
|
|
57
|
+
const focusable = alwaysFocusable || (handlesClick ? !isHostButton(render) : certainlyNotDisableable(render));
|
|
40
58
|
return {
|
|
41
59
|
props: {
|
|
42
60
|
disabled: focusable ? void 0 : disabled,
|
|
@@ -46,9 +64,29 @@ function disabledButton(render, disabled, options = {}) {
|
|
|
46
64
|
};
|
|
47
65
|
}
|
|
48
66
|
/**
|
|
67
|
+
* The click handler of a disabled part in the `aria-disabled` branch that has no click handler
|
|
68
|
+
* of its own (`Form.Submit`, a JS-free command Trigger / Close on a host link): cancels the
|
|
69
|
+
* click, so a disabled link does not navigate after hydration (conventions 1.2). Installed only
|
|
70
|
+
* while disabled: an enabled render element keeps its own `onClick` as the only one.
|
|
71
|
+
*/
|
|
72
|
+
function cancelClick(event) {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The owned `aria-disabled` of a pure trigger that also renders it while pending (conventions
|
|
77
|
+
* 3.6): the focusable-disabled branch's `true`; nothing while natively disabled (native
|
|
78
|
+
* `disabled` wins, a second unavailable state on the same element says nothing new); otherwise
|
|
79
|
+
* `true` while pending exactly when the part ignores activations (`ignoringPending`).
|
|
80
|
+
*/
|
|
81
|
+
function pendingAriaDisabled(disabledProps, ignoringPending) {
|
|
82
|
+
if (disabledProps.disabled === true) return void 0;
|
|
83
|
+
if (disabledProps["aria-disabled"] === true) return true;
|
|
84
|
+
return ignoringPending ? true : void 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
49
87
|
* The ref of a part with no library ref, merged from the consumer's `ref` and a `render`
|
|
50
|
-
* element's ref without memoisation (
|
|
51
|
-
* progress.md
|
|
88
|
+
* element's ref without memoisation (the directive-free half of `use-render.tsx`,
|
|
89
|
+
* progress.md 8.1). A fresh callback ref per render is correct because every merged callback
|
|
52
90
|
* returns a cleanup; a single ref is passed through untouched.
|
|
53
91
|
*/
|
|
54
92
|
function mergeRenderRef(consumerRef, render) {
|
|
@@ -80,6 +118,6 @@ function renderElement(options) {
|
|
|
80
118
|
return createElement(defaultElement, resolved);
|
|
81
119
|
}
|
|
82
120
|
//#endregion
|
|
83
|
-
export { disabledButton, isHostButton, mergeRenderRef, renderElement, rendersButton, resolveStateValue };
|
|
121
|
+
export { cancelClick, disabledButton, isHostButton, mergeRenderRef, pendingAriaDisabled, renderElement, rendersButton, resolveStateValue };
|
|
84
122
|
|
|
85
123
|
//# sourceMappingURL=render-element.mjs.map
|