@zj-dynamics/components 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/NOTICE.react-is +21 -0
- package/NOTICE.tabbable +22 -0
- package/README.md +31 -2
- package/compatibility.css +2 -0
- package/dist/Button.d.ts +90 -0
- package/dist/Button.js +58 -0
- package/dist/ButtonDismiss.d.ts +6 -0
- package/dist/ButtonDismiss.js +5 -0
- package/dist/Dialog.d.ts +75 -0
- package/dist/Dialog.js +59 -0
- package/dist/Icon.d.ts +20 -0
- package/dist/Icon.js +11 -0
- package/dist/InputText.d.ts +26 -0
- package/dist/InputText.js +63 -0
- package/dist/Switch.d.ts +8 -0
- package/dist/Switch.js +19 -0
- package/dist/Toast.d.ts +21 -0
- package/dist/Toast.js +58 -0
- package/dist/browserFocus.d.ts +11 -0
- package/dist/browserFocus.js +85 -0
- package/dist/browserHooks.d.ts +5 -0
- package/dist/browserHooks.js +4 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +91 -0
- package/dist/legacyModalPortal.d.ts +1 -0
- package/dist/legacyModalPortal.js +2 -0
- package/dist/mockViewportWidth.d.ts +5 -0
- package/dist/mockViewportWidth.js +58 -0
- package/dist/slotChildren.d.ts +2 -0
- package/dist/slotChildren.js +6 -0
- package/dist/theme.d.ts +26 -0
- package/dist/theme.js +65 -0
- package/dist/unstyledPrimitives.d.ts +12 -0
- package/dist/unstyledPrimitives.js +12 -0
- package/dist/useBreakpoints.d.ts +3 -0
- package/dist/useBreakpoints.js +2 -0
- package/dist/useFocusTrap.d.ts +1 -0
- package/dist/useFocusTrap.js +1 -0
- package/dist/useInView.d.ts +1 -0
- package/dist/useInView.js +1 -0
- package/dist/useIsSmallScreen.d.ts +1 -0
- package/dist/useIsSmallScreen.js +1 -0
- package/dist/useLiveAnnounce.d.ts +1 -0
- package/dist/useLiveAnnounce.js +1 -0
- package/dist/useOnKeyDown.d.ts +1 -0
- package/dist/useOnKeyDown.js +1 -0
- package/dist/useRefocusOnActivator.d.ts +1 -0
- package/dist/useRefocusOnActivator.js +1 -0
- package/dist/useResizeObserver.d.ts +22 -0
- package/dist/useResizeObserver.js +47 -0
- package/dist/useWindowDimensions.d.ts +2 -0
- package/dist/useWindowDimensions.js +1 -0
- package/dist/viewport.d.ts +46 -0
- package/dist/viewport.js +141 -0
- package/foundation/ActivityIndicator/ActivityIndicator.d.ts +38 -0
- package/foundation/ActivityIndicator/index.d.mts +2 -0
- package/foundation/ActivityIndicator/index.mjs +6 -0
- package/foundation/ActivityIndicator-es.js +30 -0
- package/foundation/Autocomplete/Autocomplete.d.ts +8 -0
- package/foundation/Autocomplete/Autocomplete.types.d.ts +401 -0
- package/foundation/Autocomplete/hooks/useAutocompleteListNav.d.ts +30 -0
- package/foundation/Autocomplete/index.d.mts +3 -0
- package/foundation/Autocomplete/index.mjs +39 -0
- package/foundation/Autocomplete/utils/interactionUtils.d.ts +14 -0
- package/foundation/Autocomplete-es.js +1322 -0
- package/foundation/Avatar/Avatar.d.ts +77 -0
- package/foundation/Avatar/index.d.mts +1 -0
- package/foundation/Avatar/index.mjs +6 -0
- package/foundation/Avatar-es.js +80 -0
- package/foundation/Banner/Banner.d.ts +10 -0
- package/foundation/Banner/Banner.types.d.ts +165 -0
- package/foundation/Banner/index.d.mts +2 -0
- package/foundation/Banner/index.mjs +14 -0
- package/foundation/Banner-es.js +134 -0
- package/foundation/Body-es.js +45 -0
- package/foundation/BottomSheet-es.js +110 -0
- package/foundation/Box/Box.d.ts +3 -0
- package/foundation/Box/Box.types.d.ts +40 -0
- package/foundation/Box/index.d.mts +1 -0
- package/foundation/Box/index.mjs +4 -0
- package/foundation/Box-es.js +130 -0
- package/foundation/Button/Button.d.ts +17 -0
- package/foundation/Button/Button.types.d.ts +112 -0
- package/foundation/Button/ButtonInternals.d.ts +11 -0
- package/foundation/Button/ButtonProvider.d.ts +11 -0
- package/foundation/Button/index.d.mts +4 -0
- package/foundation/Button/useButtonStyles.d.ts +17 -0
- package/foundation/Button-es.js +122 -0
- package/foundation/ButtonDismiss/ButtonDismiss.d.ts +6 -0
- package/foundation/ButtonDismiss/index.d.mts +1 -0
- package/foundation/ButtonDismiss-es.js +9 -0
- package/foundation/Card/Card.d.ts +78 -0
- package/foundation/Card/cardcolors.module.d.ts +90 -0
- package/foundation/Card/index.d.mts +1 -0
- package/foundation/Card/index.mjs +37 -0
- package/foundation/Card/types.d.ts +63 -0
- package/foundation/Card-es.js +138 -0
- package/foundation/Checkbox/Checkbox.d.ts +7 -0
- package/foundation/Checkbox/Checkbox.types.d.ts +51 -0
- package/foundation/Checkbox/index.d.mts +2 -0
- package/foundation/Checkbox/index.mjs +8 -0
- package/foundation/Checkbox-es.js +57 -0
- package/foundation/Chip/Chip.d.ts +14 -0
- package/foundation/Chip/Chip.types.d.ts +70 -0
- package/foundation/Chip/components/ChipDismissible/ChipDismissible.d.ts +3 -0
- package/foundation/Chip/components/ChipPrefix/Chip.Prefix.d.ts +3 -0
- package/foundation/Chip/components/ChipSelectable/ChipSelectable.d.ts +3 -0
- package/foundation/Chip/components/ChipSuffix/Chip.Suffix.d.ts +9 -0
- package/foundation/Chip/index.d.mts +4 -0
- package/foundation/Chip/index.mjs +19 -0
- package/foundation/Chip-es.js +165 -0
- package/foundation/ChipDismissible-es.js +19 -0
- package/foundation/Chips/Chip.d.ts +9 -0
- package/foundation/Chips/ChipDismissible.d.ts +11 -0
- package/foundation/Chips/ChipTypes.d.ts +59 -0
- package/foundation/Chips/Chips.d.ts +8 -0
- package/foundation/Chips/ChipsTypes.d.ts +106 -0
- package/foundation/Chips/InternalChipButton.d.ts +11 -0
- package/foundation/Chips/index.d.mts +3 -0
- package/foundation/Chips/index.mjs +56 -0
- package/foundation/Chips-es.js +114 -0
- package/foundation/Cluster/Cluster.d.ts +3 -0
- package/foundation/Cluster/index.d.mts +2 -0
- package/foundation/Cluster/index.mjs +4 -0
- package/foundation/Cluster/types.d.ts +47 -0
- package/foundation/Cluster-es.js +12 -0
- package/foundation/Combobox/Combobox.d.ts +71 -0
- package/foundation/Combobox/Combobox.footer.d.ts +7 -0
- package/foundation/Combobox/Combobox.items.d.ts +25 -0
- package/foundation/Combobox/Combobox.selectAll.d.ts +4 -0
- package/foundation/Combobox/Combobox.slotFactory.d.ts +7 -0
- package/foundation/Combobox/Combobox.types.d.ts +168 -0
- package/foundation/Combobox/index.d.mts +2 -0
- package/foundation/Combobox/index.mjs +28 -0
- package/foundation/Combobox-es.js +782 -0
- package/foundation/ComboboxPrimitive-es.js +187 -0
- package/foundation/ComboboxSeparator-es.js +3541 -0
- package/foundation/ComponentSettingsContext/ComponentSettingsContext.d.ts +41 -0
- package/foundation/ComponentSettingsContext/index.d.mts +4 -0
- package/foundation/ComponentSettingsContext/index.mjs +5 -0
- package/foundation/ComponentSettingsContext-es.js +18 -0
- package/foundation/ConfirmationModal/ConfirmationModal.d.ts +79 -0
- package/foundation/ConfirmationModal/index.d.mts +1 -0
- package/foundation/ConfirmationModal/index.mjs +37 -0
- package/foundation/ConfirmationModal-es.js +111 -0
- package/foundation/Container/Container.d.ts +6 -0
- package/foundation/Container/index.d.mts +1 -0
- package/foundation/Container/index.mjs +3 -0
- package/foundation/Container/types.d.ts +22 -0
- package/foundation/Container-es.js +16 -0
- package/foundation/Content/Content.d.ts +22 -0
- package/foundation/Content/Spacing.module.d.ts +14 -0
- package/foundation/Content/index.d.mts +1 -0
- package/foundation/Content/index.mjs +3 -0
- package/foundation/Content-es.js +13 -0
- package/foundation/ContentBlock/ContentBlock.d.ts +3 -0
- package/foundation/ContentBlock/index.d.mts +2 -0
- package/foundation/ContentBlock/index.mjs +4 -0
- package/foundation/ContentBlock/types.d.ts +37 -0
- package/foundation/ContentBlock-es.js +29 -0
- package/foundation/Countdown/Countdown.d.ts +30 -0
- package/foundation/Countdown/index.d.mts +1 -0
- package/foundation/Countdown/index.mjs +4 -0
- package/foundation/Countdown-es.js +649 -0
- package/foundation/Cover/Cover.d.ts +6 -0
- package/foundation/Cover/index.d.mts +2 -0
- package/foundation/Cover/index.mjs +4 -0
- package/foundation/Cover/types.d.ts +34 -0
- package/foundation/Cover-es.js +14 -0
- package/foundation/DataDump/DataDump.d.ts +21 -0
- package/foundation/DataDump/index.d.mts +1 -0
- package/foundation/DataDump/index.mjs +40 -0
- package/foundation/DataDump-es.js +26 -0
- package/foundation/DataList/DataList.const.d.ts +22 -0
- package/foundation/DataList/DataList.d.ts +28 -0
- package/foundation/DataList/DataList.types.d.ts +323 -0
- package/foundation/DataList/components/DataListAction/DataListAction.d.ts +3 -0
- package/foundation/DataList/components/DataListAction/index.d.mts +1 -0
- package/foundation/DataList/components/DataListBulkActions/DataListBulkActions.d.ts +4 -0
- package/foundation/DataList/components/DataListBulkActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListEmptyState/DataListEmptyState.d.ts +4 -0
- package/foundation/DataList/components/DataListEmptyState/index.d.mts +1 -0
- package/foundation/DataList/components/DataListFilters/DataListFilters.d.ts +11 -0
- package/foundation/DataList/components/DataListFilters/index.d.mts +1 -0
- package/foundation/DataList/components/DataListItemActions/DataListItemActions.d.ts +9 -0
- package/foundation/DataList/components/DataListItemActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayout/DataListLayout.d.ts +3 -0
- package/foundation/DataList/components/DataListLayout/index.d.mts +1 -0
- package/foundation/DataList/components/DataListLayoutActions/DataListLayoutActions.d.ts +2 -0
- package/foundation/DataList/components/DataListLayoutActions/index.d.mts +1 -0
- package/foundation/DataList/components/DataListSearch/DataListSearch.d.ts +8 -0
- package/foundation/DataList/components/DataListSearch/index.d.mts +1 -0
- package/foundation/DataList/components/DataListStatusBar/DataListStatusBar.d.ts +11 -0
- package/foundation/DataList/components/DataListStatusBar/index.d.mts +1 -0
- package/foundation/DataList/index.d.mts +2 -0
- package/foundation/DataList/index.mjs +96 -0
- package/foundation/DataList-es.js +141 -0
- package/foundation/DataList.const-es.js +26 -0
- package/foundation/DataList.module-es.js +3 -0
- package/foundation/DataList.utils-es.js +167 -0
- package/foundation/DataListAction-es.js +43 -0
- package/foundation/DataListActions-es.js +53 -0
- package/foundation/DataListActionsMenu-es.js +52 -0
- package/foundation/DataListBulkActions-es.js +28 -0
- package/foundation/DataListContext-es.js +26 -0
- package/foundation/DataListEmptyState-es.js +54 -0
- package/foundation/DataListFilters-es.js +43 -0
- package/foundation/DataListHeader-es.js +130 -0
- package/foundation/DataListHeaderTile-es.js +86 -0
- package/foundation/DataListItem-es.js +118 -0
- package/foundation/DataListItemActions-es.js +29 -0
- package/foundation/DataListItemActionsOverflow-es.js +34 -0
- package/foundation/DataListItemClickable-es.js +45 -0
- package/foundation/DataListItems-es.js +19 -0
- package/foundation/DataListLayout-es.js +19 -0
- package/foundation/DataListLayoutActions-es.js +36 -0
- package/foundation/DataListLayoutContext-es.js +14 -0
- package/foundation/DataListLayoutContext-es2.js +8 -0
- package/foundation/DataListLoadMore-es.js +32 -0
- package/foundation/DataListLoadingState-es.js +22 -0
- package/foundation/DataListOverflowFade-es.js +22 -0
- package/foundation/DataListSearch-es.js +84 -0
- package/foundation/DataListSort-es.js +74 -0
- package/foundation/DataListSortingOptions-es.js +34 -0
- package/foundation/DataListStatusBar-es.js +22 -0
- package/foundation/DataListStickyHeader-es.js +23 -0
- package/foundation/DataListTags-es.js +62 -0
- package/foundation/DataListTotalCount-es.js +38 -0
- package/foundation/DataTable/DataTable.d.ts +74 -0
- package/foundation/DataTable/SortIcon.d.ts +11 -0
- package/foundation/DataTable/components/DataTableActions.d.ts +2 -0
- package/foundation/DataTable/components/DataTableBody.d.ts +2 -0
- package/foundation/DataTable/components/DataTableCell.d.ts +2 -0
- package/foundation/DataTable/components/DataTableContainer.d.ts +2 -0
- package/foundation/DataTable/components/DataTableFooter.d.ts +5 -0
- package/foundation/DataTable/components/DataTableHeader.d.ts +2 -0
- package/foundation/DataTable/components/DataTableHeaderCell.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePagination.d.ts +5 -0
- package/foundation/DataTable/components/DataTablePaginationButton.d.ts +21 -0
- package/foundation/DataTable/components/DataTableRow.d.ts +2 -0
- package/foundation/DataTable/components/DataTableRowActions.d.ts +4 -0
- package/foundation/DataTable/components/DataTableSortableHeader.d.ts +24 -0
- package/foundation/DataTable/components/DataTableTable.d.ts +11 -0
- package/foundation/DataTable/components/index.d.mts +13 -0
- package/foundation/DataTable/index.d.mts +6 -0
- package/foundation/DataTable/index.mjs +29 -0
- package/foundation/DataTable/test-utilities/helpers.d.ts +1 -0
- package/foundation/DataTable/types.d.ts +83 -0
- package/foundation/DataTable-es.js +262 -0
- package/foundation/DataTableTable-es.js +117 -0
- package/foundation/DatePicker/DatePicker.d.ts +74 -0
- package/foundation/DatePicker/DatePickerActivator.d.ts +18 -0
- package/foundation/DatePicker/index.d.mts +1 -0
- package/foundation/DatePicker/index.mjs +26 -0
- package/foundation/DatePicker-es.js +13627 -0
- package/foundation/Dialog/dialogReturnFocus.d.ts +43 -0
- package/foundation/Disclosure/Disclosure.d.ts +68 -0
- package/foundation/Disclosure/index.d.mts +1 -0
- package/foundation/Disclosure/index.mjs +7 -0
- package/foundation/Disclosure-es.js +46 -0
- package/foundation/Divider/Divider.d.ts +39 -0
- package/foundation/Divider/DividerDirections.module.d.ts +6 -0
- package/foundation/Divider/DividerSizes.module.d.ts +8 -0
- package/foundation/Divider/index.d.mts +1 -0
- package/foundation/Divider/index.mjs +3 -0
- package/foundation/Divider-es.js +15 -0
- package/foundation/Drawer/Drawer.d.ts +14 -0
- package/foundation/Drawer/DrawerGrid.d.ts +7 -0
- package/foundation/Drawer/index.d.mts +2 -0
- package/foundation/Drawer/index.mjs +13 -0
- package/foundation/DrawerGrid-es.js +39 -0
- package/foundation/DrawerTitle-es.js +90 -0
- package/foundation/Emphasis/Emphasis.d.ts +12 -0
- package/foundation/Emphasis/index.d.mts +1 -0
- package/foundation/Emphasis/index.mjs +4 -0
- package/foundation/Emphasis-es.js +13 -0
- package/foundation/FeatureSwitch/FeatureSwitch.d.ts +52 -0
- package/foundation/FeatureSwitch/index.d.mts +1 -0
- package/foundation/FeatureSwitch/index.mjs +20 -0
- package/foundation/FeatureSwitch-es.js +66 -0
- package/foundation/FieldDescription-es.js +859 -0
- package/foundation/FilterPicker/FilterPicker.d.ts +11 -0
- package/foundation/FilterPicker/FilterPicker.types.d.ts +282 -0
- package/foundation/FilterPicker/FilterPickerProvider.d.ts +18 -0
- package/foundation/FilterPicker/components/FilterPickerAction/FilterPickerAction.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerAction/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/FilterPickerActivator.d.ts +3 -0
- package/foundation/FilterPicker/components/FilterPickerActivator/index.d.mts +1 -0
- package/foundation/FilterPicker/components/FilterPickerOption/FilterPickerOption.d.ts +3 -0
- package/foundation/FilterPicker/index.d.mts +3 -0
- package/foundation/FilterPicker/index.mjs +49 -0
- package/foundation/FilterPicker-es.js +110 -0
- package/foundation/FilterPicker.messages-es.js +56 -0
- package/foundation/FilterPickerAction-es.js +30 -0
- package/foundation/FilterPickerActivator-es.js +36 -0
- package/foundation/FilterPickerContent-es.js +180 -0
- package/foundation/FilterPickerContentHeader-es.js +23 -0
- package/foundation/FilterPickerContentList-es.js +74 -0
- package/foundation/FilterPickerContentSearch-es.js +35 -0
- package/foundation/FilterPickerLoadMore-es.js +14 -0
- package/foundation/FilterPickerOption-es.js +29 -0
- package/foundation/FilterPickerProvider-es.js +10 -0
- package/foundation/FilterPickerTrigger-es.js +19 -0
- package/foundation/Flex/Flex.d.ts +33 -0
- package/foundation/Flex/Flex.types.d.ts +6 -0
- package/foundation/Flex/index.d.mts +1 -0
- package/foundation/Flex/index.mjs +3 -0
- package/foundation/Flex-es.js +28 -0
- package/foundation/FormField/FormFieldAffix.d.ts +19 -0
- package/foundation/FormField/FormFieldTypes.d.ts +185 -0
- package/foundation/FormField/FormFieldWrapper.d.ts +57 -0
- package/foundation/FormField/hooks/useFormFieldName.d.ts +6 -0
- package/foundation/FormField/hooks/useFormFieldWrapperStyles.d.ts +35 -0
- package/foundation/FormField/index.d.mts +5 -0
- package/foundation/FormField/index.mjs +17 -0
- package/foundation/FormFieldPostFix-es.js +13 -0
- package/foundation/FormFieldWrapper-es.js +233 -0
- package/foundation/FormatFile/FormatFile.d.ts +42 -0
- package/foundation/FormatFile/index.d.mts +4 -0
- package/foundation/FormatFile/index.mjs +42 -0
- package/foundation/FormatFile/types.d.ts +27 -0
- package/foundation/FormatFile/useFormatFile.d.ts +5 -0
- package/foundation/FormatFile/useFormatFileStyles.d.ts +10 -0
- package/foundation/FormatFile-es.js +137 -0
- package/foundation/Frame/Frame.d.ts +3 -0
- package/foundation/Frame/index.d.mts +2 -0
- package/foundation/Frame/index.mjs +3 -0
- package/foundation/Frame/types.d.ts +24 -0
- package/foundation/Frame-es.js +10 -0
- package/foundation/Gallery/Gallery.d.ts +3 -0
- package/foundation/Gallery/GalleryTypes.d.ts +36 -0
- package/foundation/Gallery/index.d.mts +3 -0
- package/foundation/Gallery/index.mjs +64 -0
- package/foundation/Gallery-es.js +88 -0
- package/foundation/Glimmer/Glimmer.d.ts +71 -0
- package/foundation/Glimmer/index.d.mts +1 -0
- package/foundation/Glimmer/index.mjs +5 -0
- package/foundation/Glimmer/style/Shape.module.d.ts +9 -0
- package/foundation/Glimmer/style/Sizes.module.d.ts +10 -0
- package/foundation/Glimmer/style/Timing.module.d.ts +6 -0
- package/foundation/Glimmer-es.js +53 -0
- package/foundation/Grid/Grid.d.ts +32 -0
- package/foundation/Grid/GridAlign.module.d.ts +8 -0
- package/foundation/Grid/GridCell/GridCell.d.ts +23 -0
- package/foundation/Grid/GridCell/index.d.mts +1 -0
- package/foundation/Grid/index.d.mts +1 -0
- package/foundation/Grid/index.mjs +5 -0
- package/foundation/Grid-es.js +30 -0
- package/foundation/GridCell-es.js +34 -0
- package/foundation/Heading/Heading.d.ts +41 -0
- package/foundation/Heading/index.d.mts +2 -0
- package/foundation/Heading/index.mjs +4 -0
- package/foundation/Heading-es.js +55 -0
- package/foundation/HelperText-es.js +19 -0
- package/foundation/Icon/Icon.d.ts +47 -0
- package/foundation/Icon/index.d.mts +1 -0
- package/foundation/Icon-es.js +22 -0
- package/foundation/InlineLabel/InlineLabel.d.ts +18 -0
- package/foundation/InlineLabel/index.d.mts +1 -0
- package/foundation/InlineLabel/index.mjs +4 -0
- package/foundation/InlineLabel-es.js +19 -0
- package/foundation/InputAvatar/InputAvatar.d.ts +23 -0
- package/foundation/InputAvatar/index.d.mts +1 -0
- package/foundation/InputAvatar/index.mjs +22 -0
- package/foundation/InputAvatar-es.js +64 -0
- package/foundation/InputDate/InputDate.d.ts +3 -0
- package/foundation/InputDate/InputDate.types.d.ts +36 -0
- package/foundation/InputDate/index.d.mts +2 -0
- package/foundation/InputDate/index.mjs +39 -0
- package/foundation/InputDate-es.js +104 -0
- package/foundation/InputEmail/InputEmail.d.ts +3 -0
- package/foundation/InputEmail/InputEmail.types.d.ts +16 -0
- package/foundation/InputEmail/index.d.mts +2 -0
- package/foundation/InputEmail/index.mjs +22 -0
- package/foundation/InputEmail-es.js +105 -0
- package/foundation/InputFile/FileTypes.d.ts +17 -0
- package/foundation/InputFile/InputFile.d.ts +187 -0
- package/foundation/InputFile/InputFileButton.d.ts +6 -0
- package/foundation/InputFile/InputFileContentContext.d.ts +12 -0
- package/foundation/InputFile/InputFileDescription.d.ts +4 -0
- package/foundation/InputFile/InputFileDropzoneWrapper.d.ts +4 -0
- package/foundation/InputFile/InputFileHintText.d.ts +4 -0
- package/foundation/InputFile/index.d.mts +3 -0
- package/foundation/InputFile/index.mjs +16 -0
- package/foundation/InputFile-es.js +1780 -0
- package/foundation/InputGroup/InputGroup.d.ts +12 -0
- package/foundation/InputGroup/index.d.mts +1 -0
- package/foundation/InputGroup/index.mjs +3 -0
- package/foundation/InputGroup-es.js +26 -0
- package/foundation/InputNumber/InputNumber.d.ts +77 -0
- package/foundation/InputNumber/index.d.mts +2 -0
- package/foundation/InputNumber/index.mjs +33 -0
- package/foundation/InputNumber/types.d.ts +197 -0
- package/foundation/InputNumber-es.js +348 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.d.ts +3 -0
- package/foundation/InputPhoneNumber/InputPhoneNumber.types.d.ts +24 -0
- package/foundation/InputPhoneNumber/index.d.mts +2 -0
- package/foundation/InputPhoneNumber/index.mjs +22 -0
- package/foundation/InputPhoneNumber-es.js +188 -0
- package/foundation/InputText/InputText.d.ts +3 -0
- package/foundation/InputText/InputText.types.d.ts +58 -0
- package/foundation/InputText/index.d.mts +2 -0
- package/foundation/InputText/index.mjs +23 -0
- package/foundation/InputText-es.js +196 -0
- package/foundation/InputTime/InputTime.d.ts +3 -0
- package/foundation/InputTime/InputTime.types.d.ts +34 -0
- package/foundation/InputTime/index.d.mts +2 -0
- package/foundation/InputTime/index.mjs +23 -0
- package/foundation/InputTime-es.js +297 -0
- package/foundation/InputValidation/InputValidation.d.ts +10 -0
- package/foundation/InputValidation/index.d.mts +1 -0
- package/foundation/InputValidation/index.mjs +8 -0
- package/foundation/InputValidation-es.js +22 -0
- package/foundation/InternalChipDismissible-es.js +68 -0
- package/foundation/LICENSE +21 -0
- package/foundation/LegacySelect/LegacySelect.d.ts +7 -0
- package/foundation/LegacySelect/LegacySelect.types.d.ts +18 -0
- package/foundation/LegacySelect/Option.d.ts +18 -0
- package/foundation/LegacySelect/OptionGroup.d.ts +29 -0
- package/foundation/LegacySelect/index.d.mts +3 -0
- package/foundation/LegacySelect/index.mjs +23 -0
- package/foundation/LegacySelect-es.js +76 -0
- package/foundation/LegacyThemeContext/LegacyThemeContext.d.ts +5 -0
- package/foundation/LegacyThemeContext/index.d.mts +3 -0
- package/foundation/LegacyThemeContext/index.mjs +12 -0
- package/foundation/LegacyThemeContext/types.d.ts +59 -0
- package/foundation/LegacyThemeContext/updateTheme.d.ts +7 -0
- package/foundation/LegacyThemeContext-es.js +457 -0
- package/foundation/LightBox/LightBox.d.ts +165 -0
- package/foundation/LightBox/LightBox.types.d.ts +153 -0
- package/foundation/LightBox/LightBoxContext.d.ts +5 -0
- package/foundation/LightBox/index.d.mts +3 -0
- package/foundation/LightBox/index.mjs +50 -0
- package/foundation/LightBox-es.js +454 -0
- package/foundation/Link/Link.d.ts +9 -0
- package/foundation/Link/index.d.mts +2 -0
- package/foundation/Link/index.mjs +2 -0
- package/foundation/Link-es.js +12 -0
- package/foundation/List/List.d.ts +41 -0
- package/foundation/List/ListItem.d.ts +59 -0
- package/foundation/List/index.d.mts +2 -0
- package/foundation/List/index.mjs +22 -0
- package/foundation/List-es.js +199 -0
- package/foundation/Markdown/Markdown.d.ts +24 -0
- package/foundation/Markdown/index.d.mts +1 -0
- package/foundation/Markdown/index.mjs +10 -0
- package/foundation/Markdown-es.js +20558 -0
- package/foundation/Menu/Menu.d.ts +89 -0
- package/foundation/Menu/Menu.types.d.ts +105 -0
- package/foundation/Menu/index.d.mts +2 -0
- package/foundation/Menu/index.mjs +35 -0
- package/foundation/Menu/menuComposableTypes.d.ts +103 -0
- package/foundation/Menu-es.js +1033 -0
- package/foundation/MenuSubmenuTrigger-es.js +3088 -0
- package/foundation/Modal/Modal.rebuilt.d.ts +16 -0
- package/foundation/Modal/Modal.types.d.ts +138 -0
- package/foundation/Modal/ModalContext.rebuilt.d.ts +19 -0
- package/foundation/Modal/ModalSizes.module.d.ts +7 -0
- package/foundation/Modal/index.d.mts +17 -0
- package/foundation/Modal/index.mjs +302 -0
- package/foundation/Modal/useModalStyles.d.ts +12 -0
- package/foundation/MultiSelect/MultiSelect.d.ts +30 -0
- package/foundation/MultiSelect/index.d.mts +1 -0
- package/foundation/MultiSelect/index.mjs +9 -0
- package/foundation/MultiSelect/types.d.ts +13 -0
- package/foundation/MultiSelect-es.js +172 -0
- package/foundation/OverlaySeparator-es.js +13 -0
- package/foundation/Page/Page.d.ts +74 -0
- package/foundation/Page/index.d.mts +2 -0
- package/foundation/Page/index.mjs +42 -0
- package/foundation/Page/types.d.ts +123 -0
- package/foundation/Page-es.js +196 -0
- package/foundation/Popover/Popover.d.ts +9 -0
- package/foundation/Popover/Popover.types.d.ts +109 -0
- package/foundation/Popover/PopoverContext.d.ts +18 -0
- package/foundation/Popover/index.d.mts +4 -0
- package/foundation/Popover/index.mjs +27 -0
- package/foundation/Popover/usePopoverStyles.d.ts +5 -0
- package/foundation/Popover-es.js +166 -0
- package/foundation/ProgressBar/ProgressBar.d.ts +41 -0
- package/foundation/ProgressBar/ProgressBarSizes.module.d.ts +7 -0
- package/foundation/ProgressBar/index.d.mts +1 -0
- package/foundation/ProgressBar/index.mjs +5 -0
- package/foundation/ProgressBar-es.js +48 -0
- package/foundation/ProgressIndicator/ProgressIndicator.d.ts +60 -0
- package/foundation/ProgressIndicator/index.d.mts +1 -0
- package/foundation/ProgressIndicator/index.mjs +3 -0
- package/foundation/ProgressIndicator-es.js +41 -0
- package/foundation/RadioGroup/RadioGroup.d.ts +33 -0
- package/foundation/RadioGroup/RadioOption.d.ts +48 -0
- package/foundation/RadioGroup/index.d.mts +2 -0
- package/foundation/RadioGroup/index.mjs +5 -0
- package/foundation/RadioGroup-es.js +42 -0
- package/foundation/ResponsiveSwitcher/ResponsiveSwitcher.d.ts +3 -0
- package/foundation/ResponsiveSwitcher/index.d.mts +2 -0
- package/foundation/ResponsiveSwitcher/index.mjs +4 -0
- package/foundation/ResponsiveSwitcher/types.d.ts +26 -0
- package/foundation/ResponsiveSwitcher-es.js +11 -0
- package/foundation/RulnarPortalContent-es.js +1 -0
- package/foundation/ScrollAreaViewport-es.js +3959 -0
- package/foundation/SegmentedControl/SegmentedControl.d.ts +39 -0
- package/foundation/SegmentedControl/SegmentedControlBase.d.ts +7 -0
- package/foundation/SegmentedControl/SegmentedControlOption.d.ts +15 -0
- package/foundation/SegmentedControl/SegmentedControlProvider.d.ts +17 -0
- package/foundation/SegmentedControl/index.d.mts +2 -0
- package/foundation/SegmentedControl/index.mjs +3 -0
- package/foundation/SegmentedControl-es.js +64 -0
- package/foundation/Select/Select.d.ts +31 -0
- package/foundation/Select/Select.types.d.ts +145 -0
- package/foundation/Select/index.d.mts +2 -0
- package/foundation/Select/index.mjs +29 -0
- package/foundation/Select-es.js +227 -0
- package/foundation/SelectGroupLabel-es.js +1763 -0
- package/foundation/SelectPrimitive-es.js +126 -0
- package/foundation/Separator-es.js +33 -0
- package/foundation/SideDrawer/SideDrawer.d.ts +56 -0
- package/foundation/SideDrawer/SideDrawerActions.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerBackButton.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerFooter.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerTitle.d.ts +3 -0
- package/foundation/SideDrawer/SideDrawerToolbar.d.ts +2 -0
- package/foundation/SideDrawer/index.d.mts +1 -0
- package/foundation/SideDrawer/index.mjs +16 -0
- package/foundation/SideDrawer-es.js +198 -0
- package/foundation/SideKick/SideKick.d.ts +3 -0
- package/foundation/SideKick/index.d.mts +2 -0
- package/foundation/SideKick/index.mjs +4 -0
- package/foundation/SideKick/types.d.ts +35 -0
- package/foundation/SideKick-es.js +15 -0
- package/foundation/Spinner/Spinner.d.ts +22 -0
- package/foundation/Spinner/index.d.mts +1 -0
- package/foundation/Spinner/index.mjs +6 -0
- package/foundation/Spinner-es.js +21 -0
- package/foundation/Stack/Stack.d.ts +3 -0
- package/foundation/Stack/index.d.mts +2 -0
- package/foundation/Stack/index.mjs +4 -0
- package/foundation/Stack/types.d.ts +32 -0
- package/foundation/Stack-es.js +13 -0
- package/foundation/StatusIndicator/StatusIndicator.d.ts +7 -0
- package/foundation/StatusIndicator/StatusIndicator.type.d.ts +1 -0
- package/foundation/StatusIndicator/index.d.mts +2 -0
- package/foundation/StatusIndicator/index.mjs +2 -0
- package/foundation/StatusIndicator-es.js +9 -0
- package/foundation/StatusLabel/StatusLabel.d.ts +26 -0
- package/foundation/StatusLabel/index.d.mts +1 -0
- package/foundation/StatusLabel/index.mjs +5 -0
- package/foundation/StatusLabel-es.js +16 -0
- package/foundation/Table/Body.d.ts +7 -0
- package/foundation/Table/Cells/Cell.d.ts +8 -0
- package/foundation/Table/Cells/CellCurrency.d.ts +9 -0
- package/foundation/Table/Cells/CellNumeric.d.ts +5 -0
- package/foundation/Table/Footer.d.ts +7 -0
- package/foundation/Table/Header.d.ts +7 -0
- package/foundation/Table/Row.d.ts +7 -0
- package/foundation/Table/Table.d.ts +7 -0
- package/foundation/Table/index.d.mts +8 -0
- package/foundation/Table/index.mjs +4 -0
- package/foundation/Tabs/Tabs.d.ts +38 -0
- package/foundation/Tabs/index.d.mts +1 -0
- package/foundation/Tabs/index.mjs +8 -0
- package/foundation/Tabs-es.js +227 -0
- package/foundation/Text/Text.d.ts +29 -0
- package/foundation/Text/index.d.mts +2 -0
- package/foundation/Text/index.mjs +4 -0
- package/foundation/Text-es.js +25 -0
- package/foundation/Thumbnail/Thumbnail.d.ts +25 -0
- package/foundation/Thumbnail/index.d.mts +1 -0
- package/foundation/Thumbnail/index.mjs +9 -0
- package/foundation/Thumbnail-es.js +119 -0
- package/foundation/Tiles/Tiles.d.ts +3 -0
- package/foundation/Tiles/index.d.mts +2 -0
- package/foundation/Tiles/index.mjs +4 -0
- package/foundation/Tiles/types.d.ts +34 -0
- package/foundation/Tiles-es.js +11 -0
- package/foundation/Tooltip/Tooltip.d.ts +18 -0
- package/foundation/Tooltip/Tooltip.types.d.ts +1 -0
- package/foundation/Tooltip/index.d.mts +1 -0
- package/foundation/Tooltip/index.mjs +8 -0
- package/foundation/Tooltip-es.js +137 -0
- package/foundation/Typography/Typography.d.ts +64 -0
- package/foundation/Typography/css/Emphasis.module.d.ts +6 -0
- package/foundation/Typography/css/FontFamilies.module.d.ts +6 -0
- package/foundation/Typography/css/FontSizes.module.d.ts +12 -0
- package/foundation/Typography/css/FontWeights.module.d.ts +10 -0
- package/foundation/Typography/css/TextAlignment.module.d.ts +7 -0
- package/foundation/Typography/css/TextCases.module.d.ts +8 -0
- package/foundation/Typography/css/TextColors.module.d.ts +69 -0
- package/foundation/Typography/index.d.mts +1 -0
- package/foundation/Typography/index.mjs +3 -0
- package/foundation/Typography/types.d.ts +7 -0
- package/foundation/Typography-es.js +53 -0
- package/foundation/_baseAssignValue-es.js +29 -0
- package/foundation/_baseEach-es.js +1028 -0
- package/foundation/_baseFlatten-es.js +65 -0
- package/foundation/_baseFor-es.js +45 -0
- package/foundation/_commonjsHelpers-es.js +7 -0
- package/foundation/_getAllKeys-es.js +506 -0
- package/foundation/_getTag-es.js +133 -0
- package/foundation/_isIterateeCall-es.js +55 -0
- package/foundation/_setToString-es.js +168 -0
- package/foundation/buttonRenderAdapter-es.js +52 -0
- package/foundation/buttonStyles.d.mts +1 -0
- package/foundation/buttonStyles.mjs +1 -0
- package/foundation/clearable.d.ts +1 -0
- package/foundation/common.messages-es.js +18 -0
- package/foundation/compatHooks.mjs +2 -0
- package/foundation/constants-es.js +3 -0
- package/foundation/dateLocale-es.js +1142 -0
- package/foundation/debounce-es.js +329 -0
- package/foundation/dialogFocus.d.mts +1 -0
- package/foundation/dialogFocus.mjs +66 -0
- package/foundation/filterDataAttributes-es.js +24 -0
- package/foundation/floating-ui.react-es.js +6174 -0
- package/foundation/getMappedSpaceToken-es.js +18 -0
- package/foundation/helpers-es.js +15 -0
- package/foundation/identity-es.js +809 -0
- package/foundation/imageTypes.d.mts +1 -0
- package/foundation/imageTypes.mjs +1 -0
- package/foundation/index-es.js +1186 -0
- package/foundation/isObjectLike-es.js +190 -0
- package/foundation/isSymbol-es.js +33 -0
- package/foundation/isTypedArray-es.js +589 -0
- package/foundation/keysIn-es.js +385 -0
- package/foundation/linkEvents.d.mts +1 -0
- package/foundation/linkEvents.mjs +9 -0
- package/foundation/maxHeight-es.js +22 -0
- package/foundation/mergeClassName-es.js +10 -0
- package/foundation/mergeRefs-es.js +18 -0
- package/foundation/nestedEscape-es.js +91 -0
- package/foundation/noop-es.js +24 -0
- package/foundation/primitives/BottomSheet/BottomSheet.d.ts +37 -0
- package/foundation/primitives/BottomSheet/BottomSheet.types.d.ts +36 -0
- package/foundation/primitives/BottomSheet/index.d.mts +2 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.d.ts +32 -0
- package/foundation/primitives/ComboboxPrimitive/ComboboxPrimitive.types.d.ts +30 -0
- package/foundation/primitives/ComboboxPrimitive/index.d.mts +2 -0
- package/foundation/primitives/HelperText/HelperText.d.ts +25 -0
- package/foundation/primitives/HelperText/index.d.mts +1 -0
- package/foundation/primitives/OverlaySeparator/OverlaySeparator.d.ts +6 -0
- package/foundation/primitives/OverlaySeparator/index.d.mts +1 -0
- package/foundation/primitives/SelectPrimitive/SelectPrimitive.d.ts +74 -0
- package/foundation/primitives/SelectPrimitive/index.d.mts +2 -0
- package/foundation/primitives/SelectPrimitive/types.d.ts +31 -0
- package/foundation/primitives/index.d.mts +12 -0
- package/foundation/primitives/index.mjs +29 -0
- package/foundation/routerLink.d.mts +3 -0
- package/foundation/routerLink.mjs +1 -0
- package/foundation/scrollEdges-es.js +64 -0
- package/foundation/scrollable-es.js +54 -0
- package/foundation/sharedHelpers/getMappedBreakpointWidth.d.ts +8 -0
- package/foundation/sharedHelpers/types.d.ts +254 -0
- package/foundation/stringifyLocale-es.js +11 -0
- package/foundation/styles.css +16646 -0
- package/foundation/tslib.es6-es.js +97 -0
- package/foundation/unstyledPrimitives/index.d.mts +22 -0
- package/foundation/useActiveLayout-es.js +14 -0
- package/foundation/useBatchSelect-es.js +36 -0
- package/foundation/useChildComponent-es.js +15 -0
- package/foundation/useComponentMessages-es.js +86 -0
- package/foundation/useCompositeListItem-es.js +3955 -0
- package/foundation/useFormFieldFocus-es.js +37 -0
- package/foundation/useFormFieldName-es.js +11 -0
- package/foundation/useLabel-es.js +81 -0
- package/foundation/useRenderElement-es.js +628 -0
- package/foundation/useResponsiveSizing-es.js +8 -0
- package/foundation/useScrollLock-es.js +5746 -0
- package/foundation/useScrollToActive-es.js +581 -0
- package/foundation/utils/isNormalClick.d.ts +6 -0
- package/foundation/utils/isPreviewableImage.d.ts +1 -0
- package/foundation/utils/meta/meta.json +298 -0
- package/foundation.css +67 -0
- package/package.json +540 -4
- package/src/styles.css +181 -0
|
@@ -0,0 +1,3088 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { a as useRefWithInit, f as formatErrorMessage, u as useRenderElement, m as mergeProps, b as useMergedRefs, N as NOOP, E as EMPTY_OBJECT, c as EMPTY_ARRAY, w as warn } from './useRenderElement-es.js';
|
|
3
|
+
import { bl as isMouseLikePointerType, q as useTimeout, I as getWindow, bm as mergeCleanups, y as addEventListener, e as getTarget, au as isElement, bn as isTypeableElement, bo as matchesFocusVisible, bp as isTargetInsideEnabledTrigger, h as createChangeEventDetails, bq as triggerFocus, br as createAttribute, D as activeElement, o as ownerDocument, a0 as contains, bs as mac, a9 as webkit, i as isHTMLElement, bt as triggerPress, bu as escapeKey, H as useOnMount, T as Timeout, aM as useFloatingTree, aJ as useFloatingParentNodeId, d as useStableCallback, c as useIsoLayoutEffect, bv as isInteractiveElement, bw as getNodeChildren, bx as triggerHover, w as useValueAsRef, p as popupTransitionStateMapping, ad as itemPress, by as dispatchClickWithModifiers, f as useButton, t as transitionStatusMapping, u as useBaseUiId, l as useOpenChangeComplete, Z as outsidePress, n as FloatingFocusManager, a2 as FloatingPortal, bz as useAnimationsFinished, bA as POPUP_COLLISION_AVOIDANCE, a3 as InternalBackdrop, a4 as inertValue, bB as FloatingNode, a5 as DROPDOWN_COLLISION_AVOIDANCE, bC as siblingOpen, v as useControlled, s as useTransitionStatus, aL as PopupTriggerMap, bD as FloatingTreeStore, X as ReactStore, bE as fastComponent, aI as useId, bF as useFloatingNodeId, R as useOpenInteractionType, b8 as useImplicitActiveTrigger, b9 as useOpenStateTransitions, bG as attachPreventUnmountOnClose, b5 as setPopupOpenState, Y as focusOut, aS as listNavigation, bH as useSyncedFloatingRootContext, k as imperativeAction, W as useDismiss, a7 as useDirection, bI as TYPEAHEAD_RESET_MS, F as FOCUSABLE_POPUP_PROPS, b4 as usePopupInteractionProps, ba as PopupHandleAttachment, bJ as FloatingTree, bK as useCompositeRootContext, a as isLastTraversableNode, b as getParentNode, bL as getTabbableBeforeElement, bM as isOutsideEvent, bN as getTabbableAfterElement, bO as getNextTabbable, bP as fastComponentRef, bb as useTriggerDataForwarding, a1 as cancelOpen, V as useClick, _ as pressableTriggerOpenStateMapping, bQ as FocusGuard, bR as PATIENT_CLICK_THRESHOLD, bS as useTriggerRegistration, S as SafeReact, be as triggerOpenStateMapping, bT as voiceOver } from './useScrollLock-es.js';
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
import { A as useCompositeListItem, z as getDisabledMountTransitionStyles, w as useAnchorPositioning, v as useAnchoredPopupScrollLock, x as usePositioner, C as CompositeList, j as useListNavigation, k as useTypeahead, p as isMouseWithinBounds } from './useCompositeListItem-es.js';
|
|
6
|
+
import { u as useToolbarRootContext, l as isElementDisabled } from './SelectGroupLabel-es.js';
|
|
7
|
+
import { C as COMPOSITE_KEYS } from './scrollEdges-es.js';
|
|
8
|
+
import { N as NullStore, o as createInitialPopupStoreState, p as popupStoreSelectors, q as usePopupHandleStore } from './ScrollAreaViewport-es.js';
|
|
9
|
+
import * as ReactDOM from 'react-dom';
|
|
10
|
+
|
|
11
|
+
function resolveValue(value, pointerType) {
|
|
12
|
+
if (pointerType != null && !isMouseLikePointerType(pointerType)) {
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'function') {
|
|
16
|
+
return value();
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function getDelay(value, prop, pointerType) {
|
|
21
|
+
const result = resolveValue(value, pointerType);
|
|
22
|
+
if (typeof result === 'number') {
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return result?.[prop];
|
|
26
|
+
}
|
|
27
|
+
function getRestMs(value) {
|
|
28
|
+
if (typeof value === 'function') {
|
|
29
|
+
return value();
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function isClickLikeOpenEvent(openEventType, interactedInside) {
|
|
34
|
+
return interactedInside || openEventType === 'click' || openEventType === 'mousedown';
|
|
35
|
+
}
|
|
36
|
+
function isHoverOpenEvent(openEventType) {
|
|
37
|
+
return openEventType?.includes('mouse') && openEventType !== 'mousedown';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const isMacSafari = mac && webkit;
|
|
41
|
+
/**
|
|
42
|
+
* Opens the floating element while the reference element has focus, like CSS
|
|
43
|
+
* `:focus`.
|
|
44
|
+
* @see https://floating-ui.com/docs/useFocus
|
|
45
|
+
*/
|
|
46
|
+
function useFocus(context, props = {}) {
|
|
47
|
+
const {
|
|
48
|
+
enabled = true,
|
|
49
|
+
delay
|
|
50
|
+
} = props;
|
|
51
|
+
const store = 'rootStore' in context ? context.rootStore : context;
|
|
52
|
+
const {
|
|
53
|
+
events,
|
|
54
|
+
dataRef
|
|
55
|
+
} = store.context;
|
|
56
|
+
const blockFocusRef = React.useRef(false);
|
|
57
|
+
// Track which reference should be blocked from re-opening after Escape/press dismissal.
|
|
58
|
+
const blockedReferenceRef = React.useRef(null);
|
|
59
|
+
const keyboardModalityRef = React.useRef(true);
|
|
60
|
+
const timeout = useTimeout();
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
const domReference = store.select('domReferenceElement');
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const win = getWindow(domReference);
|
|
67
|
+
|
|
68
|
+
// If the reference was focused and the user left the tab/window, and the
|
|
69
|
+
// floating element was not open, the focus should be blocked when they
|
|
70
|
+
// return to the tab/window.
|
|
71
|
+
function onBlur() {
|
|
72
|
+
const currentDomReference = store.select('domReferenceElement');
|
|
73
|
+
if (!store.select('open') && isHTMLElement(currentDomReference) && currentDomReference === activeElement(ownerDocument(currentDomReference))) {
|
|
74
|
+
blockFocusRef.current = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function onKeyDown() {
|
|
78
|
+
keyboardModalityRef.current = true;
|
|
79
|
+
}
|
|
80
|
+
function onPointerDown() {
|
|
81
|
+
keyboardModalityRef.current = false;
|
|
82
|
+
}
|
|
83
|
+
return mergeCleanups(addEventListener(win, 'blur', onBlur), isMacSafari && addEventListener(win, 'keydown', onKeyDown, true), isMacSafari && addEventListener(win, 'pointerdown', onPointerDown, true));
|
|
84
|
+
}, [store, enabled]);
|
|
85
|
+
React.useEffect(() => {
|
|
86
|
+
if (!enabled) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
function onOpenChangeLocal(details) {
|
|
90
|
+
if (details.reason === triggerPress || details.reason === escapeKey) {
|
|
91
|
+
const referenceElement = store.select('domReferenceElement');
|
|
92
|
+
if (isElement(referenceElement)) {
|
|
93
|
+
blockedReferenceRef.current = referenceElement;
|
|
94
|
+
blockFocusRef.current = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
events.on('openchange', onOpenChangeLocal);
|
|
99
|
+
return () => {
|
|
100
|
+
events.off('openchange', onOpenChangeLocal);
|
|
101
|
+
};
|
|
102
|
+
}, [events, enabled, store]);
|
|
103
|
+
const reference = React.useMemo(() => {
|
|
104
|
+
function resetBlockedFocus() {
|
|
105
|
+
blockFocusRef.current = false;
|
|
106
|
+
blockedReferenceRef.current = null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
onMouseLeave() {
|
|
110
|
+
resetBlockedFocus();
|
|
111
|
+
},
|
|
112
|
+
onFocus(event) {
|
|
113
|
+
const focusTarget = event.currentTarget;
|
|
114
|
+
if (blockFocusRef.current) {
|
|
115
|
+
if (blockedReferenceRef.current === focusTarget) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
resetBlockedFocus();
|
|
119
|
+
}
|
|
120
|
+
const target = getTarget(event.nativeEvent);
|
|
121
|
+
if (isElement(target)) {
|
|
122
|
+
// Safari fails to match `:focus-visible` if focus was initially
|
|
123
|
+
// outside the document.
|
|
124
|
+
if (isMacSafari && !event.relatedTarget) {
|
|
125
|
+
if (!keyboardModalityRef.current && !isTypeableElement(target)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
} else if (!matchesFocusVisible(target)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const movedFromOtherEnabledTrigger = isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements);
|
|
133
|
+
const {
|
|
134
|
+
nativeEvent,
|
|
135
|
+
currentTarget
|
|
136
|
+
} = event;
|
|
137
|
+
const delayValue = typeof delay === 'function' ? delay() : delay;
|
|
138
|
+
if (store.select('open') && movedFromOtherEnabledTrigger || delayValue === 0 || delayValue === undefined) {
|
|
139
|
+
store.setOpen(true, createChangeEventDetails(triggerFocus, nativeEvent, currentTarget));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
timeout.start(delayValue, () => {
|
|
143
|
+
if (blockFocusRef.current) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
store.setOpen(true, createChangeEventDetails(triggerFocus, nativeEvent, currentTarget));
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
onBlur(event) {
|
|
150
|
+
resetBlockedFocus();
|
|
151
|
+
const relatedTarget = event.relatedTarget;
|
|
152
|
+
const nativeEvent = event.nativeEvent;
|
|
153
|
+
|
|
154
|
+
// Hit the non-modal focus management portal guard. Focus will be
|
|
155
|
+
// moved into the floating element immediately after.
|
|
156
|
+
const movedToFocusGuard = isElement(relatedTarget) && relatedTarget.hasAttribute(createAttribute('focus-guard')) && relatedTarget.getAttribute('data-type') === 'outside';
|
|
157
|
+
|
|
158
|
+
// Wait for the window blur listener to fire.
|
|
159
|
+
timeout.start(0, () => {
|
|
160
|
+
const domReference = store.select('domReferenceElement');
|
|
161
|
+
const activeEl = activeElement(ownerDocument(domReference));
|
|
162
|
+
|
|
163
|
+
// Focus left the page, keep it open.
|
|
164
|
+
if (!relatedTarget && activeEl === domReference) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// When focusing the reference element (e.g. regular click), then
|
|
169
|
+
// clicking into the floating element, prevent it from hiding.
|
|
170
|
+
// Note: it must be focusable, e.g. `tabindex="-1"`.
|
|
171
|
+
// We can not rely on relatedTarget to point to the correct element
|
|
172
|
+
// as it will only point to the shadow host of the newly focused element
|
|
173
|
+
// and not the element that actually has received focus if it is located
|
|
174
|
+
// inside a shadow root.
|
|
175
|
+
if (contains(dataRef.current.floatingContext?.refs.floating.current, activeEl) || contains(domReference, activeEl) || movedToFocusGuard) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// If the next focused element is one of the triggers, do not close
|
|
180
|
+
// the floating element. The focus handler of that trigger will
|
|
181
|
+
// handle the open state.
|
|
182
|
+
const nextFocusedElement = relatedTarget ?? activeEl;
|
|
183
|
+
if (isTargetInsideEnabledTrigger(nextFocusedElement, store.context.triggerElements)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
store.setOpen(false, createChangeEventDetails(triggerFocus, nativeEvent));
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}, [dataRef, delay, store, timeout]);
|
|
191
|
+
return React.useMemo(() => enabled ? {
|
|
192
|
+
reference,
|
|
193
|
+
trigger: reference
|
|
194
|
+
} : {}, [enabled, reference]);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class HoverInteraction {
|
|
198
|
+
constructor() {
|
|
199
|
+
this.pointerType = undefined;
|
|
200
|
+
this.interactedInside = false;
|
|
201
|
+
this.handler = undefined;
|
|
202
|
+
this.blockMouseMove = true;
|
|
203
|
+
this.performedPointerEventsMutation = false;
|
|
204
|
+
this.pointerEventsScopeElement = null;
|
|
205
|
+
this.pointerEventsReferenceElement = null;
|
|
206
|
+
this.pointerEventsFloatingElement = null;
|
|
207
|
+
this.restTimeoutPending = false;
|
|
208
|
+
this.openChangeTimeout = new Timeout();
|
|
209
|
+
this.restTimeout = new Timeout();
|
|
210
|
+
this.handleCloseOptions = undefined;
|
|
211
|
+
}
|
|
212
|
+
static create() {
|
|
213
|
+
return new HoverInteraction();
|
|
214
|
+
}
|
|
215
|
+
dispose = () => {
|
|
216
|
+
this.openChangeTimeout.clear();
|
|
217
|
+
this.restTimeout.clear();
|
|
218
|
+
};
|
|
219
|
+
disposeEffect = () => {
|
|
220
|
+
return this.dispose;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const pointerEventsMutationOwnerByScopeElement = new WeakMap();
|
|
224
|
+
function clearSafePolygonPointerEventsMutation(instance) {
|
|
225
|
+
if (!instance.performedPointerEventsMutation) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const scopeElement = instance.pointerEventsScopeElement;
|
|
229
|
+
if (scopeElement && pointerEventsMutationOwnerByScopeElement.get(scopeElement) === instance) {
|
|
230
|
+
instance.pointerEventsScopeElement?.style.removeProperty('pointer-events');
|
|
231
|
+
instance.pointerEventsReferenceElement?.style.removeProperty('pointer-events');
|
|
232
|
+
instance.pointerEventsFloatingElement?.style.removeProperty('pointer-events');
|
|
233
|
+
pointerEventsMutationOwnerByScopeElement.delete(scopeElement);
|
|
234
|
+
}
|
|
235
|
+
instance.performedPointerEventsMutation = false;
|
|
236
|
+
instance.pointerEventsScopeElement = null;
|
|
237
|
+
instance.pointerEventsReferenceElement = null;
|
|
238
|
+
instance.pointerEventsFloatingElement = null;
|
|
239
|
+
}
|
|
240
|
+
function applySafePolygonPointerEventsMutation(instance, options) {
|
|
241
|
+
const {
|
|
242
|
+
scopeElement,
|
|
243
|
+
referenceElement,
|
|
244
|
+
floatingElement
|
|
245
|
+
} = options;
|
|
246
|
+
const existingOwner = pointerEventsMutationOwnerByScopeElement.get(scopeElement);
|
|
247
|
+
if (existingOwner && existingOwner !== instance) {
|
|
248
|
+
clearSafePolygonPointerEventsMutation(existingOwner);
|
|
249
|
+
}
|
|
250
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
251
|
+
instance.performedPointerEventsMutation = true;
|
|
252
|
+
instance.pointerEventsScopeElement = scopeElement;
|
|
253
|
+
instance.pointerEventsReferenceElement = referenceElement;
|
|
254
|
+
instance.pointerEventsFloatingElement = floatingElement;
|
|
255
|
+
pointerEventsMutationOwnerByScopeElement.set(scopeElement, instance);
|
|
256
|
+
scopeElement.style.pointerEvents = 'none';
|
|
257
|
+
referenceElement.style.pointerEvents = 'auto';
|
|
258
|
+
floatingElement.style.pointerEvents = 'auto';
|
|
259
|
+
}
|
|
260
|
+
function useHoverInteractionSharedState(store) {
|
|
261
|
+
const data = store.context.dataRef.current;
|
|
262
|
+
const instance = useRefWithInit(() => data.hoverInteractionState ?? HoverInteraction.create()).current;
|
|
263
|
+
if (!data.hoverInteractionState) {
|
|
264
|
+
data.hoverInteractionState = instance;
|
|
265
|
+
}
|
|
266
|
+
useOnMount(data.hoverInteractionState.disposeEffect);
|
|
267
|
+
return data.hoverInteractionState;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Provides hover interactions that should be attached to the floating element.
|
|
272
|
+
*/
|
|
273
|
+
function useHoverFloatingInteraction(context, parameters = {}) {
|
|
274
|
+
const {
|
|
275
|
+
enabled = true,
|
|
276
|
+
closeDelay: closeDelayProp = 0,
|
|
277
|
+
nodeId: nodeIdProp
|
|
278
|
+
} = parameters;
|
|
279
|
+
const store = 'rootStore' in context ? context.rootStore : context;
|
|
280
|
+
const open = store.useState('open');
|
|
281
|
+
const floatingElement = store.useState('floatingElement');
|
|
282
|
+
const domReferenceElement = store.useState('domReferenceElement');
|
|
283
|
+
const {
|
|
284
|
+
dataRef
|
|
285
|
+
} = store.context;
|
|
286
|
+
const tree = useFloatingTree();
|
|
287
|
+
const parentId = useFloatingParentNodeId();
|
|
288
|
+
const instance = useHoverInteractionSharedState(store);
|
|
289
|
+
const childClosedTimeout = useTimeout();
|
|
290
|
+
const isClickLikeOpenEvent$1 = useStableCallback(() => {
|
|
291
|
+
return isClickLikeOpenEvent(dataRef.current.openEvent?.type, instance.interactedInside);
|
|
292
|
+
});
|
|
293
|
+
const isHoverOpen = useStableCallback(() => {
|
|
294
|
+
return isHoverOpenEvent(dataRef.current.openEvent?.type);
|
|
295
|
+
});
|
|
296
|
+
const clearPointerEvents = useStableCallback(() => {
|
|
297
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
298
|
+
});
|
|
299
|
+
useIsoLayoutEffect(() => {
|
|
300
|
+
if (!open) {
|
|
301
|
+
instance.pointerType = undefined;
|
|
302
|
+
instance.restTimeoutPending = false;
|
|
303
|
+
instance.interactedInside = false;
|
|
304
|
+
clearPointerEvents();
|
|
305
|
+
}
|
|
306
|
+
}, [open, instance, clearPointerEvents]);
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
return clearPointerEvents;
|
|
309
|
+
}, [clearPointerEvents]);
|
|
310
|
+
useIsoLayoutEffect(() => {
|
|
311
|
+
if (!enabled) {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
if (open && instance.handleCloseOptions?.blockPointerEvents && isHoverOpen() && isElement(domReferenceElement) && floatingElement) {
|
|
315
|
+
const ref = domReferenceElement;
|
|
316
|
+
const floatingEl = floatingElement;
|
|
317
|
+
const doc = ownerDocument(floatingElement);
|
|
318
|
+
const parentFloating = tree?.nodesRef.current.find(node => node.id === parentId)?.context?.elements.floating;
|
|
319
|
+
if (parentFloating) {
|
|
320
|
+
parentFloating.style.pointerEvents = '';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// A keep-mounted submenu can appear in the tree before it opens, so a
|
|
324
|
+
// cached scope or parent lookup may resolve to the submenu itself. That
|
|
325
|
+
// would not shield sibling items in the parent menu.
|
|
326
|
+
const cachedScopeElement = instance.pointerEventsScopeElement !== floatingEl ? instance.pointerEventsScopeElement : null;
|
|
327
|
+
const parentScopeElement = parentFloating !== floatingEl ? parentFloating : null;
|
|
328
|
+
const scopeElement = instance.handleCloseOptions?.getScope?.() ?? cachedScopeElement ?? parentScopeElement ?? ref.closest('[data-rootownerid]') ?? doc.body;
|
|
329
|
+
applySafePolygonPointerEventsMutation(instance, {
|
|
330
|
+
scopeElement,
|
|
331
|
+
referenceElement: ref,
|
|
332
|
+
floatingElement: floatingEl
|
|
333
|
+
});
|
|
334
|
+
return () => {
|
|
335
|
+
clearPointerEvents();
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return undefined;
|
|
339
|
+
}, [enabled, open, domReferenceElement, floatingElement, instance, isHoverOpen, tree, parentId, clearPointerEvents]);
|
|
340
|
+
React.useEffect(() => {
|
|
341
|
+
if (!enabled) {
|
|
342
|
+
return undefined;
|
|
343
|
+
}
|
|
344
|
+
function hasParentChildren() {
|
|
345
|
+
return !!(tree && parentId && getNodeChildren(tree.nodesRef.current, parentId).length > 0);
|
|
346
|
+
}
|
|
347
|
+
function closeWithDelay(event) {
|
|
348
|
+
const closeDelay = getDelay(closeDelayProp, 'close', instance.pointerType);
|
|
349
|
+
const close = () => {
|
|
350
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
351
|
+
tree?.events.emit('floating.closed', event);
|
|
352
|
+
};
|
|
353
|
+
if (closeDelay) {
|
|
354
|
+
instance.openChangeTimeout.start(closeDelay, close);
|
|
355
|
+
} else {
|
|
356
|
+
instance.openChangeTimeout.clear();
|
|
357
|
+
close();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
function handleInteractInside(event) {
|
|
361
|
+
const target = getTarget(event);
|
|
362
|
+
if (!isInteractiveElement(target)) {
|
|
363
|
+
instance.interactedInside = false;
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
instance.interactedInside = target?.closest('[aria-haspopup]') != null;
|
|
367
|
+
}
|
|
368
|
+
function onFloatingMouseEnter() {
|
|
369
|
+
instance.openChangeTimeout.clear();
|
|
370
|
+
childClosedTimeout.clear();
|
|
371
|
+
tree?.events.off('floating.closed', onNodeClosed);
|
|
372
|
+
clearPointerEvents();
|
|
373
|
+
}
|
|
374
|
+
function onFloatingMouseLeave(event) {
|
|
375
|
+
if (hasParentChildren() && tree) {
|
|
376
|
+
tree.events.on('floating.closed', onNodeClosed);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements)) {
|
|
380
|
+
// If the mouse is leaving the reference element to another trigger, don't explicitly close the popup
|
|
381
|
+
// as it will be moved.
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const currentNodeId = dataRef.current.floatingContext?.nodeId ?? nodeIdProp;
|
|
385
|
+
const relatedTarget = event.relatedTarget;
|
|
386
|
+
const isMovingIntoDescendantFloating = tree && currentNodeId && isElement(relatedTarget) && getNodeChildren(tree.nodesRef.current, currentNodeId, false).some(node => contains(node.context?.elements.floating, relatedTarget));
|
|
387
|
+
if (isMovingIntoDescendantFloating) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// If the safePolygon handler is active, let it handle the close logic.
|
|
392
|
+
if (instance.handler) {
|
|
393
|
+
instance.handler(event);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
clearPointerEvents();
|
|
397
|
+
if (isHoverOpen() && !isClickLikeOpenEvent$1()) {
|
|
398
|
+
closeWithDelay(event);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
function onNodeClosed(event) {
|
|
402
|
+
if (!tree || !parentId || hasParentChildren()) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
// Allow the mouseenter event to fire in case child was closed because mouse moved into parent.
|
|
406
|
+
childClosedTimeout.start(0, () => {
|
|
407
|
+
tree.events.off('floating.closed', onNodeClosed);
|
|
408
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
409
|
+
tree.events.emit('floating.closed', event);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
const floating = floatingElement;
|
|
413
|
+
return mergeCleanups(floating && addEventListener(floating, 'mouseenter', onFloatingMouseEnter), floating && addEventListener(floating, 'mouseleave', onFloatingMouseLeave), floating && addEventListener(floating, 'pointerdown', handleInteractInside, true), () => {
|
|
414
|
+
tree?.events.off('floating.closed', onNodeClosed);
|
|
415
|
+
});
|
|
416
|
+
}, [enabled, floatingElement, store, dataRef, closeDelayProp, nodeIdProp, isHoverOpen, isClickLikeOpenEvent$1, clearPointerEvents, instance, tree, parentId, childClosedTimeout]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const EMPTY_REF = {
|
|
420
|
+
current: null
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Provides hover interactions that should be attached to reference or trigger
|
|
425
|
+
* elements.
|
|
426
|
+
*/
|
|
427
|
+
function useHoverReferenceInteraction(context, props = {}) {
|
|
428
|
+
const {
|
|
429
|
+
enabled = true,
|
|
430
|
+
delay = 0,
|
|
431
|
+
handleClose = null,
|
|
432
|
+
mouseOnly = false,
|
|
433
|
+
restMs = 0,
|
|
434
|
+
move = true,
|
|
435
|
+
triggerElementRef = EMPTY_REF,
|
|
436
|
+
externalTree,
|
|
437
|
+
isActiveTrigger = true,
|
|
438
|
+
getHandleCloseContext,
|
|
439
|
+
isClosing,
|
|
440
|
+
shouldOpen: shouldOpenProp,
|
|
441
|
+
guardStaleOpen = false
|
|
442
|
+
} = props;
|
|
443
|
+
const store = 'rootStore' in context ? context.rootStore : context;
|
|
444
|
+
const {
|
|
445
|
+
dataRef,
|
|
446
|
+
events
|
|
447
|
+
} = store.context;
|
|
448
|
+
const tree = useFloatingTree(externalTree);
|
|
449
|
+
const instance = useHoverInteractionSharedState(store);
|
|
450
|
+
const isHoverCloseActiveRef = React.useRef(false);
|
|
451
|
+
const handleCloseRef = useValueAsRef(handleClose);
|
|
452
|
+
const delayRef = useValueAsRef(delay);
|
|
453
|
+
const restMsRef = useValueAsRef(restMs);
|
|
454
|
+
const enabledRef = useValueAsRef(enabled);
|
|
455
|
+
const shouldOpenRef = useValueAsRef(shouldOpenProp);
|
|
456
|
+
const isClosingRef = useValueAsRef(isClosing);
|
|
457
|
+
const isClickLikeOpenEvent$1 = useStableCallback(() => {
|
|
458
|
+
return isClickLikeOpenEvent(dataRef.current.openEvent?.type, instance.interactedInside);
|
|
459
|
+
});
|
|
460
|
+
const checkShouldOpen = useStableCallback(() => {
|
|
461
|
+
return shouldOpenRef.current?.() !== false;
|
|
462
|
+
});
|
|
463
|
+
const isOverInactiveTrigger = useStableCallback((currentDomReference, currentTarget, target) => {
|
|
464
|
+
const allTriggers = store.context.triggerElements;
|
|
465
|
+
|
|
466
|
+
// Fast path for normal usage where handlers are attached directly to triggers.
|
|
467
|
+
if (allTriggers.hasElement(currentTarget)) {
|
|
468
|
+
return !currentDomReference || !contains(currentDomReference, currentTarget);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Fallback for delegated/wrapper usage where currentTarget may be outside the trigger map.
|
|
472
|
+
if (!isElement(target)) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
const targetElement = target;
|
|
476
|
+
return allTriggers.hasMatchingElement(trigger => contains(trigger, targetElement)) && (!currentDomReference || !contains(currentDomReference, targetElement));
|
|
477
|
+
});
|
|
478
|
+
const cleanupMouseMoveHandler = useStableCallback(() => {
|
|
479
|
+
if (!instance.handler) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const doc = ownerDocument(store.select('domReferenceElement'));
|
|
483
|
+
doc.removeEventListener('mousemove', instance.handler);
|
|
484
|
+
instance.handler = undefined;
|
|
485
|
+
});
|
|
486
|
+
const clearPointerEvents = useStableCallback(() => {
|
|
487
|
+
clearSafePolygonPointerEventsMutation(instance);
|
|
488
|
+
});
|
|
489
|
+
if (isActiveTrigger) {
|
|
490
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
491
|
+
instance.handleCloseOptions = handleCloseRef.current?.__options;
|
|
492
|
+
}
|
|
493
|
+
React.useEffect(() => cleanupMouseMoveHandler, [cleanupMouseMoveHandler]);
|
|
494
|
+
|
|
495
|
+
// When closing before opening, clear the delay timeouts to cancel it
|
|
496
|
+
// from showing.
|
|
497
|
+
React.useEffect(() => {
|
|
498
|
+
if (!enabled) {
|
|
499
|
+
return undefined;
|
|
500
|
+
}
|
|
501
|
+
function onOpenChangeLocal(details) {
|
|
502
|
+
if (!details.open) {
|
|
503
|
+
isHoverCloseActiveRef.current = details.reason === triggerHover;
|
|
504
|
+
cleanupMouseMoveHandler();
|
|
505
|
+
instance.openChangeTimeout.clear();
|
|
506
|
+
instance.restTimeout.clear();
|
|
507
|
+
instance.blockMouseMove = true;
|
|
508
|
+
instance.restTimeoutPending = false;
|
|
509
|
+
} else {
|
|
510
|
+
isHoverCloseActiveRef.current = false;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
events.on('openchange', onOpenChangeLocal);
|
|
514
|
+
return () => {
|
|
515
|
+
events.off('openchange', onOpenChangeLocal);
|
|
516
|
+
};
|
|
517
|
+
}, [enabled, events, instance, cleanupMouseMoveHandler]);
|
|
518
|
+
React.useEffect(() => {
|
|
519
|
+
if (!enabled) {
|
|
520
|
+
return undefined;
|
|
521
|
+
}
|
|
522
|
+
function closeWithDelay(event, runElseBranch = true) {
|
|
523
|
+
const closeDelay = getDelay(delayRef.current, 'close', instance.pointerType);
|
|
524
|
+
if (closeDelay) {
|
|
525
|
+
instance.openChangeTimeout.start(closeDelay, () => {
|
|
526
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
527
|
+
tree?.events.emit('floating.closed', event);
|
|
528
|
+
});
|
|
529
|
+
} else if (runElseBranch) {
|
|
530
|
+
instance.openChangeTimeout.clear();
|
|
531
|
+
store.setOpen(false, createChangeEventDetails(triggerHover, event));
|
|
532
|
+
tree?.events.emit('floating.closed', event);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
const trigger = triggerElementRef.current ?? (isActiveTrigger ? store.select('domReferenceElement') : null);
|
|
536
|
+
if (!isElement(trigger)) {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
function onMouseEnter(event) {
|
|
540
|
+
instance.openChangeTimeout.clear();
|
|
541
|
+
instance.blockMouseMove = false;
|
|
542
|
+
if (mouseOnly && !isMouseLikePointerType(instance.pointerType)) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Only rest delay is set; there's no fallback delay.
|
|
547
|
+
// This will be handled by `onMouseMove`.
|
|
548
|
+
const restMsValue = getRestMs(restMsRef.current);
|
|
549
|
+
const openDelay = getDelay(delayRef.current, 'open', instance.pointerType);
|
|
550
|
+
const eventTarget = getTarget(event);
|
|
551
|
+
const currentTarget = event.currentTarget ?? null;
|
|
552
|
+
const currentDomReference = store.select('domReferenceElement');
|
|
553
|
+
let triggerNode = currentTarget;
|
|
554
|
+
|
|
555
|
+
// Wrapper/delegated mode: resolve the actual trigger from the event target.
|
|
556
|
+
if (isElement(eventTarget) && !store.context.triggerElements.hasElement(eventTarget)) {
|
|
557
|
+
for (const triggerElement of store.context.triggerElements.elements()) {
|
|
558
|
+
if (contains(triggerElement, eventTarget)) {
|
|
559
|
+
triggerNode = triggerElement;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Wrapper/delegated mode fallback: if the wrapper contains the active trigger,
|
|
566
|
+
// treat this as re-entering that active trigger.
|
|
567
|
+
if (isElement(currentTarget) && isElement(currentDomReference) && !store.context.triggerElements.hasElement(currentTarget) && contains(currentTarget, currentDomReference)) {
|
|
568
|
+
triggerNode = currentDomReference;
|
|
569
|
+
}
|
|
570
|
+
const isOverInactive = triggerNode == null ? false : isOverInactiveTrigger(currentDomReference, triggerNode, eventTarget);
|
|
571
|
+
const isOpen = store.select('open');
|
|
572
|
+
const isInClosingTransition = isClosingRef.current?.() ?? store.select('transitionStatus') === 'ending';
|
|
573
|
+
const isHoverCloseTransition = !isOpen && isInClosingTransition && isHoverCloseActiveRef.current;
|
|
574
|
+
const isReenteringSameTriggerDuringCloseTransition = !isOverInactive && isElement(triggerNode) && isElement(currentDomReference) && contains(currentDomReference, triggerNode) && isHoverCloseTransition;
|
|
575
|
+
const isRestOnlyDelay = restMsValue > 0 && !openDelay;
|
|
576
|
+
const shouldOpenImmediately = isOverInactive && (isOpen || isHoverCloseTransition) || isReenteringSameTriggerDuringCloseTransition;
|
|
577
|
+
const shouldOpen = !isOpen || isOverInactive;
|
|
578
|
+
|
|
579
|
+
// Open immediately when moving between triggers while open, or during
|
|
580
|
+
// a hover-driven close transition (including same-trigger re-entry).
|
|
581
|
+
if (shouldOpenImmediately) {
|
|
582
|
+
if (checkShouldOpen()) {
|
|
583
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
584
|
+
}
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (isRestOnlyDelay) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (openDelay) {
|
|
591
|
+
instance.openChangeTimeout.start(openDelay, () => {
|
|
592
|
+
if (shouldOpen && checkShouldOpen()) {
|
|
593
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
} else if (shouldOpen) {
|
|
597
|
+
if (checkShouldOpen()) {
|
|
598
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, event, triggerNode));
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function onMouseLeave(event) {
|
|
603
|
+
if (isClickLikeOpenEvent$1()) {
|
|
604
|
+
clearPointerEvents();
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
cleanupMouseMoveHandler();
|
|
608
|
+
const domReferenceElement = store.select('domReferenceElement');
|
|
609
|
+
const doc = ownerDocument(domReferenceElement);
|
|
610
|
+
instance.restTimeout.clear();
|
|
611
|
+
instance.restTimeoutPending = false;
|
|
612
|
+
const handleCloseContextBase = dataRef.current.floatingContext ?? getHandleCloseContext?.();
|
|
613
|
+
if (isTargetInsideEnabledTrigger(event.relatedTarget, store.context.triggerElements)) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (handleCloseRef.current && handleCloseContextBase) {
|
|
617
|
+
if (!store.select('open')) {
|
|
618
|
+
instance.openChangeTimeout.clear();
|
|
619
|
+
}
|
|
620
|
+
const currentTrigger = triggerElementRef.current;
|
|
621
|
+
instance.handler = handleCloseRef.current({
|
|
622
|
+
...handleCloseContextBase,
|
|
623
|
+
tree,
|
|
624
|
+
x: event.clientX,
|
|
625
|
+
y: event.clientY,
|
|
626
|
+
onClose() {
|
|
627
|
+
clearPointerEvents();
|
|
628
|
+
cleanupMouseMoveHandler();
|
|
629
|
+
if (enabledRef.current && !isClickLikeOpenEvent$1() && currentTrigger === store.select('domReferenceElement')) {
|
|
630
|
+
closeWithDelay(event, true);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
doc.addEventListener('mousemove', instance.handler);
|
|
635
|
+
instance.handler(event);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const shouldClose = instance.pointerType === 'touch' ? !contains(store.select('floatingElement'), event.relatedTarget) : true;
|
|
639
|
+
if (shouldClose) {
|
|
640
|
+
closeWithDelay(event);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Backup cancellation for Chrome's dropped `mouseleave` — see `guardStaleOpen`.
|
|
645
|
+
function onMouseOut(event) {
|
|
646
|
+
if (contains(trigger, event.relatedTarget)) {
|
|
647
|
+
return; // moved within the trigger's own subtree
|
|
648
|
+
}
|
|
649
|
+
instance.openChangeTimeout.clear();
|
|
650
|
+
instance.restTimeout.clear();
|
|
651
|
+
instance.restTimeoutPending = false;
|
|
652
|
+
}
|
|
653
|
+
const staleOpenGuard = guardStaleOpen ? addEventListener(trigger, 'mouseout', onMouseOut) : undefined;
|
|
654
|
+
if (move) {
|
|
655
|
+
return mergeCleanups(addEventListener(trigger, 'mousemove', onMouseEnter, {
|
|
656
|
+
once: true
|
|
657
|
+
}), addEventListener(trigger, 'mouseenter', onMouseEnter), addEventListener(trigger, 'mouseleave', onMouseLeave), staleOpenGuard);
|
|
658
|
+
}
|
|
659
|
+
return mergeCleanups(addEventListener(trigger, 'mouseenter', onMouseEnter), addEventListener(trigger, 'mouseleave', onMouseLeave), staleOpenGuard);
|
|
660
|
+
}, [cleanupMouseMoveHandler, clearPointerEvents, dataRef, delayRef, store, enabled, handleCloseRef, instance, isActiveTrigger, isOverInactiveTrigger, isClickLikeOpenEvent$1, mouseOnly, move, restMsRef, triggerElementRef, tree, enabledRef, getHandleCloseContext, isClosingRef, checkShouldOpen, guardStaleOpen]);
|
|
661
|
+
return React.useMemo(() => {
|
|
662
|
+
if (!enabled) {
|
|
663
|
+
return undefined;
|
|
664
|
+
}
|
|
665
|
+
function setPointerRef(event) {
|
|
666
|
+
instance.pointerType = event.pointerType;
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
onPointerDown: setPointerRef,
|
|
670
|
+
onPointerEnter: setPointerRef,
|
|
671
|
+
onMouseMove(event) {
|
|
672
|
+
const {
|
|
673
|
+
nativeEvent
|
|
674
|
+
} = event;
|
|
675
|
+
const trigger = event.currentTarget;
|
|
676
|
+
const currentDomReference = store.select('domReferenceElement');
|
|
677
|
+
const currentOpen = store.select('open');
|
|
678
|
+
const isOverInactive = isOverInactiveTrigger(currentDomReference, trigger, event.target);
|
|
679
|
+
if (mouseOnly && !isMouseLikePointerType(instance.pointerType)) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (currentOpen && isOverInactive && instance.handleCloseOptions?.blockPointerEvents) {
|
|
683
|
+
const floatingElement = store.select('floatingElement');
|
|
684
|
+
if (floatingElement) {
|
|
685
|
+
const scopeElement = instance.handleCloseOptions?.getScope?.() ?? trigger.ownerDocument.body;
|
|
686
|
+
applySafePolygonPointerEventsMutation(instance, {
|
|
687
|
+
scopeElement,
|
|
688
|
+
referenceElement: trigger,
|
|
689
|
+
floatingElement
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
const restMsValue = getRestMs(restMsRef.current);
|
|
694
|
+
if (currentOpen && !isOverInactive || restMsValue === 0) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (!isOverInactive && instance.restTimeoutPending && event.movementX ** 2 + event.movementY ** 2 < 2) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
instance.restTimeout.clear();
|
|
701
|
+
function handleMouseMove() {
|
|
702
|
+
instance.restTimeoutPending = false;
|
|
703
|
+
|
|
704
|
+
// A delayed hover open should not override a click-like open that happened
|
|
705
|
+
// while the hover delay was pending.
|
|
706
|
+
if (isClickLikeOpenEvent$1()) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const latestOpen = store.select('open');
|
|
710
|
+
if (!instance.blockMouseMove && (!latestOpen || isOverInactive) && checkShouldOpen()) {
|
|
711
|
+
store.setOpen(true, createChangeEventDetails(triggerHover, nativeEvent, trigger));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
if (instance.pointerType === 'touch') {
|
|
715
|
+
ReactDOM.flushSync(() => {
|
|
716
|
+
handleMouseMove();
|
|
717
|
+
});
|
|
718
|
+
} else if (isOverInactive && currentOpen) {
|
|
719
|
+
handleMouseMove();
|
|
720
|
+
} else {
|
|
721
|
+
instance.restTimeoutPending = true;
|
|
722
|
+
instance.restTimeout.start(restMsValue, handleMouseMove);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
}, [enabled, instance, isClickLikeOpenEvent$1, isOverInactiveTrigger, mouseOnly, store, restMsRef, checkShouldOpen]);
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/* eslint-disable no-nested-ternary */
|
|
730
|
+
|
|
731
|
+
const CURSOR_SPEED_THRESHOLD = 0.1;
|
|
732
|
+
const CURSOR_SPEED_THRESHOLD_SQUARED = CURSOR_SPEED_THRESHOLD * CURSOR_SPEED_THRESHOLD;
|
|
733
|
+
const POLYGON_BUFFER = 0.5;
|
|
734
|
+
function hasIntersectingEdge(pointX, pointY, xi, yi, xj, yj) {
|
|
735
|
+
return yi >= pointY !== yj >= pointY && pointX <= (xj - xi) * (pointY - yi) / (yj - yi) + xi;
|
|
736
|
+
}
|
|
737
|
+
function isPointInQuadrilateral(pointX, pointY, x1, y1, x2, y2, x3, y3, x4, y4) {
|
|
738
|
+
let isInsideValue = false;
|
|
739
|
+
if (hasIntersectingEdge(pointX, pointY, x1, y1, x2, y2)) {
|
|
740
|
+
isInsideValue = !isInsideValue;
|
|
741
|
+
}
|
|
742
|
+
if (hasIntersectingEdge(pointX, pointY, x2, y2, x3, y3)) {
|
|
743
|
+
isInsideValue = !isInsideValue;
|
|
744
|
+
}
|
|
745
|
+
if (hasIntersectingEdge(pointX, pointY, x3, y3, x4, y4)) {
|
|
746
|
+
isInsideValue = !isInsideValue;
|
|
747
|
+
}
|
|
748
|
+
if (hasIntersectingEdge(pointX, pointY, x4, y4, x1, y1)) {
|
|
749
|
+
isInsideValue = !isInsideValue;
|
|
750
|
+
}
|
|
751
|
+
return isInsideValue;
|
|
752
|
+
}
|
|
753
|
+
function isInsideRect(pointX, pointY, rect) {
|
|
754
|
+
return pointX >= rect.x && pointX <= rect.x + rect.width && pointY >= rect.y && pointY <= rect.y + rect.height;
|
|
755
|
+
}
|
|
756
|
+
function isInsideAxisAlignedRect(pointX, pointY, x1, y1, x2, y2) {
|
|
757
|
+
const minX = Math.min(x1, x2);
|
|
758
|
+
const maxX = Math.max(x1, x2);
|
|
759
|
+
const minY = Math.min(y1, y2);
|
|
760
|
+
const maxY = Math.max(y1, y2);
|
|
761
|
+
return pointX >= minX && pointX <= maxX && pointY >= minY && pointY <= maxY;
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Generates a safe polygon area that the user can traverse without closing the
|
|
765
|
+
* floating element once leaving the reference element.
|
|
766
|
+
* @see https://floating-ui.com/docs/useHover#safepolygon
|
|
767
|
+
*/
|
|
768
|
+
function safePolygon(options = {}) {
|
|
769
|
+
const {
|
|
770
|
+
blockPointerEvents = false
|
|
771
|
+
} = options;
|
|
772
|
+
const timeout = new Timeout();
|
|
773
|
+
const fn = ({
|
|
774
|
+
x,
|
|
775
|
+
y,
|
|
776
|
+
placement,
|
|
777
|
+
elements,
|
|
778
|
+
onClose,
|
|
779
|
+
nodeId,
|
|
780
|
+
tree
|
|
781
|
+
}) => {
|
|
782
|
+
const side = placement?.split('-')[0];
|
|
783
|
+
let hasLanded = false;
|
|
784
|
+
let lastX = null;
|
|
785
|
+
let lastY = null;
|
|
786
|
+
let lastCursorTime = typeof performance !== 'undefined' ? performance.now() : 0;
|
|
787
|
+
function isCursorMovingSlowly(nextX, nextY) {
|
|
788
|
+
const currentTime = performance.now();
|
|
789
|
+
const elapsedTime = currentTime - lastCursorTime;
|
|
790
|
+
if (lastX === null || lastY === null || elapsedTime === 0) {
|
|
791
|
+
lastX = nextX;
|
|
792
|
+
lastY = nextY;
|
|
793
|
+
lastCursorTime = currentTime;
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
const deltaX = nextX - lastX;
|
|
797
|
+
const deltaY = nextY - lastY;
|
|
798
|
+
const distanceSquared = deltaX * deltaX + deltaY * deltaY;
|
|
799
|
+
const thresholdSquared = elapsedTime * elapsedTime * CURSOR_SPEED_THRESHOLD_SQUARED;
|
|
800
|
+
lastX = nextX;
|
|
801
|
+
lastY = nextY;
|
|
802
|
+
lastCursorTime = currentTime;
|
|
803
|
+
return distanceSquared < thresholdSquared;
|
|
804
|
+
}
|
|
805
|
+
function close() {
|
|
806
|
+
timeout.clear();
|
|
807
|
+
onClose();
|
|
808
|
+
}
|
|
809
|
+
return function onMouseMove(event) {
|
|
810
|
+
timeout.clear();
|
|
811
|
+
const domReference = elements.domReference;
|
|
812
|
+
const floating = elements.floating;
|
|
813
|
+
if (!domReference || !floating || side == null || x == null || y == null) {
|
|
814
|
+
return undefined;
|
|
815
|
+
}
|
|
816
|
+
const {
|
|
817
|
+
clientX,
|
|
818
|
+
clientY
|
|
819
|
+
} = event;
|
|
820
|
+
const target = getTarget(event);
|
|
821
|
+
const isLeave = event.type === 'mouseleave';
|
|
822
|
+
const isOverFloatingEl = contains(floating, target);
|
|
823
|
+
const isOverReferenceEl = contains(domReference, target);
|
|
824
|
+
if (isOverFloatingEl) {
|
|
825
|
+
hasLanded = true;
|
|
826
|
+
if (!isLeave) {
|
|
827
|
+
return undefined;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
if (isOverReferenceEl) {
|
|
831
|
+
hasLanded = false;
|
|
832
|
+
if (!isLeave) {
|
|
833
|
+
hasLanded = true;
|
|
834
|
+
return undefined;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// Prevent overlapping floating element from being stuck in an open-close
|
|
839
|
+
// loop: https://github.com/floating-ui/floating-ui/issues/1910
|
|
840
|
+
if (isLeave && isElement(event.relatedTarget) && contains(floating, event.relatedTarget)) {
|
|
841
|
+
return undefined;
|
|
842
|
+
}
|
|
843
|
+
function hasOpenChildNode() {
|
|
844
|
+
return Boolean(tree && getNodeChildren(tree.nodesRef.current, nodeId).length > 0);
|
|
845
|
+
}
|
|
846
|
+
function closeIfNoOpenChild() {
|
|
847
|
+
if (!hasOpenChildNode()) {
|
|
848
|
+
close();
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// If any nested child is open, abort.
|
|
853
|
+
if (hasOpenChildNode()) {
|
|
854
|
+
return undefined;
|
|
855
|
+
}
|
|
856
|
+
const refRect = domReference.getBoundingClientRect();
|
|
857
|
+
const rect = floating.getBoundingClientRect();
|
|
858
|
+
const cursorLeaveFromRight = x > rect.right - rect.width / 2;
|
|
859
|
+
const cursorLeaveFromBottom = y > rect.bottom - rect.height / 2;
|
|
860
|
+
const isFloatingWider = rect.width > refRect.width;
|
|
861
|
+
const isFloatingTaller = rect.height > refRect.height;
|
|
862
|
+
const left = (isFloatingWider ? refRect : rect).left;
|
|
863
|
+
const right = (isFloatingWider ? refRect : rect).right;
|
|
864
|
+
const top = (isFloatingTaller ? refRect : rect).top;
|
|
865
|
+
const bottom = (isFloatingTaller ? refRect : rect).bottom;
|
|
866
|
+
|
|
867
|
+
// If the pointer is leaving from the opposite side, the "buffer" logic
|
|
868
|
+
// creates a point where the floating element remains open, but should be
|
|
869
|
+
// ignored.
|
|
870
|
+
// A constant of 1 handles floating point rounding errors.
|
|
871
|
+
if (side === 'top' && y >= refRect.bottom - 1 || side === 'bottom' && y <= refRect.top + 1 || side === 'left' && x >= refRect.right - 1 || side === 'right' && x <= refRect.left + 1) {
|
|
872
|
+
closeIfNoOpenChild();
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// Ignore when the cursor is within the rectangular trough between the
|
|
877
|
+
// two elements. Since the triangle is created from the cursor point,
|
|
878
|
+
// which can start beyond the ref element's edge, traversing back and
|
|
879
|
+
// forth from the ref to the floating element can cause it to close. This
|
|
880
|
+
// ensures it always remains open in that case.
|
|
881
|
+
let isInsideTroughRect = false;
|
|
882
|
+
switch (side) {
|
|
883
|
+
case 'top':
|
|
884
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, left, refRect.top + 1, right, rect.bottom - 1);
|
|
885
|
+
break;
|
|
886
|
+
case 'bottom':
|
|
887
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, left, rect.top + 1, right, refRect.bottom - 1);
|
|
888
|
+
break;
|
|
889
|
+
case 'left':
|
|
890
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, rect.right - 1, bottom, refRect.left + 1, top);
|
|
891
|
+
break;
|
|
892
|
+
case 'right':
|
|
893
|
+
isInsideTroughRect = isInsideAxisAlignedRect(clientX, clientY, refRect.right - 1, bottom, rect.left + 1, top);
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
if (isInsideTroughRect) {
|
|
897
|
+
return undefined;
|
|
898
|
+
}
|
|
899
|
+
if (hasLanded && !isInsideRect(clientX, clientY, refRect)) {
|
|
900
|
+
closeIfNoOpenChild();
|
|
901
|
+
return undefined;
|
|
902
|
+
}
|
|
903
|
+
if (!isLeave && isCursorMovingSlowly(clientX, clientY)) {
|
|
904
|
+
closeIfNoOpenChild();
|
|
905
|
+
return undefined;
|
|
906
|
+
}
|
|
907
|
+
let isInsidePolygon = false;
|
|
908
|
+
switch (side) {
|
|
909
|
+
case 'top':
|
|
910
|
+
{
|
|
911
|
+
const cursorXOffset = isFloatingWider ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
912
|
+
const cursorPointOneX = isFloatingWider ? x + cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
913
|
+
const cursorPointTwoX = isFloatingWider ? x - cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
914
|
+
const cursorPointY = y + POLYGON_BUFFER + 1;
|
|
915
|
+
const commonYLeft = cursorLeaveFromRight ? rect.bottom - POLYGON_BUFFER : isFloatingWider ? rect.bottom - POLYGON_BUFFER : rect.top;
|
|
916
|
+
const commonYRight = cursorLeaveFromRight ? isFloatingWider ? rect.bottom - POLYGON_BUFFER : rect.top : rect.bottom - POLYGON_BUFFER;
|
|
917
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointOneX, cursorPointY, cursorPointTwoX, cursorPointY, rect.left, commonYLeft, rect.right, commonYRight);
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
case 'bottom':
|
|
921
|
+
{
|
|
922
|
+
const cursorXOffset = isFloatingWider ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
923
|
+
const cursorPointOneX = isFloatingWider ? x + cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
924
|
+
const cursorPointTwoX = isFloatingWider ? x - cursorXOffset : cursorLeaveFromRight ? x + cursorXOffset : x - cursorXOffset;
|
|
925
|
+
const cursorPointY = y - POLYGON_BUFFER;
|
|
926
|
+
const commonYLeft = cursorLeaveFromRight ? rect.top + POLYGON_BUFFER : isFloatingWider ? rect.top + POLYGON_BUFFER : rect.bottom;
|
|
927
|
+
const commonYRight = cursorLeaveFromRight ? isFloatingWider ? rect.top + POLYGON_BUFFER : rect.bottom : rect.top + POLYGON_BUFFER;
|
|
928
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointOneX, cursorPointY, cursorPointTwoX, cursorPointY, rect.left, commonYLeft, rect.right, commonYRight);
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
case 'left':
|
|
932
|
+
{
|
|
933
|
+
const cursorYOffset = isFloatingTaller ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
934
|
+
const cursorPointOneY = isFloatingTaller ? y + cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
935
|
+
const cursorPointTwoY = isFloatingTaller ? y - cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
936
|
+
const cursorPointX = x + POLYGON_BUFFER + 1;
|
|
937
|
+
const commonXTop = cursorLeaveFromBottom ? rect.right - POLYGON_BUFFER : isFloatingTaller ? rect.right - POLYGON_BUFFER : rect.left;
|
|
938
|
+
const commonXBottom = cursorLeaveFromBottom ? isFloatingTaller ? rect.right - POLYGON_BUFFER : rect.left : rect.right - POLYGON_BUFFER;
|
|
939
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, commonXTop, rect.top, commonXBottom, rect.bottom, cursorPointX, cursorPointOneY, cursorPointX, cursorPointTwoY);
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
case 'right':
|
|
943
|
+
{
|
|
944
|
+
const cursorYOffset = isFloatingTaller ? POLYGON_BUFFER / 2 : POLYGON_BUFFER * 4;
|
|
945
|
+
const cursorPointOneY = isFloatingTaller ? y + cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
946
|
+
const cursorPointTwoY = isFloatingTaller ? y - cursorYOffset : cursorLeaveFromBottom ? y + cursorYOffset : y - cursorYOffset;
|
|
947
|
+
const cursorPointX = x - POLYGON_BUFFER;
|
|
948
|
+
const commonXTop = cursorLeaveFromBottom ? rect.left + POLYGON_BUFFER : isFloatingTaller ? rect.left + POLYGON_BUFFER : rect.right;
|
|
949
|
+
const commonXBottom = cursorLeaveFromBottom ? isFloatingTaller ? rect.left + POLYGON_BUFFER : rect.right : rect.left + POLYGON_BUFFER;
|
|
950
|
+
isInsidePolygon = isPointInQuadrilateral(clientX, clientY, cursorPointX, cursorPointOneY, cursorPointX, cursorPointTwoY, commonXTop, rect.top, commonXBottom, rect.bottom);
|
|
951
|
+
break;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (!isInsidePolygon) {
|
|
955
|
+
closeIfNoOpenChild();
|
|
956
|
+
} else if (!hasLanded) {
|
|
957
|
+
timeout.start(40, closeIfNoOpenChild);
|
|
958
|
+
}
|
|
959
|
+
return undefined;
|
|
960
|
+
};
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
964
|
+
fn.__options = {
|
|
965
|
+
...options,
|
|
966
|
+
blockPointerEvents
|
|
967
|
+
};
|
|
968
|
+
return fn;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
const MenuPositionerContext = /*#__PURE__*/React.createContext(undefined);
|
|
972
|
+
if (process.env.NODE_ENV !== "production") MenuPositionerContext.displayName = "MenuPositionerContext";
|
|
973
|
+
function useMenuPositionerContext(optional) {
|
|
974
|
+
const context = React.useContext(MenuPositionerContext);
|
|
975
|
+
if (context === undefined && !optional) {
|
|
976
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenuPositionerContext is missing. MenuPositioner parts must be placed within <Menu.Positioner>.' : formatErrorMessage(33));
|
|
977
|
+
}
|
|
978
|
+
return context;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
const MenuRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
982
|
+
if (process.env.NODE_ENV !== "production") MenuRootContext.displayName = "MenuRootContext";
|
|
983
|
+
function useMenuRootContext(optional) {
|
|
984
|
+
const context = React.useContext(MenuRootContext);
|
|
985
|
+
if (context === undefined && !optional) {
|
|
986
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenuRootContext is missing. Menu parts must be placed within <Menu.Root>.' : formatErrorMessage(36));
|
|
987
|
+
}
|
|
988
|
+
return context;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const ContextMenuRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
992
|
+
if (process.env.NODE_ENV !== "production") ContextMenuRootContext.displayName = "ContextMenuRootContext";
|
|
993
|
+
function useContextMenuRootContext(optional = true) {
|
|
994
|
+
const context = React.useContext(ContextMenuRootContext);
|
|
995
|
+
if (context === undefined && !optional) {
|
|
996
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: ContextMenuRootContext is missing. ContextMenu parts must be placed within <ContextMenu.Root>.' : formatErrorMessage(25));
|
|
997
|
+
}
|
|
998
|
+
return context;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* An overlay displayed beneath the menu popup.
|
|
1003
|
+
* Renders a `<div>` element.
|
|
1004
|
+
*
|
|
1005
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1006
|
+
*/
|
|
1007
|
+
const MenuBackdrop = /*#__PURE__*/React.forwardRef(function MenuBackdrop(componentProps, forwardedRef) {
|
|
1008
|
+
const {
|
|
1009
|
+
render,
|
|
1010
|
+
className,
|
|
1011
|
+
style,
|
|
1012
|
+
...elementProps
|
|
1013
|
+
} = componentProps;
|
|
1014
|
+
const {
|
|
1015
|
+
store
|
|
1016
|
+
} = useMenuRootContext();
|
|
1017
|
+
const open = store.useState('open');
|
|
1018
|
+
const mounted = store.useState('mounted');
|
|
1019
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
1020
|
+
const lastOpenChangeReason = store.useState('lastOpenChangeReason');
|
|
1021
|
+
const contextMenuContext = useContextMenuRootContext();
|
|
1022
|
+
const state = {
|
|
1023
|
+
open,
|
|
1024
|
+
transitionStatus
|
|
1025
|
+
};
|
|
1026
|
+
return useRenderElement('div', componentProps, {
|
|
1027
|
+
ref: contextMenuContext?.backdropRef ? [forwardedRef, contextMenuContext.backdropRef] : forwardedRef,
|
|
1028
|
+
state,
|
|
1029
|
+
stateAttributesMapping: popupTransitionStateMapping,
|
|
1030
|
+
props: [{
|
|
1031
|
+
role: 'presentation',
|
|
1032
|
+
hidden: !mounted,
|
|
1033
|
+
style: {
|
|
1034
|
+
pointerEvents: lastOpenChangeReason === triggerHover ? 'none' : undefined,
|
|
1035
|
+
userSelect: 'none',
|
|
1036
|
+
WebkitUserSelect: 'none'
|
|
1037
|
+
}
|
|
1038
|
+
}, elementProps]
|
|
1039
|
+
});
|
|
1040
|
+
});
|
|
1041
|
+
if (process.env.NODE_ENV !== "production") MenuBackdrop.displayName = "MenuBackdrop";
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* Returns common props shared by all menu item types.
|
|
1045
|
+
* This hook extracts the shared logic for id, role, tabIndex, onKeyDown,
|
|
1046
|
+
* onMouseMove, onClick, and onMouseUp handlers.
|
|
1047
|
+
*/
|
|
1048
|
+
function useMenuItemCommonProps(params) {
|
|
1049
|
+
const {
|
|
1050
|
+
closeOnClick,
|
|
1051
|
+
highlighted,
|
|
1052
|
+
id,
|
|
1053
|
+
nodeId,
|
|
1054
|
+
store,
|
|
1055
|
+
typingRef,
|
|
1056
|
+
itemRef,
|
|
1057
|
+
itemMetadata
|
|
1058
|
+
} = params;
|
|
1059
|
+
const {
|
|
1060
|
+
events: menuEvents
|
|
1061
|
+
} = store.useState('floatingTreeRoot');
|
|
1062
|
+
const open = store.useState('open');
|
|
1063
|
+
const contextMenuContext = useContextMenuRootContext(true);
|
|
1064
|
+
const isContextMenu = contextMenuContext !== undefined;
|
|
1065
|
+
return React.useMemo(() => ({
|
|
1066
|
+
id,
|
|
1067
|
+
role: 'menuitem',
|
|
1068
|
+
tabIndex: open && highlighted ? 0 : -1,
|
|
1069
|
+
onKeyDown(event) {
|
|
1070
|
+
if (event.key === ' ' && typingRef?.current) {
|
|
1071
|
+
event.preventDefault();
|
|
1072
|
+
}
|
|
1073
|
+
},
|
|
1074
|
+
onMouseMove(event) {
|
|
1075
|
+
if (!nodeId) {
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// Inform the floating tree that a menu item within this menu was hovered/moved over
|
|
1080
|
+
// so unrelated descendant submenus can be closed.
|
|
1081
|
+
menuEvents.emit('itemhover', {
|
|
1082
|
+
nodeId,
|
|
1083
|
+
target: event.currentTarget
|
|
1084
|
+
});
|
|
1085
|
+
},
|
|
1086
|
+
onClick(event) {
|
|
1087
|
+
if (closeOnClick) {
|
|
1088
|
+
menuEvents.emit('close', {
|
|
1089
|
+
domEvent: event,
|
|
1090
|
+
reason: itemPress
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
},
|
|
1094
|
+
onMouseUp(event) {
|
|
1095
|
+
if (contextMenuContext) {
|
|
1096
|
+
const initialCursorPoint = contextMenuContext.initialCursorPointRef.current;
|
|
1097
|
+
contextMenuContext.initialCursorPointRef.current = null;
|
|
1098
|
+
if (isContextMenu && initialCursorPoint && Math.abs(event.clientX - initialCursorPoint.x) <= 1 && Math.abs(event.clientY - initialCursorPoint.y) <= 1) {
|
|
1099
|
+
return;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// On non-macOS platforms, this mouseup belongs to the right-click gesture
|
|
1103
|
+
// that opened the context menu, so it must not activate an item.
|
|
1104
|
+
if (isContextMenu && !mac && event.button === 2) {
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
if (itemRef.current && store.context.allowMouseUpTriggerRef.current && (!isContextMenu || event.button === 2)) {
|
|
1109
|
+
// This fires whenever the user clicks on the trigger, moves the cursor, and releases it over the item.
|
|
1110
|
+
// We trigger the click and override the `closeOnClick` preference to always close the menu.
|
|
1111
|
+
if (itemMetadata.type === 'regular-item') {
|
|
1112
|
+
// `detail: 1` marks this as a mouse-gesture click so MenuRoot doesn't
|
|
1113
|
+
// treat it as a keyboard activation (`detail === 0` → `data-instant`).
|
|
1114
|
+
dispatchClickWithModifiers(itemRef.current, event, {
|
|
1115
|
+
detail: 1
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}), [closeOnClick, highlighted, id, menuEvents, nodeId, open, store, typingRef, itemRef, contextMenuContext, isContextMenu, itemMetadata]);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const REGULAR_ITEM = {
|
|
1124
|
+
type: 'regular-item'
|
|
1125
|
+
};
|
|
1126
|
+
function useMenuItem(params) {
|
|
1127
|
+
const {
|
|
1128
|
+
closeOnClick,
|
|
1129
|
+
disabled,
|
|
1130
|
+
highlighted,
|
|
1131
|
+
id,
|
|
1132
|
+
store,
|
|
1133
|
+
typingRef = store.context.typingRef,
|
|
1134
|
+
nativeButton,
|
|
1135
|
+
itemMetadata,
|
|
1136
|
+
nodeId
|
|
1137
|
+
} = params;
|
|
1138
|
+
const itemRef = React.useRef(null);
|
|
1139
|
+
const {
|
|
1140
|
+
getButtonProps,
|
|
1141
|
+
buttonRef
|
|
1142
|
+
} = useButton({
|
|
1143
|
+
disabled,
|
|
1144
|
+
focusableWhenDisabled: true,
|
|
1145
|
+
native: nativeButton,
|
|
1146
|
+
composite: true
|
|
1147
|
+
});
|
|
1148
|
+
const commonProps = useMenuItemCommonProps({
|
|
1149
|
+
closeOnClick,
|
|
1150
|
+
highlighted,
|
|
1151
|
+
id,
|
|
1152
|
+
nodeId,
|
|
1153
|
+
store,
|
|
1154
|
+
typingRef,
|
|
1155
|
+
itemRef,
|
|
1156
|
+
itemMetadata
|
|
1157
|
+
});
|
|
1158
|
+
const getItemProps = React.useCallback(externalProps => {
|
|
1159
|
+
return mergeProps(commonProps, {
|
|
1160
|
+
onMouseEnter() {
|
|
1161
|
+
if (itemMetadata.type !== 'submenu-trigger') {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
itemMetadata.setActive();
|
|
1165
|
+
}
|
|
1166
|
+
}, externalProps, getButtonProps);
|
|
1167
|
+
}, [commonProps, getButtonProps, itemMetadata]);
|
|
1168
|
+
const mergedRef = useMergedRefs(itemRef, buttonRef);
|
|
1169
|
+
return React.useMemo(() => ({
|
|
1170
|
+
getItemProps,
|
|
1171
|
+
itemRef: mergedRef
|
|
1172
|
+
}), [getItemProps, mergedRef]);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
let MenuCheckboxItemDataAttributes = /*#__PURE__*/function (MenuCheckboxItemDataAttributes) {
|
|
1176
|
+
/**
|
|
1177
|
+
* Present when the menu checkbox item is checked.
|
|
1178
|
+
*/
|
|
1179
|
+
MenuCheckboxItemDataAttributes["checked"] = "data-checked";
|
|
1180
|
+
/**
|
|
1181
|
+
* Present when the menu checkbox item is not checked.
|
|
1182
|
+
*/
|
|
1183
|
+
MenuCheckboxItemDataAttributes["unchecked"] = "data-unchecked";
|
|
1184
|
+
/**
|
|
1185
|
+
* Present when the menu checkbox item is disabled.
|
|
1186
|
+
*/
|
|
1187
|
+
MenuCheckboxItemDataAttributes["disabled"] = "data-disabled";
|
|
1188
|
+
/**
|
|
1189
|
+
* Present when the menu checkbox item is highlighted.
|
|
1190
|
+
*/
|
|
1191
|
+
MenuCheckboxItemDataAttributes["highlighted"] = "data-highlighted";
|
|
1192
|
+
return MenuCheckboxItemDataAttributes;
|
|
1193
|
+
}({});
|
|
1194
|
+
|
|
1195
|
+
const itemMapping = {
|
|
1196
|
+
checked(value) {
|
|
1197
|
+
if (value) {
|
|
1198
|
+
return {
|
|
1199
|
+
[MenuCheckboxItemDataAttributes.checked]: ''
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
return {
|
|
1203
|
+
[MenuCheckboxItemDataAttributes.unchecked]: ''
|
|
1204
|
+
};
|
|
1205
|
+
},
|
|
1206
|
+
...transitionStatusMapping
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
const MenuGroupContext = /*#__PURE__*/React.createContext(undefined);
|
|
1210
|
+
if (process.env.NODE_ENV !== "production") MenuGroupContext.displayName = "MenuGroupContext";
|
|
1211
|
+
function useMenuGroupRootContext() {
|
|
1212
|
+
const context = React.useContext(MenuGroupContext);
|
|
1213
|
+
if (context === undefined) {
|
|
1214
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenuGroupContext is missing. Menu group parts must be used within <Menu.Group> or <Menu.RadioGroup>.' : formatErrorMessage(31));
|
|
1215
|
+
}
|
|
1216
|
+
return context;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
const MenuGroup = /*#__PURE__*/React.forwardRef(function MenuGroup(componentProps, forwardedRef) {
|
|
1220
|
+
const {
|
|
1221
|
+
render,
|
|
1222
|
+
className,
|
|
1223
|
+
style,
|
|
1224
|
+
...elementProps
|
|
1225
|
+
} = componentProps;
|
|
1226
|
+
const [labelId, setLabelId] = React.useState(undefined);
|
|
1227
|
+
const element = useRenderElement('div', componentProps, {
|
|
1228
|
+
ref: forwardedRef,
|
|
1229
|
+
props: {
|
|
1230
|
+
role: 'group',
|
|
1231
|
+
'aria-labelledby': labelId,
|
|
1232
|
+
...elementProps
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
return /*#__PURE__*/jsx(MenuGroupContext.Provider, {
|
|
1236
|
+
value: setLabelId,
|
|
1237
|
+
children: element
|
|
1238
|
+
});
|
|
1239
|
+
});
|
|
1240
|
+
if (process.env.NODE_ENV !== "production") MenuGroup.displayName = "MenuGroup";
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* An accessible label that is automatically associated with its parent group.
|
|
1244
|
+
* Renders a `<div>` element.
|
|
1245
|
+
*
|
|
1246
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1247
|
+
*/
|
|
1248
|
+
const MenuGroupLabel = /*#__PURE__*/React.forwardRef(function MenuGroupLabel(componentProps, forwardedRef) {
|
|
1249
|
+
const {
|
|
1250
|
+
render,
|
|
1251
|
+
className,
|
|
1252
|
+
style,
|
|
1253
|
+
id: idProp,
|
|
1254
|
+
...elementProps
|
|
1255
|
+
} = componentProps;
|
|
1256
|
+
const id = useBaseUiId(idProp);
|
|
1257
|
+
const setLabelId = useMenuGroupRootContext();
|
|
1258
|
+
useIsoLayoutEffect(() => {
|
|
1259
|
+
setLabelId(id);
|
|
1260
|
+
return () => {
|
|
1261
|
+
setLabelId(currentId => currentId === id ? undefined : currentId);
|
|
1262
|
+
};
|
|
1263
|
+
}, [setLabelId, id]);
|
|
1264
|
+
return useRenderElement('div', componentProps, {
|
|
1265
|
+
ref: forwardedRef,
|
|
1266
|
+
props: {
|
|
1267
|
+
id,
|
|
1268
|
+
role: 'presentation',
|
|
1269
|
+
...elementProps
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
if (process.env.NODE_ENV !== "production") MenuGroupLabel.displayName = "MenuGroupLabel";
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* An individual interactive item in the menu.
|
|
1277
|
+
* Renders a `<div>` element.
|
|
1278
|
+
*
|
|
1279
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1280
|
+
*/
|
|
1281
|
+
const MenuItem = /*#__PURE__*/React.forwardRef(function MenuItem(componentProps, forwardedRef) {
|
|
1282
|
+
const {
|
|
1283
|
+
render,
|
|
1284
|
+
className,
|
|
1285
|
+
id: idProp,
|
|
1286
|
+
label,
|
|
1287
|
+
nativeButton = false,
|
|
1288
|
+
disabled: disabledProp = false,
|
|
1289
|
+
closeOnClick = true,
|
|
1290
|
+
style,
|
|
1291
|
+
...elementProps
|
|
1292
|
+
} = componentProps;
|
|
1293
|
+
const listItem = useCompositeListItem({
|
|
1294
|
+
guess: true,
|
|
1295
|
+
label
|
|
1296
|
+
});
|
|
1297
|
+
const menuPositionerContext = useMenuPositionerContext(true);
|
|
1298
|
+
const id = useBaseUiId(idProp);
|
|
1299
|
+
const {
|
|
1300
|
+
store
|
|
1301
|
+
} = useMenuRootContext();
|
|
1302
|
+
const rootDisabled = store.useState('disabled');
|
|
1303
|
+
const disabled = disabledProp || rootDisabled;
|
|
1304
|
+
const highlighted = store.useState('isActive', listItem.index);
|
|
1305
|
+
const itemProps = store.useState('itemProps');
|
|
1306
|
+
const {
|
|
1307
|
+
getItemProps,
|
|
1308
|
+
itemRef
|
|
1309
|
+
} = useMenuItem({
|
|
1310
|
+
closeOnClick,
|
|
1311
|
+
disabled,
|
|
1312
|
+
highlighted,
|
|
1313
|
+
id,
|
|
1314
|
+
store,
|
|
1315
|
+
nativeButton,
|
|
1316
|
+
nodeId: menuPositionerContext?.context.nodeId,
|
|
1317
|
+
itemMetadata: REGULAR_ITEM
|
|
1318
|
+
});
|
|
1319
|
+
const state = {
|
|
1320
|
+
disabled,
|
|
1321
|
+
highlighted
|
|
1322
|
+
};
|
|
1323
|
+
return useRenderElement('div', componentProps, {
|
|
1324
|
+
state,
|
|
1325
|
+
props: [itemProps, elementProps, getItemProps],
|
|
1326
|
+
ref: [itemRef, forwardedRef, listItem.ref]
|
|
1327
|
+
});
|
|
1328
|
+
});
|
|
1329
|
+
if (process.env.NODE_ENV !== "production") MenuItem.displayName = "MenuItem";
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* A link in the menu that can be used to navigate to a different page or section.
|
|
1333
|
+
* Renders an `<a>` element.
|
|
1334
|
+
*
|
|
1335
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1336
|
+
*/
|
|
1337
|
+
const MenuLinkItem = /*#__PURE__*/React.forwardRef(function MenuLinkItem(componentProps, forwardedRef) {
|
|
1338
|
+
const {
|
|
1339
|
+
render,
|
|
1340
|
+
className,
|
|
1341
|
+
id: idProp,
|
|
1342
|
+
label,
|
|
1343
|
+
closeOnClick = false,
|
|
1344
|
+
style,
|
|
1345
|
+
...elementProps
|
|
1346
|
+
} = componentProps;
|
|
1347
|
+
const linkRef = React.useRef(null);
|
|
1348
|
+
const listItem = useCompositeListItem({
|
|
1349
|
+
guess: true,
|
|
1350
|
+
label
|
|
1351
|
+
});
|
|
1352
|
+
const menuPositionerContext = useMenuPositionerContext(true);
|
|
1353
|
+
const nodeId = menuPositionerContext?.context.nodeId;
|
|
1354
|
+
const id = useBaseUiId(idProp);
|
|
1355
|
+
const {
|
|
1356
|
+
store
|
|
1357
|
+
} = useMenuRootContext();
|
|
1358
|
+
const highlighted = store.useState('isActive', listItem.index);
|
|
1359
|
+
const itemProps = store.useState('itemProps');
|
|
1360
|
+
const typingRef = store.context.typingRef;
|
|
1361
|
+
const {
|
|
1362
|
+
getButtonProps,
|
|
1363
|
+
buttonRef
|
|
1364
|
+
} = useButton({
|
|
1365
|
+
native: false,
|
|
1366
|
+
composite: true
|
|
1367
|
+
});
|
|
1368
|
+
const commonProps = useMenuItemCommonProps({
|
|
1369
|
+
closeOnClick,
|
|
1370
|
+
highlighted,
|
|
1371
|
+
id,
|
|
1372
|
+
nodeId,
|
|
1373
|
+
store,
|
|
1374
|
+
typingRef,
|
|
1375
|
+
itemRef: linkRef,
|
|
1376
|
+
itemMetadata: REGULAR_ITEM
|
|
1377
|
+
});
|
|
1378
|
+
function getItemProps(externalProps) {
|
|
1379
|
+
return mergeProps(commonProps, externalProps, getButtonProps);
|
|
1380
|
+
}
|
|
1381
|
+
const state = {
|
|
1382
|
+
highlighted
|
|
1383
|
+
};
|
|
1384
|
+
return useRenderElement('a', componentProps, {
|
|
1385
|
+
state,
|
|
1386
|
+
props: [itemProps, elementProps, getItemProps],
|
|
1387
|
+
ref: [linkRef, buttonRef, forwardedRef, listItem.ref]
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
if (process.env.NODE_ENV !== "production") MenuLinkItem.displayName = "MenuLinkItem";
|
|
1391
|
+
|
|
1392
|
+
const MenuPopup = /*#__PURE__*/React.forwardRef(function MenuPopup(componentProps, forwardedRef) {
|
|
1393
|
+
const {
|
|
1394
|
+
render,
|
|
1395
|
+
className,
|
|
1396
|
+
style,
|
|
1397
|
+
finalFocus,
|
|
1398
|
+
...elementProps
|
|
1399
|
+
} = componentProps;
|
|
1400
|
+
const {
|
|
1401
|
+
store
|
|
1402
|
+
} = useMenuRootContext();
|
|
1403
|
+
const {
|
|
1404
|
+
side,
|
|
1405
|
+
align
|
|
1406
|
+
} = useMenuPositionerContext();
|
|
1407
|
+
const insideToolbar = useToolbarRootContext(true) != null;
|
|
1408
|
+
const open = store.useState('open');
|
|
1409
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
1410
|
+
const popupProps = store.useState('popupProps');
|
|
1411
|
+
const mounted = store.useState('mounted');
|
|
1412
|
+
const instantType = store.useState('instantType');
|
|
1413
|
+
const activeTriggerElement = store.useState('activeTriggerElement');
|
|
1414
|
+
const parent = store.useState('parent');
|
|
1415
|
+
const lastOpenChangeReason = store.useState('lastOpenChangeReason');
|
|
1416
|
+
const rootId = store.useState('rootId');
|
|
1417
|
+
const floatingContext = store.useState('floatingRootContext');
|
|
1418
|
+
const floatingTreeRoot = store.useState('floatingTreeRoot');
|
|
1419
|
+
const closeDelay = store.useState('closeDelay');
|
|
1420
|
+
const hoverEnabled = store.useState('hoverEnabled');
|
|
1421
|
+
const disabled = store.useState('disabled');
|
|
1422
|
+
const openMethod = store.useState('openMethod');
|
|
1423
|
+
const isContextMenu = parent.type === 'context-menu';
|
|
1424
|
+
useOpenChangeComplete({
|
|
1425
|
+
open,
|
|
1426
|
+
ref: store.context.popupRef,
|
|
1427
|
+
onComplete() {
|
|
1428
|
+
if (open) {
|
|
1429
|
+
store.context.onOpenChangeComplete?.(true);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
React.useEffect(() => {
|
|
1434
|
+
function handleClose(event) {
|
|
1435
|
+
store.setOpen(false, createChangeEventDetails(event.reason, event.domEvent));
|
|
1436
|
+
}
|
|
1437
|
+
floatingTreeRoot.events.on('close', handleClose);
|
|
1438
|
+
return () => {
|
|
1439
|
+
floatingTreeRoot.events.off('close', handleClose);
|
|
1440
|
+
};
|
|
1441
|
+
}, [floatingTreeRoot.events, store]);
|
|
1442
|
+
useHoverFloatingInteraction(floatingContext, {
|
|
1443
|
+
enabled: hoverEnabled && !disabled && !isContextMenu && parent.type !== 'menubar',
|
|
1444
|
+
closeDelay
|
|
1445
|
+
});
|
|
1446
|
+
const setPopupElement = store.useStateSetter('popupElement');
|
|
1447
|
+
const state = {
|
|
1448
|
+
transitionStatus,
|
|
1449
|
+
side,
|
|
1450
|
+
align,
|
|
1451
|
+
open,
|
|
1452
|
+
nested: parent.type === 'menu',
|
|
1453
|
+
instant: instantType
|
|
1454
|
+
};
|
|
1455
|
+
const element = useRenderElement('div', componentProps, {
|
|
1456
|
+
state,
|
|
1457
|
+
ref: [forwardedRef, store.context.popupRef, setPopupElement],
|
|
1458
|
+
stateAttributesMapping: popupTransitionStateMapping,
|
|
1459
|
+
props: [popupProps, {
|
|
1460
|
+
onKeyDown(event) {
|
|
1461
|
+
if (insideToolbar && COMPOSITE_KEYS.has(event.key)) {
|
|
1462
|
+
event.stopPropagation();
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
}, getDisabledMountTransitionStyles(transitionStatus), elementProps, {
|
|
1466
|
+
'data-rootownerid': rootId
|
|
1467
|
+
}]
|
|
1468
|
+
});
|
|
1469
|
+
let returnFocus = parent.type === undefined || isContextMenu;
|
|
1470
|
+
if (activeTriggerElement || parent.type === 'menubar' && lastOpenChangeReason !== outsidePress) {
|
|
1471
|
+
returnFocus = true;
|
|
1472
|
+
}
|
|
1473
|
+
return /*#__PURE__*/jsx(FloatingFocusManager, {
|
|
1474
|
+
context: floatingContext,
|
|
1475
|
+
openInteractionType: openMethod,
|
|
1476
|
+
modal: isContextMenu,
|
|
1477
|
+
disabled: !mounted,
|
|
1478
|
+
returnFocus: finalFocus === undefined ? returnFocus : finalFocus,
|
|
1479
|
+
initialFocus: parent.type !== 'menu',
|
|
1480
|
+
restoreFocus: true,
|
|
1481
|
+
externalTree: parent.type !== 'menubar' ? floatingTreeRoot : undefined,
|
|
1482
|
+
previousFocusableElement: activeTriggerElement,
|
|
1483
|
+
nextFocusableElement: parent.type === undefined ? store.context.triggerFocusTargetRef : undefined,
|
|
1484
|
+
beforeContentFocusGuardRef: parent.type === undefined ? store.context.beforeContentFocusGuardRef : undefined,
|
|
1485
|
+
children: element
|
|
1486
|
+
});
|
|
1487
|
+
});
|
|
1488
|
+
if (process.env.NODE_ENV !== "production") MenuPopup.displayName = "MenuPopup";
|
|
1489
|
+
|
|
1490
|
+
const MenuPortalContext = /*#__PURE__*/React.createContext(undefined);
|
|
1491
|
+
if (process.env.NODE_ENV !== "production") MenuPortalContext.displayName = "MenuPortalContext";
|
|
1492
|
+
function useMenuPortalContext() {
|
|
1493
|
+
const value = React.useContext(MenuPortalContext);
|
|
1494
|
+
if (value === undefined) {
|
|
1495
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Menu.Portal> is missing.' : formatErrorMessage(32));
|
|
1496
|
+
}
|
|
1497
|
+
return value;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const MenuPortal = /*#__PURE__*/React.forwardRef(function MenuPortal(props, forwardedRef) {
|
|
1501
|
+
const {
|
|
1502
|
+
keepMounted = false,
|
|
1503
|
+
...portalProps
|
|
1504
|
+
} = props;
|
|
1505
|
+
const {
|
|
1506
|
+
store
|
|
1507
|
+
} = useMenuRootContext();
|
|
1508
|
+
const mounted = store.useState('mounted');
|
|
1509
|
+
const shouldRender = mounted || keepMounted;
|
|
1510
|
+
if (!shouldRender) {
|
|
1511
|
+
return null;
|
|
1512
|
+
}
|
|
1513
|
+
return /*#__PURE__*/jsx(MenuPortalContext.Provider, {
|
|
1514
|
+
value: keepMounted,
|
|
1515
|
+
children: /*#__PURE__*/jsx(FloatingPortal, {
|
|
1516
|
+
ref: forwardedRef,
|
|
1517
|
+
...portalProps
|
|
1518
|
+
})
|
|
1519
|
+
});
|
|
1520
|
+
});
|
|
1521
|
+
if (process.env.NODE_ENV !== "production") MenuPortal.displayName = "MenuPortal";
|
|
1522
|
+
|
|
1523
|
+
const MenuPositioner = /*#__PURE__*/React.forwardRef(function MenuPositioner(componentProps, forwardedRef) {
|
|
1524
|
+
const {
|
|
1525
|
+
anchor: anchorProp,
|
|
1526
|
+
positionMethod: positionMethodProp = 'absolute',
|
|
1527
|
+
className,
|
|
1528
|
+
render,
|
|
1529
|
+
side,
|
|
1530
|
+
align: alignProp,
|
|
1531
|
+
sideOffset: sideOffsetProp = 0,
|
|
1532
|
+
alignOffset: alignOffsetProp = 0,
|
|
1533
|
+
collisionBoundary = 'clipping-ancestors',
|
|
1534
|
+
collisionPadding = 5,
|
|
1535
|
+
arrowPadding = 5,
|
|
1536
|
+
sticky = false,
|
|
1537
|
+
disableAnchorTracking = false,
|
|
1538
|
+
collisionAvoidance: collisionAvoidanceProp = DROPDOWN_COLLISION_AVOIDANCE,
|
|
1539
|
+
style,
|
|
1540
|
+
...elementProps
|
|
1541
|
+
} = componentProps;
|
|
1542
|
+
const {
|
|
1543
|
+
store
|
|
1544
|
+
} = useMenuRootContext();
|
|
1545
|
+
const keepMounted = useMenuPortalContext();
|
|
1546
|
+
const contextMenuContext = useContextMenuRootContext(true);
|
|
1547
|
+
const parent = store.useState('parent');
|
|
1548
|
+
const floatingRootContext = store.useState('floatingRootContext');
|
|
1549
|
+
const floatingTreeRoot = store.useState('floatingTreeRoot');
|
|
1550
|
+
const mounted = store.useState('mounted');
|
|
1551
|
+
const open = store.useState('open');
|
|
1552
|
+
const modal = store.useState('modal');
|
|
1553
|
+
const openMethod = store.useState('openMethod');
|
|
1554
|
+
const triggerElement = store.useState('activeTriggerElement');
|
|
1555
|
+
const transitionStatus = store.useState('transitionStatus');
|
|
1556
|
+
const positionerElement = store.useState('positionerElement');
|
|
1557
|
+
const instantType = store.useState('instantType');
|
|
1558
|
+
const adaptiveOrigin = store.useState('adaptiveOrigin');
|
|
1559
|
+
const lastOpenChangeReason = store.useState('lastOpenChangeReason');
|
|
1560
|
+
const floatingNodeId = store.useState('floatingNodeId');
|
|
1561
|
+
const floatingParentNodeId = store.useState('floatingParentNodeId');
|
|
1562
|
+
const domReference = floatingRootContext.useState('domReferenceElement');
|
|
1563
|
+
const previousTriggerRef = React.useRef(null);
|
|
1564
|
+
const runOnceAnimationsFinish = useAnimationsFinished(positionerElement);
|
|
1565
|
+
let anchor = anchorProp;
|
|
1566
|
+
let sideOffset = sideOffsetProp;
|
|
1567
|
+
let alignOffset = alignOffsetProp;
|
|
1568
|
+
let align = alignProp;
|
|
1569
|
+
let collisionAvoidance = collisionAvoidanceProp;
|
|
1570
|
+
if (parent.type === 'context-menu') {
|
|
1571
|
+
anchor = anchorProp ?? parent.context?.anchor;
|
|
1572
|
+
align = align ?? 'start';
|
|
1573
|
+
if (!side && align !== 'center') {
|
|
1574
|
+
alignOffset = componentProps.alignOffset ?? 2;
|
|
1575
|
+
sideOffset = componentProps.sideOffset ?? -5;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
let computedSide = side;
|
|
1579
|
+
let computedAlign = align;
|
|
1580
|
+
if (parent.type === 'menu') {
|
|
1581
|
+
computedSide = computedSide ?? 'inline-end';
|
|
1582
|
+
computedAlign = computedAlign ?? 'start';
|
|
1583
|
+
collisionAvoidance = componentProps.collisionAvoidance ?? POPUP_COLLISION_AVOIDANCE;
|
|
1584
|
+
} else if (parent.type === 'menubar') {
|
|
1585
|
+
computedSide = computedSide ?? (parent.context.orientation === 'vertical' ? 'inline-end' : 'bottom');
|
|
1586
|
+
computedAlign = computedAlign ?? 'start';
|
|
1587
|
+
}
|
|
1588
|
+
const contextMenu = parent.type === 'context-menu';
|
|
1589
|
+
const positioner = useAnchorPositioning({
|
|
1590
|
+
anchor,
|
|
1591
|
+
floatingRootContext,
|
|
1592
|
+
positionMethod: contextMenuContext ? 'fixed' : positionMethodProp,
|
|
1593
|
+
mounted,
|
|
1594
|
+
side: computedSide,
|
|
1595
|
+
sideOffset,
|
|
1596
|
+
align: computedAlign,
|
|
1597
|
+
alignOffset,
|
|
1598
|
+
arrowPadding: contextMenu ? 0 : arrowPadding,
|
|
1599
|
+
collisionBoundary,
|
|
1600
|
+
collisionPadding,
|
|
1601
|
+
sticky,
|
|
1602
|
+
nodeId: floatingNodeId,
|
|
1603
|
+
keepMounted,
|
|
1604
|
+
disableAnchorTracking,
|
|
1605
|
+
collisionAvoidance,
|
|
1606
|
+
shift: contextMenu ? {
|
|
1607
|
+
crossAxis: !('side' in collisionAvoidance && collisionAvoidance.side === 'flip'),
|
|
1608
|
+
rootBoundary: 'layoutViewport'
|
|
1609
|
+
} : undefined,
|
|
1610
|
+
externalTree: floatingTreeRoot,
|
|
1611
|
+
adaptiveOrigin
|
|
1612
|
+
});
|
|
1613
|
+
React.useEffect(() => {
|
|
1614
|
+
function onMenuOpenChange(details) {
|
|
1615
|
+
if (details.open) {
|
|
1616
|
+
if (details.parentNodeId === floatingNodeId) {
|
|
1617
|
+
store.set('hoverEnabled', false);
|
|
1618
|
+
}
|
|
1619
|
+
if (details.nodeId !== floatingNodeId && details.parentNodeId === store.select('floatingParentNodeId')) {
|
|
1620
|
+
store.setOpen(false, createChangeEventDetails(siblingOpen));
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
floatingTreeRoot.events.on('menuopenchange', onMenuOpenChange);
|
|
1625
|
+
return () => {
|
|
1626
|
+
floatingTreeRoot.events.off('menuopenchange', onMenuOpenChange);
|
|
1627
|
+
};
|
|
1628
|
+
}, [store, floatingTreeRoot.events, floatingNodeId]);
|
|
1629
|
+
React.useEffect(() => {
|
|
1630
|
+
if (store.select('floatingParentNodeId') == null) {
|
|
1631
|
+
return undefined;
|
|
1632
|
+
}
|
|
1633
|
+
function onParentClose(details) {
|
|
1634
|
+
if (details.open || details.nodeId !== store.select('floatingParentNodeId')) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const reason = details.reason ?? siblingOpen;
|
|
1638
|
+
store.setOpen(false, createChangeEventDetails(reason));
|
|
1639
|
+
}
|
|
1640
|
+
floatingTreeRoot.events.on('menuopenchange', onParentClose);
|
|
1641
|
+
return () => {
|
|
1642
|
+
floatingTreeRoot.events.off('menuopenchange', onParentClose);
|
|
1643
|
+
};
|
|
1644
|
+
}, [floatingTreeRoot.events, store]);
|
|
1645
|
+
const closeTimeout = useTimeout();
|
|
1646
|
+
|
|
1647
|
+
// Clear pending close timeout when the menu closes.
|
|
1648
|
+
React.useEffect(() => {
|
|
1649
|
+
if (!open) {
|
|
1650
|
+
closeTimeout.clear();
|
|
1651
|
+
}
|
|
1652
|
+
}, [open, closeTimeout]);
|
|
1653
|
+
|
|
1654
|
+
// Close unrelated child submenus when hovering a different item in the parent menu.
|
|
1655
|
+
React.useEffect(() => {
|
|
1656
|
+
function onItemHover(event) {
|
|
1657
|
+
// If an item within our parent menu is hovered, and this menu's trigger is not that item,
|
|
1658
|
+
// close this submenu. This ensures hovering a different item in the parent closes other branches.
|
|
1659
|
+
if (!open || event.nodeId !== store.select('floatingParentNodeId')) {
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
if (event.target && triggerElement && triggerElement !== event.target) {
|
|
1663
|
+
const delay = store.select('closeDelay');
|
|
1664
|
+
if (delay > 0) {
|
|
1665
|
+
if (!closeTimeout.isStarted()) {
|
|
1666
|
+
closeTimeout.start(delay, () => {
|
|
1667
|
+
store.setOpen(false, createChangeEventDetails(siblingOpen));
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
} else {
|
|
1671
|
+
store.setOpen(false, createChangeEventDetails(siblingOpen));
|
|
1672
|
+
}
|
|
1673
|
+
} else {
|
|
1674
|
+
// User re-hovered the submenu trigger, cancel pending close.
|
|
1675
|
+
closeTimeout.clear();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
floatingTreeRoot.events.on('itemhover', onItemHover);
|
|
1679
|
+
return () => {
|
|
1680
|
+
floatingTreeRoot.events.off('itemhover', onItemHover);
|
|
1681
|
+
};
|
|
1682
|
+
}, [floatingTreeRoot.events, open, triggerElement, store, closeTimeout]);
|
|
1683
|
+
React.useEffect(() => {
|
|
1684
|
+
const eventDetails = {
|
|
1685
|
+
open,
|
|
1686
|
+
nodeId: floatingNodeId,
|
|
1687
|
+
parentNodeId: floatingParentNodeId,
|
|
1688
|
+
reason: store.select('lastOpenChangeReason')
|
|
1689
|
+
};
|
|
1690
|
+
floatingTreeRoot.events.emit('menuopenchange', eventDetails);
|
|
1691
|
+
}, [floatingTreeRoot.events, open, store, floatingNodeId, floatingParentNodeId]);
|
|
1692
|
+
|
|
1693
|
+
// Keep positioner transition behavior aligned with Popover when switching detached triggers.
|
|
1694
|
+
useIsoLayoutEffect(() => {
|
|
1695
|
+
const currentTrigger = domReference;
|
|
1696
|
+
const previousTrigger = previousTriggerRef.current;
|
|
1697
|
+
if (currentTrigger) {
|
|
1698
|
+
previousTriggerRef.current = currentTrigger;
|
|
1699
|
+
}
|
|
1700
|
+
if (previousTrigger && currentTrigger && currentTrigger !== previousTrigger) {
|
|
1701
|
+
store.set('instantType', undefined);
|
|
1702
|
+
const abortController = new AbortController();
|
|
1703
|
+
runOnceAnimationsFinish(() => {
|
|
1704
|
+
store.set('instantType', 'trigger-change');
|
|
1705
|
+
}, abortController.signal);
|
|
1706
|
+
return () => {
|
|
1707
|
+
abortController.abort();
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
return undefined;
|
|
1711
|
+
}, [domReference, runOnceAnimationsFinish, store]);
|
|
1712
|
+
const state = {
|
|
1713
|
+
open,
|
|
1714
|
+
side: positioner.side,
|
|
1715
|
+
align: positioner.align,
|
|
1716
|
+
anchorHidden: positioner.anchorHidden,
|
|
1717
|
+
nested: parent.type === 'menu',
|
|
1718
|
+
instant: instantType
|
|
1719
|
+
};
|
|
1720
|
+
const menubarModal = parent.type === 'menubar' && parent.context.modal;
|
|
1721
|
+
const popupModal = modal && lastOpenChangeReason !== triggerHover;
|
|
1722
|
+
useAnchoredPopupScrollLock(open && (menubarModal || popupModal), openMethod === 'touch', positionerElement, triggerElement);
|
|
1723
|
+
const element = usePositioner(componentProps, state, {
|
|
1724
|
+
styles: positioner.positionerStyles,
|
|
1725
|
+
transitionStatus,
|
|
1726
|
+
props: elementProps,
|
|
1727
|
+
refs: [forwardedRef, store.useStateSetter('positionerElement')],
|
|
1728
|
+
hidden: !mounted,
|
|
1729
|
+
inert: !open
|
|
1730
|
+
});
|
|
1731
|
+
const shouldRenderBackdrop = mounted && parent.type !== 'menu' && (parent.type !== 'menubar' && modal && lastOpenChangeReason !== triggerHover || parent.type === 'menubar' && parent.context.modal);
|
|
1732
|
+
|
|
1733
|
+
// cuts a hole in the backdrop to allow pointer interaction with the menubar or dropdown menu trigger element
|
|
1734
|
+
let backdropCutout = null;
|
|
1735
|
+
if (parent.type === 'menubar') {
|
|
1736
|
+
backdropCutout = parent.context.contentElement;
|
|
1737
|
+
} else if (parent.type === undefined) {
|
|
1738
|
+
backdropCutout = triggerElement;
|
|
1739
|
+
}
|
|
1740
|
+
return /*#__PURE__*/jsxs(MenuPositionerContext.Provider, {
|
|
1741
|
+
value: positioner,
|
|
1742
|
+
children: [shouldRenderBackdrop && /*#__PURE__*/jsx(InternalBackdrop, {
|
|
1743
|
+
ref: parent.type === 'context-menu' || parent.type === 'nested-context-menu' ? parent.context.internalBackdropRef : null,
|
|
1744
|
+
inert: inertValue(!open),
|
|
1745
|
+
cutout: backdropCutout
|
|
1746
|
+
}), /*#__PURE__*/jsx(FloatingNode, {
|
|
1747
|
+
id: floatingNodeId,
|
|
1748
|
+
children: /*#__PURE__*/jsx(CompositeList, {
|
|
1749
|
+
elementsRef: store.context.itemDomElements,
|
|
1750
|
+
labelsRef: store.context.itemLabels,
|
|
1751
|
+
children: element
|
|
1752
|
+
})
|
|
1753
|
+
})]
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
1756
|
+
if (process.env.NODE_ENV !== "production") MenuPositioner.displayName = "MenuPositioner";
|
|
1757
|
+
|
|
1758
|
+
const MenuRadioGroupContext = /*#__PURE__*/React.createContext(undefined);
|
|
1759
|
+
if (process.env.NODE_ENV !== "production") MenuRadioGroupContext.displayName = "MenuRadioGroupContext";
|
|
1760
|
+
function useMenuRadioGroupContext() {
|
|
1761
|
+
const context = React.useContext(MenuRadioGroupContext);
|
|
1762
|
+
if (context === undefined) {
|
|
1763
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenuRadioGroupContext is missing. MenuRadioGroup parts must be placed within <Menu.RadioGroup>.' : formatErrorMessage(34));
|
|
1764
|
+
}
|
|
1765
|
+
return context;
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
/**
|
|
1769
|
+
* Groups related radio items.
|
|
1770
|
+
* Renders a `<div>` element.
|
|
1771
|
+
*
|
|
1772
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1773
|
+
*/
|
|
1774
|
+
const MenuRadioGroup = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef(function MenuRadioGroup(componentProps, forwardedRef) {
|
|
1775
|
+
const {
|
|
1776
|
+
render,
|
|
1777
|
+
className,
|
|
1778
|
+
value: valueProp,
|
|
1779
|
+
defaultValue,
|
|
1780
|
+
onValueChange: onValueChangeProp,
|
|
1781
|
+
disabled = false,
|
|
1782
|
+
style,
|
|
1783
|
+
'aria-labelledby': ariaLabelledByProp,
|
|
1784
|
+
...elementProps
|
|
1785
|
+
} = componentProps;
|
|
1786
|
+
const [labelId, setLabelId] = React.useState(undefined);
|
|
1787
|
+
const [value, setValueUnwrapped] = useControlled({
|
|
1788
|
+
controlled: valueProp,
|
|
1789
|
+
default: defaultValue,
|
|
1790
|
+
name: 'MenuRadioGroup'
|
|
1791
|
+
});
|
|
1792
|
+
const setValue = useStableCallback((newValue, eventDetails) => {
|
|
1793
|
+
onValueChangeProp?.(newValue, eventDetails);
|
|
1794
|
+
if (eventDetails.isCanceled) {
|
|
1795
|
+
return;
|
|
1796
|
+
}
|
|
1797
|
+
setValueUnwrapped(newValue);
|
|
1798
|
+
});
|
|
1799
|
+
const state = {
|
|
1800
|
+
disabled
|
|
1801
|
+
};
|
|
1802
|
+
const element = useRenderElement('div', componentProps, {
|
|
1803
|
+
state,
|
|
1804
|
+
ref: forwardedRef,
|
|
1805
|
+
props: {
|
|
1806
|
+
role: 'group',
|
|
1807
|
+
'aria-labelledby': ariaLabelledByProp ?? labelId,
|
|
1808
|
+
'aria-disabled': disabled || undefined,
|
|
1809
|
+
...elementProps
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
const context = React.useMemo(() => ({
|
|
1813
|
+
value,
|
|
1814
|
+
setValue,
|
|
1815
|
+
disabled
|
|
1816
|
+
}), [value, setValue, disabled]);
|
|
1817
|
+
return /*#__PURE__*/jsx(MenuGroupContext.Provider, {
|
|
1818
|
+
value: setLabelId,
|
|
1819
|
+
children: /*#__PURE__*/jsx(MenuRadioGroupContext.Provider, {
|
|
1820
|
+
value: context,
|
|
1821
|
+
children: element
|
|
1822
|
+
})
|
|
1823
|
+
});
|
|
1824
|
+
}));
|
|
1825
|
+
if (process.env.NODE_ENV !== "production") MenuRadioGroup.displayName = "MenuRadioGroup";
|
|
1826
|
+
|
|
1827
|
+
const MenuRadioItemContext = /*#__PURE__*/React.createContext(undefined);
|
|
1828
|
+
if (process.env.NODE_ENV !== "production") MenuRadioItemContext.displayName = "MenuRadioItemContext";
|
|
1829
|
+
function useMenuRadioItemContext() {
|
|
1830
|
+
const context = React.useContext(MenuRadioItemContext);
|
|
1831
|
+
if (context === undefined) {
|
|
1832
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenuRadioItemContext is missing. MenuRadioItem parts must be placed within <Menu.RadioItem>.' : formatErrorMessage(35));
|
|
1833
|
+
}
|
|
1834
|
+
return context;
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
const MenuRadioItem = /*#__PURE__*/React.forwardRef(function MenuRadioItem(componentProps, forwardedRef) {
|
|
1838
|
+
const {
|
|
1839
|
+
render,
|
|
1840
|
+
className,
|
|
1841
|
+
id: idProp,
|
|
1842
|
+
label,
|
|
1843
|
+
nativeButton = false,
|
|
1844
|
+
disabled: disabledProp = false,
|
|
1845
|
+
closeOnClick = false,
|
|
1846
|
+
value,
|
|
1847
|
+
style,
|
|
1848
|
+
...elementProps
|
|
1849
|
+
} = componentProps;
|
|
1850
|
+
const listItem = useCompositeListItem({
|
|
1851
|
+
guess: true,
|
|
1852
|
+
label
|
|
1853
|
+
});
|
|
1854
|
+
const menuPositionerContext = useMenuPositionerContext(true);
|
|
1855
|
+
const id = useBaseUiId(idProp);
|
|
1856
|
+
const {
|
|
1857
|
+
store
|
|
1858
|
+
} = useMenuRootContext();
|
|
1859
|
+
const highlighted = store.useState('isActive', listItem.index);
|
|
1860
|
+
const itemProps = store.useState('itemProps');
|
|
1861
|
+
const {
|
|
1862
|
+
value: selectedValue,
|
|
1863
|
+
setValue: setSelectedValue,
|
|
1864
|
+
disabled: groupDisabled
|
|
1865
|
+
} = useMenuRadioGroupContext();
|
|
1866
|
+
const rootDisabled = store.useState('disabled');
|
|
1867
|
+
const disabled = disabledProp || groupDisabled || rootDisabled;
|
|
1868
|
+
const checked = selectedValue === value;
|
|
1869
|
+
const {
|
|
1870
|
+
getItemProps,
|
|
1871
|
+
itemRef
|
|
1872
|
+
} = useMenuItem({
|
|
1873
|
+
closeOnClick,
|
|
1874
|
+
disabled,
|
|
1875
|
+
highlighted,
|
|
1876
|
+
id,
|
|
1877
|
+
store,
|
|
1878
|
+
nativeButton,
|
|
1879
|
+
nodeId: menuPositionerContext?.context.nodeId,
|
|
1880
|
+
itemMetadata: REGULAR_ITEM
|
|
1881
|
+
});
|
|
1882
|
+
const state = React.useMemo(() => ({
|
|
1883
|
+
disabled,
|
|
1884
|
+
highlighted,
|
|
1885
|
+
checked
|
|
1886
|
+
}), [disabled, highlighted, checked]);
|
|
1887
|
+
function handleClick(event) {
|
|
1888
|
+
const details = createChangeEventDetails(itemPress, event.nativeEvent, undefined, {
|
|
1889
|
+
preventUnmountOnClose: NOOP
|
|
1890
|
+
});
|
|
1891
|
+
setSelectedValue(value, details);
|
|
1892
|
+
}
|
|
1893
|
+
const element = useRenderElement('div', componentProps, {
|
|
1894
|
+
state,
|
|
1895
|
+
stateAttributesMapping: itemMapping,
|
|
1896
|
+
props: [itemProps, {
|
|
1897
|
+
role: 'menuitemradio',
|
|
1898
|
+
'aria-checked': checked,
|
|
1899
|
+
onClick: handleClick
|
|
1900
|
+
}, elementProps, getItemProps],
|
|
1901
|
+
ref: [itemRef, forwardedRef, listItem.ref]
|
|
1902
|
+
});
|
|
1903
|
+
return /*#__PURE__*/jsx(MenuRadioItemContext.Provider, {
|
|
1904
|
+
value: state,
|
|
1905
|
+
children: element
|
|
1906
|
+
});
|
|
1907
|
+
});
|
|
1908
|
+
if (process.env.NODE_ENV !== "production") MenuRadioItem.displayName = "MenuRadioItem";
|
|
1909
|
+
|
|
1910
|
+
/**
|
|
1911
|
+
* Indicates whether the radio item is selected.
|
|
1912
|
+
* Renders a `<span>` element.
|
|
1913
|
+
*
|
|
1914
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
1915
|
+
*/
|
|
1916
|
+
const MenuRadioItemIndicator = /*#__PURE__*/React.forwardRef(function MenuRadioItemIndicator(componentProps, forwardedRef) {
|
|
1917
|
+
const {
|
|
1918
|
+
render,
|
|
1919
|
+
className,
|
|
1920
|
+
style,
|
|
1921
|
+
keepMounted = false,
|
|
1922
|
+
...elementProps
|
|
1923
|
+
} = componentProps;
|
|
1924
|
+
const item = useMenuRadioItemContext();
|
|
1925
|
+
const indicatorRef = React.useRef(null);
|
|
1926
|
+
const {
|
|
1927
|
+
transitionStatus,
|
|
1928
|
+
mounted,
|
|
1929
|
+
setMounted
|
|
1930
|
+
} = useTransitionStatus(item.checked);
|
|
1931
|
+
useOpenChangeComplete({
|
|
1932
|
+
open: item.checked,
|
|
1933
|
+
ref: indicatorRef,
|
|
1934
|
+
onComplete() {
|
|
1935
|
+
if (!item.checked) {
|
|
1936
|
+
setMounted(false);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
});
|
|
1940
|
+
const state = {
|
|
1941
|
+
checked: item.checked,
|
|
1942
|
+
disabled: item.disabled,
|
|
1943
|
+
highlighted: item.highlighted,
|
|
1944
|
+
transitionStatus
|
|
1945
|
+
};
|
|
1946
|
+
const element = useRenderElement('span', componentProps, {
|
|
1947
|
+
state,
|
|
1948
|
+
stateAttributesMapping: itemMapping,
|
|
1949
|
+
ref: [forwardedRef, indicatorRef],
|
|
1950
|
+
props: {
|
|
1951
|
+
'aria-hidden': true,
|
|
1952
|
+
...elementProps
|
|
1953
|
+
},
|
|
1954
|
+
enabled: keepMounted || mounted
|
|
1955
|
+
});
|
|
1956
|
+
return element;
|
|
1957
|
+
});
|
|
1958
|
+
if (process.env.NODE_ENV !== "production") MenuRadioItemIndicator.displayName = "MenuRadioItemIndicator";
|
|
1959
|
+
|
|
1960
|
+
const MenubarContext = /*#__PURE__*/React.createContext(null);
|
|
1961
|
+
if (process.env.NODE_ENV !== "production") MenubarContext.displayName = "MenubarContext";
|
|
1962
|
+
function useMenubarContext(optional) {
|
|
1963
|
+
const context = React.useContext(MenubarContext);
|
|
1964
|
+
if (context === null && !optional) {
|
|
1965
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: MenubarContext is missing. Menubar parts must be placed within <Menubar>.' : formatErrorMessage(5));
|
|
1966
|
+
}
|
|
1967
|
+
return context;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
const selectors = {
|
|
1971
|
+
...popupStoreSelectors,
|
|
1972
|
+
disabled: state => state.parent.type === 'menubar' ? state.parent.context.disabled || state.disabled : state.disabled,
|
|
1973
|
+
modal: state => (state.parent.type === undefined || state.parent.type === 'context-menu') && (state.modal ?? true),
|
|
1974
|
+
openMethod: state => state.openMethod,
|
|
1975
|
+
allowMouseEnter: state => state.allowMouseEnter,
|
|
1976
|
+
highlightItemOnHover: state => state.highlightItemOnHover,
|
|
1977
|
+
parent: state => state.parent,
|
|
1978
|
+
rootId: state => {
|
|
1979
|
+
if (state.parent.type === 'menu') {
|
|
1980
|
+
return state.parent.store.select('rootId');
|
|
1981
|
+
}
|
|
1982
|
+
return state.parent.type !== undefined ? state.parent.context.rootId : state.rootId;
|
|
1983
|
+
},
|
|
1984
|
+
activeIndex: state => state.activeIndex,
|
|
1985
|
+
isActive: (state, itemIndex) => state.activeIndex === itemIndex,
|
|
1986
|
+
hoverEnabled: state => state.hoverEnabled,
|
|
1987
|
+
instantType: state => state.instantType,
|
|
1988
|
+
lastOpenChangeReason: state => state.openChangeReason,
|
|
1989
|
+
floatingTreeRoot: state => {
|
|
1990
|
+
if (state.parent.type === 'menu') {
|
|
1991
|
+
return state.parent.store.select('floatingTreeRoot');
|
|
1992
|
+
}
|
|
1993
|
+
return state.floatingTreeRoot;
|
|
1994
|
+
},
|
|
1995
|
+
floatingNodeId: state => state.floatingNodeId,
|
|
1996
|
+
floatingParentNodeId: state => state.floatingParentNodeId,
|
|
1997
|
+
itemProps: state => state.itemProps,
|
|
1998
|
+
closeDelay: state => state.closeDelay,
|
|
1999
|
+
adaptiveOrigin: state => state.adaptiveOrigin,
|
|
2000
|
+
keyboardEventRelay: state => {
|
|
2001
|
+
if (state.keyboardEventRelay) {
|
|
2002
|
+
return state.keyboardEventRelay;
|
|
2003
|
+
}
|
|
2004
|
+
if (state.parent.type === 'menu') {
|
|
2005
|
+
return state.parent.store.select('keyboardEventRelay');
|
|
2006
|
+
}
|
|
2007
|
+
return undefined;
|
|
2008
|
+
}
|
|
2009
|
+
};
|
|
2010
|
+
|
|
2011
|
+
/**
|
|
2012
|
+
* The store view that detached handle-backed triggers read from. Both the real `MenuStore` and the
|
|
2013
|
+
* inert fallback store satisfy it, so a trigger can read from whichever store the handle currently
|
|
2014
|
+
* exposes. Narrowed to the members a trigger actually uses — the trigger-data members plus `setOpen`
|
|
2015
|
+
* (called by the focus guards) — so the exposed surface can't bypass the open-change pipeline; on
|
|
2016
|
+
* the detached fallback store every one of these mutations is a no-op.
|
|
2017
|
+
*/
|
|
2018
|
+
|
|
2019
|
+
class MenuStore extends ReactStore {
|
|
2020
|
+
constructor(initialState) {
|
|
2021
|
+
super({
|
|
2022
|
+
...createInitialState(),
|
|
2023
|
+
...initialState
|
|
2024
|
+
}, createInitialContext(), selectors);
|
|
2025
|
+
|
|
2026
|
+
// Set up propagation of state from parent menu if applicable.
|
|
2027
|
+
this.unsubscribeParentListener = this.observe('parent', parent => {
|
|
2028
|
+
this.unsubscribeParentListener?.();
|
|
2029
|
+
if (parent.type === 'menu') {
|
|
2030
|
+
let rootId = parent.store.select('rootId');
|
|
2031
|
+
let floatingTreeRoot = parent.store.select('floatingTreeRoot');
|
|
2032
|
+
let keyboardEventRelay = parent.store.select('keyboardEventRelay');
|
|
2033
|
+
this.unsubscribeParentListener = parent.store.subscribe(() => {
|
|
2034
|
+
const nextRootId = parent.store.select('rootId');
|
|
2035
|
+
const nextFloatingTreeRoot = parent.store.select('floatingTreeRoot');
|
|
2036
|
+
const nextKeyboardEventRelay = parent.store.select('keyboardEventRelay');
|
|
2037
|
+
if (rootId === nextRootId && floatingTreeRoot === nextFloatingTreeRoot && keyboardEventRelay === nextKeyboardEventRelay) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2040
|
+
rootId = nextRootId;
|
|
2041
|
+
floatingTreeRoot = nextFloatingTreeRoot;
|
|
2042
|
+
keyboardEventRelay = nextKeyboardEventRelay;
|
|
2043
|
+
this.notifyAll();
|
|
2044
|
+
});
|
|
2045
|
+
this.context.allowMouseUpTriggerRef = parent.store.context.allowMouseUpTriggerRef;
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
if (parent.type !== undefined) {
|
|
2049
|
+
this.context.allowMouseUpTriggerRef = parent.context.allowMouseUpTriggerRef;
|
|
2050
|
+
}
|
|
2051
|
+
this.unsubscribeParentListener = null;
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
setOpen(open, eventDetails) {
|
|
2055
|
+
this.state.floatingRootContext.context.events.emit('setOpen', {
|
|
2056
|
+
open,
|
|
2057
|
+
eventDetails
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2060
|
+
unsubscribeParentListener = null;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Creates the inert fallback store used by detached handle-backed triggers while no `Menu.Root` is
|
|
2065
|
+
* attached. It preserves a menu-specific trigger registry in context so detached triggers can
|
|
2066
|
+
* register before migrating to the live root store. `setOpen` is a no-op (matching the inert
|
|
2067
|
+
* reads/writes of `NullStore`), so a trigger can hand the store to focus-guard helpers that expect
|
|
2068
|
+
* `setOpen` without it ever taking effect while detached.
|
|
2069
|
+
*/
|
|
2070
|
+
function createNullMenuStore() {
|
|
2071
|
+
const store = new NullStore(Object.freeze(createInitialState()), Object.freeze(createInitialContext()), selectors);
|
|
2072
|
+
return Object.assign(store, {
|
|
2073
|
+
setOpen: NOOP
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
function createInitialContext() {
|
|
2077
|
+
return {
|
|
2078
|
+
positionerRef: /*#__PURE__*/React.createRef(),
|
|
2079
|
+
popupRef: /*#__PURE__*/React.createRef(),
|
|
2080
|
+
typingRef: {
|
|
2081
|
+
current: false
|
|
2082
|
+
},
|
|
2083
|
+
itemDomElements: {
|
|
2084
|
+
current: []
|
|
2085
|
+
},
|
|
2086
|
+
itemLabels: {
|
|
2087
|
+
current: []
|
|
2088
|
+
},
|
|
2089
|
+
allowMouseUpTriggerRef: {
|
|
2090
|
+
current: false
|
|
2091
|
+
},
|
|
2092
|
+
triggerFocusTargetRef: /*#__PURE__*/React.createRef(),
|
|
2093
|
+
beforeContentFocusGuardRef: /*#__PURE__*/React.createRef(),
|
|
2094
|
+
onOpenChangeComplete: undefined,
|
|
2095
|
+
triggerElements: new PopupTriggerMap()
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
function createInitialState() {
|
|
2099
|
+
return {
|
|
2100
|
+
...createInitialPopupStoreState(),
|
|
2101
|
+
disabled: false,
|
|
2102
|
+
modal: true,
|
|
2103
|
+
openMethod: null,
|
|
2104
|
+
allowMouseEnter: false,
|
|
2105
|
+
highlightItemOnHover: true,
|
|
2106
|
+
parent: {
|
|
2107
|
+
type: undefined
|
|
2108
|
+
},
|
|
2109
|
+
rootId: undefined,
|
|
2110
|
+
activeIndex: null,
|
|
2111
|
+
hoverEnabled: true,
|
|
2112
|
+
instantType: undefined,
|
|
2113
|
+
openChangeReason: null,
|
|
2114
|
+
floatingTreeRoot: new FloatingTreeStore(),
|
|
2115
|
+
floatingNodeId: undefined,
|
|
2116
|
+
floatingParentNodeId: null,
|
|
2117
|
+
itemProps: EMPTY_OBJECT,
|
|
2118
|
+
keyboardEventRelay: undefined,
|
|
2119
|
+
closeDelay: 0,
|
|
2120
|
+
adaptiveOrigin: undefined
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
const MenuSubmenuRootContext = /*#__PURE__*/React.createContext(undefined);
|
|
2125
|
+
if (process.env.NODE_ENV !== "production") MenuSubmenuRootContext.displayName = "MenuSubmenuRootContext";
|
|
2126
|
+
function useMenuSubmenuRootContext() {
|
|
2127
|
+
return React.useContext(MenuSubmenuRootContext);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
const MenuRoot = fastComponent(function MenuRoot(props) {
|
|
2131
|
+
const {
|
|
2132
|
+
children,
|
|
2133
|
+
open: openProp,
|
|
2134
|
+
onOpenChange,
|
|
2135
|
+
onOpenChangeComplete,
|
|
2136
|
+
defaultOpen = false,
|
|
2137
|
+
disabled: disabledProp = false,
|
|
2138
|
+
modal: modalProp,
|
|
2139
|
+
loopFocus = true,
|
|
2140
|
+
orientation = 'vertical',
|
|
2141
|
+
actionsRef,
|
|
2142
|
+
closeParentOnEsc = false,
|
|
2143
|
+
handle,
|
|
2144
|
+
triggerId: triggerIdProp,
|
|
2145
|
+
defaultTriggerId: defaultTriggerIdProp = null,
|
|
2146
|
+
highlightItemOnHover = true
|
|
2147
|
+
} = props;
|
|
2148
|
+
const contextMenuContext = useContextMenuRootContext(true);
|
|
2149
|
+
const parentMenuRootContext = useMenuRootContext(true);
|
|
2150
|
+
const menubarContext = useMenubarContext(true);
|
|
2151
|
+
const isSubmenu = useMenuSubmenuRootContext();
|
|
2152
|
+
const parentFromContext = React.useMemo(() => {
|
|
2153
|
+
if (isSubmenu && parentMenuRootContext) {
|
|
2154
|
+
return {
|
|
2155
|
+
type: 'menu',
|
|
2156
|
+
store: parentMenuRootContext.store
|
|
2157
|
+
};
|
|
2158
|
+
}
|
|
2159
|
+
if (menubarContext) {
|
|
2160
|
+
return {
|
|
2161
|
+
type: 'menubar',
|
|
2162
|
+
context: menubarContext
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
// Ensure this is not a Menu nested inside ContextMenu.Trigger.
|
|
2167
|
+
// ContextMenu parentContext is always undefined as ContextMenu.Root is instantiated with
|
|
2168
|
+
// <MenuRootContext.Provider value={undefined}>
|
|
2169
|
+
if (contextMenuContext && !parentMenuRootContext) {
|
|
2170
|
+
return {
|
|
2171
|
+
type: 'context-menu',
|
|
2172
|
+
context: contextMenuContext
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
return {
|
|
2176
|
+
type: undefined
|
|
2177
|
+
};
|
|
2178
|
+
}, [contextMenuContext, parentMenuRootContext, menubarContext, isSubmenu]);
|
|
2179
|
+
const store = useMenuRootStore({
|
|
2180
|
+
open: defaultOpen,
|
|
2181
|
+
openProp,
|
|
2182
|
+
activeTriggerId: defaultTriggerIdProp,
|
|
2183
|
+
triggerIdProp,
|
|
2184
|
+
parent: parentFromContext
|
|
2185
|
+
});
|
|
2186
|
+
store.useControlledProp('openProp', openProp);
|
|
2187
|
+
store.useControlledProp('triggerIdProp', triggerIdProp);
|
|
2188
|
+
store.useContextCallback('onOpenChangeComplete', onOpenChangeComplete);
|
|
2189
|
+
const rootId = useId();
|
|
2190
|
+
const floatingId = useId();
|
|
2191
|
+
const floatingTreeRoot = store.useState('floatingTreeRoot');
|
|
2192
|
+
const floatingNodeIdFromContext = useFloatingNodeId(floatingTreeRoot);
|
|
2193
|
+
const floatingParentNodeIdFromContext = useFloatingParentNodeId();
|
|
2194
|
+
const open = store.useState('open');
|
|
2195
|
+
const activeTriggerElement = store.useState('activeTriggerElement');
|
|
2196
|
+
const positionerElement = store.useState('positionerElement');
|
|
2197
|
+
const hoverEnabled = store.useState('hoverEnabled');
|
|
2198
|
+
const disabled = store.useState('disabled');
|
|
2199
|
+
const lastOpenChangeReason = store.useState('lastOpenChangeReason');
|
|
2200
|
+
const parent = store.useState('parent');
|
|
2201
|
+
const activeIndex = store.useState('activeIndex');
|
|
2202
|
+
const payload = store.useState('payload');
|
|
2203
|
+
const floatingParentNodeId = store.useState('floatingParentNodeId');
|
|
2204
|
+
const openEventRef = React.useRef(null);
|
|
2205
|
+
const allowOutsidePressDismissalRef = React.useRef(parent.type !== 'context-menu');
|
|
2206
|
+
const allowOutsidePressDismissalTimeout = useTimeout();
|
|
2207
|
+
const allowTouchToCloseRef = React.useRef(true);
|
|
2208
|
+
const allowTouchToCloseTimeout = useTimeout();
|
|
2209
|
+
const nested = floatingParentNodeId != null;
|
|
2210
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2211
|
+
if (parent.type !== undefined && modalProp !== undefined) {
|
|
2212
|
+
console.warn('Base UI: The `modal` prop is not supported on nested menus. It will be ignored.');
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
const {
|
|
2216
|
+
openMethod,
|
|
2217
|
+
triggerProps: interactionTypeProps
|
|
2218
|
+
} = useOpenInteractionType(open);
|
|
2219
|
+
store.useSyncedValues({
|
|
2220
|
+
disabled: disabledProp,
|
|
2221
|
+
highlightItemOnHover,
|
|
2222
|
+
modal: parent.type === undefined ? modalProp : undefined,
|
|
2223
|
+
openMethod,
|
|
2224
|
+
rootId
|
|
2225
|
+
});
|
|
2226
|
+
useImplicitActiveTrigger(store);
|
|
2227
|
+
const {
|
|
2228
|
+
forceUnmount
|
|
2229
|
+
} = useOpenStateTransitions(open, store, () => {
|
|
2230
|
+
store.set('allowMouseEnter', false);
|
|
2231
|
+
});
|
|
2232
|
+
useIsoLayoutEffect(() => {
|
|
2233
|
+
if (contextMenuContext && !parentMenuRootContext) {
|
|
2234
|
+
// This is a context menu root.
|
|
2235
|
+
// It doesn't support detached triggers yet, so we have to sync the parent context manually.
|
|
2236
|
+
store.update({
|
|
2237
|
+
parent: {
|
|
2238
|
+
type: 'context-menu',
|
|
2239
|
+
context: contextMenuContext
|
|
2240
|
+
},
|
|
2241
|
+
floatingNodeId: floatingNodeIdFromContext,
|
|
2242
|
+
floatingParentNodeId: floatingParentNodeIdFromContext
|
|
2243
|
+
});
|
|
2244
|
+
} else if (parentMenuRootContext) {
|
|
2245
|
+
store.update({
|
|
2246
|
+
floatingNodeId: floatingNodeIdFromContext,
|
|
2247
|
+
floatingParentNodeId: floatingParentNodeIdFromContext
|
|
2248
|
+
});
|
|
2249
|
+
}
|
|
2250
|
+
}, [contextMenuContext, parentMenuRootContext, floatingNodeIdFromContext, floatingParentNodeIdFromContext, store]);
|
|
2251
|
+
React.useEffect(() => {
|
|
2252
|
+
if (!open) {
|
|
2253
|
+
openEventRef.current = null;
|
|
2254
|
+
}
|
|
2255
|
+
if (parent.type !== 'context-menu') {
|
|
2256
|
+
return;
|
|
2257
|
+
}
|
|
2258
|
+
if (!open) {
|
|
2259
|
+
allowOutsidePressDismissalTimeout.clear();
|
|
2260
|
+
allowOutsidePressDismissalRef.current = false;
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// With `mousedown` outside press events and long press touch input, there
|
|
2265
|
+
// needs to be a grace period after opening to ensure the dismissal event
|
|
2266
|
+
// doesn't fire immediately after open.
|
|
2267
|
+
allowOutsidePressDismissalTimeout.start(500, () => {
|
|
2268
|
+
allowOutsidePressDismissalRef.current = true;
|
|
2269
|
+
});
|
|
2270
|
+
}, [allowOutsidePressDismissalTimeout, open, parent.type]);
|
|
2271
|
+
useIsoLayoutEffect(() => {
|
|
2272
|
+
if (!open && !hoverEnabled) {
|
|
2273
|
+
store.set('hoverEnabled', true);
|
|
2274
|
+
}
|
|
2275
|
+
}, [open, hoverEnabled, store]);
|
|
2276
|
+
const setOpen = useStableCallback((nextOpen, eventDetails) => {
|
|
2277
|
+
const reason = eventDetails.reason;
|
|
2278
|
+
|
|
2279
|
+
// Read the store directly, as relayed tree events and stale hover timers can request
|
|
2280
|
+
// a close after the state changed but before this component re-rendered.
|
|
2281
|
+
if (!nextOpen && !store.select('open')) {
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
if (open === nextOpen && eventDetails.trigger === activeTriggerElement && lastOpenChangeReason === reason) {
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
const shouldPreventUnmountOnClose = attachPreventUnmountOnClose(eventDetails);
|
|
2288
|
+
|
|
2289
|
+
// Do not immediately reset the activeTriggerId to allow
|
|
2290
|
+
// exit animations to play and focus to be returned correctly.
|
|
2291
|
+
if (!nextOpen && eventDetails.trigger == null) {
|
|
2292
|
+
eventDetails.trigger = activeTriggerElement ?? undefined;
|
|
2293
|
+
}
|
|
2294
|
+
onOpenChange?.(nextOpen, eventDetails);
|
|
2295
|
+
if (eventDetails.isCanceled) {
|
|
2296
|
+
return;
|
|
2297
|
+
}
|
|
2298
|
+
store.state.floatingRootContext.dispatchOpenChange(nextOpen, eventDetails);
|
|
2299
|
+
const nativeEvent = eventDetails.event;
|
|
2300
|
+
if (nextOpen === false && nativeEvent?.type === 'click' && nativeEvent.pointerType === 'touch' && !allowTouchToCloseRef.current) {
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// Prevent the menu from closing on mobile devices that have a delayed click event.
|
|
2305
|
+
// In some cases the menu, when tapped, will fire the focus event first and then the click event.
|
|
2306
|
+
// Without this guard, the menu will close immediately after opening.
|
|
2307
|
+
if (nextOpen && reason === triggerFocus) {
|
|
2308
|
+
allowTouchToCloseRef.current = false;
|
|
2309
|
+
allowTouchToCloseTimeout.start(300, () => {
|
|
2310
|
+
allowTouchToCloseRef.current = true;
|
|
2311
|
+
});
|
|
2312
|
+
} else {
|
|
2313
|
+
allowTouchToCloseRef.current = true;
|
|
2314
|
+
allowTouchToCloseTimeout.clear();
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
// Keyboard and assistive-technology activations produce `detail === 0` clicks;
|
|
2318
|
+
// mouse-gesture clicks (including the synthesized drag-release click from
|
|
2319
|
+
// `useMenuItemCommonProps`) carry `detail >= 1`.
|
|
2320
|
+
const isKeyboardClick = (reason === triggerPress || reason === itemPress) && nativeEvent.detail === 0;
|
|
2321
|
+
const isDismissClose = !nextOpen && (reason === escapeKey || reason == null);
|
|
2322
|
+
const updatedState = {
|
|
2323
|
+
open: nextOpen,
|
|
2324
|
+
openChangeReason: reason
|
|
2325
|
+
};
|
|
2326
|
+
openEventRef.current = eventDetails.event;
|
|
2327
|
+
setPopupOpenState(updatedState, nextOpen, eventDetails.trigger, shouldPreventUnmountOnClose());
|
|
2328
|
+
store.update(updatedState);
|
|
2329
|
+
if (parent.type === 'menubar' && (reason === triggerFocus || reason === focusOut || reason === triggerHover || reason === listNavigation || reason === siblingOpen)) {
|
|
2330
|
+
store.set('instantType', 'group');
|
|
2331
|
+
} else if (isKeyboardClick || isDismissClose) {
|
|
2332
|
+
store.set('instantType', isKeyboardClick ? 'click' : 'dismiss');
|
|
2333
|
+
} else {
|
|
2334
|
+
store.set('instantType', undefined);
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
const floatingRootContext = useSyncedFloatingRootContext({
|
|
2338
|
+
popupStore: store,
|
|
2339
|
+
floatingId,
|
|
2340
|
+
nested: floatingParentNodeIdFromContext != null,
|
|
2341
|
+
onOpenChange: setOpen
|
|
2342
|
+
});
|
|
2343
|
+
const floatingEvents = floatingRootContext.context.events;
|
|
2344
|
+
|
|
2345
|
+
// Registered in a layout effect (not a passive one) so `setOpen` emits from imperative
|
|
2346
|
+
// `MenuHandle.open()` calls made in the same commit this root mounts — e.g. from another layout
|
|
2347
|
+
// effect during a route-transition handoff — are received instead of being silently dropped.
|
|
2348
|
+
useIsoLayoutEffect(() => {
|
|
2349
|
+
const handleSetOpenEvent = ({
|
|
2350
|
+
open: nextOpen,
|
|
2351
|
+
eventDetails
|
|
2352
|
+
}) => setOpen(nextOpen, eventDetails);
|
|
2353
|
+
floatingEvents.on('setOpen', handleSetOpenEvent);
|
|
2354
|
+
return () => {
|
|
2355
|
+
floatingEvents?.off('setOpen', handleSetOpenEvent);
|
|
2356
|
+
};
|
|
2357
|
+
}, [floatingEvents, setOpen]);
|
|
2358
|
+
const handleImperativeClose = React.useCallback(() => {
|
|
2359
|
+
store.setOpen(false, createChangeEventDetails(imperativeAction));
|
|
2360
|
+
}, [store]);
|
|
2361
|
+
React.useImperativeHandle(actionsRef, () => ({
|
|
2362
|
+
unmount: forceUnmount,
|
|
2363
|
+
close: handleImperativeClose
|
|
2364
|
+
}), [forceUnmount, handleImperativeClose]);
|
|
2365
|
+
let ctx;
|
|
2366
|
+
if (parent.type === 'context-menu') {
|
|
2367
|
+
ctx = parent.context;
|
|
2368
|
+
}
|
|
2369
|
+
React.useImperativeHandle(ctx?.positionerRef, () => positionerElement, [positionerElement]);
|
|
2370
|
+
React.useImperativeHandle(ctx?.actionsRef, () => ({
|
|
2371
|
+
setOpen
|
|
2372
|
+
}), [setOpen]);
|
|
2373
|
+
const dismiss = useDismiss(floatingRootContext, {
|
|
2374
|
+
enabled: !disabled,
|
|
2375
|
+
bubbles: {
|
|
2376
|
+
escapeKey: closeParentOnEsc && parent.type === 'menu'
|
|
2377
|
+
},
|
|
2378
|
+
outsidePress() {
|
|
2379
|
+
if (parent.type !== 'context-menu' || openEventRef.current?.type === 'contextmenu') {
|
|
2380
|
+
return true;
|
|
2381
|
+
}
|
|
2382
|
+
return allowOutsidePressDismissalRef.current;
|
|
2383
|
+
},
|
|
2384
|
+
externalTree: nested ? floatingTreeRoot : undefined
|
|
2385
|
+
});
|
|
2386
|
+
const direction = useDirection();
|
|
2387
|
+
const setActiveIndex = React.useCallback(index => {
|
|
2388
|
+
if (store.select('activeIndex') === index) {
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
store.set('activeIndex', index);
|
|
2392
|
+
}, [store]);
|
|
2393
|
+
const listNavigation$1 = useListNavigation(floatingRootContext, {
|
|
2394
|
+
enabled: !disabled,
|
|
2395
|
+
listRef: store.context.itemDomElements,
|
|
2396
|
+
activeIndex,
|
|
2397
|
+
nested: parent.type !== undefined,
|
|
2398
|
+
loopFocus,
|
|
2399
|
+
orientation,
|
|
2400
|
+
parentOrientation: parent.type === 'menubar' ? parent.context.orientation : undefined,
|
|
2401
|
+
rtl: direction === 'rtl',
|
|
2402
|
+
disabledIndices: EMPTY_ARRAY,
|
|
2403
|
+
onNavigate: setActiveIndex,
|
|
2404
|
+
openOnArrowKeyDown: parent.type !== 'context-menu',
|
|
2405
|
+
externalTree: nested ? floatingTreeRoot : undefined,
|
|
2406
|
+
focusItemOnHover: highlightItemOnHover
|
|
2407
|
+
});
|
|
2408
|
+
const onTyping = React.useCallback(nextTyping => {
|
|
2409
|
+
store.context.typingRef.current = nextTyping;
|
|
2410
|
+
}, [store]);
|
|
2411
|
+
const typeahead = useTypeahead(floatingRootContext, {
|
|
2412
|
+
enabled: !disabled,
|
|
2413
|
+
listRef: store.context.itemLabels,
|
|
2414
|
+
elementsRef: store.context.itemDomElements,
|
|
2415
|
+
activeIndex,
|
|
2416
|
+
resetMs: TYPEAHEAD_RESET_MS,
|
|
2417
|
+
onMatch: index => {
|
|
2418
|
+
if (open && index !== activeIndex) {
|
|
2419
|
+
store.set('activeIndex', index);
|
|
2420
|
+
}
|
|
2421
|
+
},
|
|
2422
|
+
onTyping
|
|
2423
|
+
});
|
|
2424
|
+
const activeTriggerProps = React.useMemo(() => {
|
|
2425
|
+
const mergedProps = mergeProps(typeahead.reference, listNavigation$1.reference, dismiss.reference, {
|
|
2426
|
+
onMouseMove() {
|
|
2427
|
+
store.set('allowMouseEnter', true);
|
|
2428
|
+
}
|
|
2429
|
+
}, interactionTypeProps);
|
|
2430
|
+
mergedProps['aria-haspopup'] = 'menu';
|
|
2431
|
+
mergedProps['aria-expanded'] = open;
|
|
2432
|
+
return mergedProps;
|
|
2433
|
+
}, [store, typeahead.reference, listNavigation$1.reference, dismiss.reference, interactionTypeProps, open]);
|
|
2434
|
+
const inactiveTriggerProps = React.useMemo(() => {
|
|
2435
|
+
const mergedProps = mergeProps(listNavigation$1.trigger, dismiss.trigger, interactionTypeProps);
|
|
2436
|
+
mergedProps['aria-haspopup'] = 'menu';
|
|
2437
|
+
mergedProps['aria-expanded'] = false;
|
|
2438
|
+
return mergedProps;
|
|
2439
|
+
}, [listNavigation$1.trigger, dismiss.trigger, interactionTypeProps]);
|
|
2440
|
+
const popupProps = React.useMemo(() => mergeProps(FOCUSABLE_POPUP_PROPS, {
|
|
2441
|
+
id: floatingId,
|
|
2442
|
+
role: 'menu',
|
|
2443
|
+
'aria-labelledby': activeTriggerElement?.id,
|
|
2444
|
+
onMouseMove() {
|
|
2445
|
+
store.set('allowMouseEnter', true);
|
|
2446
|
+
if (parent.type === 'menu') {
|
|
2447
|
+
store.set('hoverEnabled', false);
|
|
2448
|
+
}
|
|
2449
|
+
},
|
|
2450
|
+
onClick() {
|
|
2451
|
+
if (store.select('hoverEnabled')) {
|
|
2452
|
+
store.set('hoverEnabled', false);
|
|
2453
|
+
}
|
|
2454
|
+
},
|
|
2455
|
+
onKeyDown(event) {
|
|
2456
|
+
// The Menubar's CompositeRoot captures keyboard events via
|
|
2457
|
+
// event delegation. This works well when Menu.Root is nested inside Menubar,
|
|
2458
|
+
// but with detached triggers we need to manually forward the event to the CompositeRoot.
|
|
2459
|
+
const relay = store.select('keyboardEventRelay');
|
|
2460
|
+
if (relay && !event.isPropagationStopped()) {
|
|
2461
|
+
relay(event);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}, typeahead.floating, listNavigation$1.floating, dismiss.floating), [activeTriggerElement, floatingId, parent.type, store, typeahead.floating, listNavigation$1.floating, dismiss.floating]);
|
|
2465
|
+
const itemProps = listNavigation$1.item ?? EMPTY_OBJECT;
|
|
2466
|
+
usePopupInteractionProps(store, {
|
|
2467
|
+
floatingRootContext,
|
|
2468
|
+
activeTriggerProps,
|
|
2469
|
+
inactiveTriggerProps,
|
|
2470
|
+
popupProps,
|
|
2471
|
+
itemProps
|
|
2472
|
+
});
|
|
2473
|
+
const context = React.useMemo(() => ({
|
|
2474
|
+
store,
|
|
2475
|
+
parent: parentFromContext
|
|
2476
|
+
}), [store, parentFromContext]);
|
|
2477
|
+
const content = /*#__PURE__*/jsxs(MenuRootContext.Provider, {
|
|
2478
|
+
value: context,
|
|
2479
|
+
children: [handle && /*#__PURE__*/jsx(PopupHandleAttachment, {
|
|
2480
|
+
handle: handle,
|
|
2481
|
+
store: store
|
|
2482
|
+
}), typeof children === 'function' ? children({
|
|
2483
|
+
payload
|
|
2484
|
+
}) : children]
|
|
2485
|
+
});
|
|
2486
|
+
if (parent.type === undefined || parent.type === 'context-menu') {
|
|
2487
|
+
// set up a FloatingTree to provide the context to nested menus
|
|
2488
|
+
return /*#__PURE__*/jsx(FloatingTree, {
|
|
2489
|
+
externalTree: floatingTreeRoot,
|
|
2490
|
+
children: content
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2493
|
+
return content;
|
|
2494
|
+
});
|
|
2495
|
+
if (process.env.NODE_ENV !== "production") MenuRoot.displayName = "MenuRoot";
|
|
2496
|
+
function useMenuRootStore(initialState) {
|
|
2497
|
+
// The store is owned by this Root instance and created exactly once. It is not tied to the handle:
|
|
2498
|
+
// the handle attaches to it, so swapping the handle re-attaches rather than recreating state.
|
|
2499
|
+
// Default values are only initial values; controlled values and root state are synced after creation.
|
|
2500
|
+
// Unlike other popups, Menu wires its floating root context separately (it relays open changes
|
|
2501
|
+
// through an event).
|
|
2502
|
+
const store = useRefWithInit(() => new MenuStore(initialState)).current;
|
|
2503
|
+
return store;
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/**
|
|
2507
|
+
* Groups all parts of a submenu.
|
|
2508
|
+
* Doesn't render its own HTML element.
|
|
2509
|
+
*
|
|
2510
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
2511
|
+
*/
|
|
2512
|
+
function MenuSubmenuRoot(props) {
|
|
2513
|
+
const parentMenu = useMenuRootContext().store;
|
|
2514
|
+
const contextValue = React.useMemo(() => ({
|
|
2515
|
+
parentMenu
|
|
2516
|
+
}), [parentMenu]);
|
|
2517
|
+
return /*#__PURE__*/jsx(MenuSubmenuRootContext.Provider, {
|
|
2518
|
+
value: contextValue,
|
|
2519
|
+
children: /*#__PURE__*/jsx(MenuRoot, {
|
|
2520
|
+
...props
|
|
2521
|
+
})
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
function useCompositeItem(params = {}) {
|
|
2526
|
+
const {
|
|
2527
|
+
highlightItemOnHover,
|
|
2528
|
+
highlightedIndex,
|
|
2529
|
+
onHighlightedIndexChange
|
|
2530
|
+
} = useCompositeRootContext();
|
|
2531
|
+
const {
|
|
2532
|
+
ref,
|
|
2533
|
+
index
|
|
2534
|
+
} = useCompositeListItem(params);
|
|
2535
|
+
const isHighlighted = highlightedIndex === index;
|
|
2536
|
+
const itemRef = React.useRef(null);
|
|
2537
|
+
const mergedRef = useMergedRefs(ref, itemRef);
|
|
2538
|
+
const compositeProps = {
|
|
2539
|
+
tabIndex: isHighlighted ? 0 : -1,
|
|
2540
|
+
onFocus() {
|
|
2541
|
+
onHighlightedIndexChange(index);
|
|
2542
|
+
},
|
|
2543
|
+
onMouseMove() {
|
|
2544
|
+
const item = itemRef.current;
|
|
2545
|
+
if (!highlightItemOnHover || !item) {
|
|
2546
|
+
return;
|
|
2547
|
+
}
|
|
2548
|
+
const disabled = item.hasAttribute('disabled') || item.ariaDisabled === 'true';
|
|
2549
|
+
if (!isHighlighted && !disabled) {
|
|
2550
|
+
item.focus();
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
};
|
|
2554
|
+
return {
|
|
2555
|
+
compositeProps,
|
|
2556
|
+
compositeRef: mergedRef,
|
|
2557
|
+
index
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
function CompositeItem(componentProps) {
|
|
2562
|
+
const {
|
|
2563
|
+
render,
|
|
2564
|
+
className,
|
|
2565
|
+
style,
|
|
2566
|
+
state = EMPTY_OBJECT,
|
|
2567
|
+
props = EMPTY_ARRAY,
|
|
2568
|
+
refs = EMPTY_ARRAY,
|
|
2569
|
+
metadata,
|
|
2570
|
+
stateAttributesMapping,
|
|
2571
|
+
tag = 'div',
|
|
2572
|
+
...elementProps
|
|
2573
|
+
} = componentProps;
|
|
2574
|
+
const {
|
|
2575
|
+
compositeProps,
|
|
2576
|
+
compositeRef
|
|
2577
|
+
} = useCompositeItem({
|
|
2578
|
+
metadata
|
|
2579
|
+
});
|
|
2580
|
+
return useRenderElement(tag, componentProps, {
|
|
2581
|
+
state,
|
|
2582
|
+
// The composite ref attaches first so an outer item wins when nested items share a DOM node.
|
|
2583
|
+
ref: [compositeRef, ...refs],
|
|
2584
|
+
props: [compositeProps, ...props, elementProps],
|
|
2585
|
+
stateAttributesMapping
|
|
2586
|
+
});
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2589
|
+
function findRootOwnerId(node) {
|
|
2590
|
+
if (isHTMLElement(node) && node.hasAttribute('data-rootownerid')) {
|
|
2591
|
+
return node.getAttribute('data-rootownerid');
|
|
2592
|
+
}
|
|
2593
|
+
if (isLastTraversableNode(node)) {
|
|
2594
|
+
return undefined;
|
|
2595
|
+
}
|
|
2596
|
+
return findRootOwnerId(getParentNode(node));
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
/**
|
|
2600
|
+
* Minimal store interface required by the focus guard hook.
|
|
2601
|
+
* Both PopoverStore and MenuStore satisfy this interface.
|
|
2602
|
+
*/
|
|
2603
|
+
|
|
2604
|
+
/**
|
|
2605
|
+
* Provides focus guard handlers for popup triggers (Popover, Menu).
|
|
2606
|
+
*
|
|
2607
|
+
* When the popup is open, invisible focus guard elements are placed before and after
|
|
2608
|
+
* the trigger. These handlers close the popup and move focus to the appropriate
|
|
2609
|
+
* tabbable element when the guards receive focus (i.e. when the user tabs out).
|
|
2610
|
+
*/
|
|
2611
|
+
function useTriggerFocusGuards(store, triggerElementRef) {
|
|
2612
|
+
const preFocusGuardRef = React.useRef(null);
|
|
2613
|
+
function handlePreFocusGuardFocus(event) {
|
|
2614
|
+
ReactDOM.flushSync(() => {
|
|
2615
|
+
store.setOpen(false, createChangeEventDetails(focusOut, event.nativeEvent, event.currentTarget));
|
|
2616
|
+
});
|
|
2617
|
+
const previousTabbable = getTabbableBeforeElement(preFocusGuardRef.current);
|
|
2618
|
+
previousTabbable?.focus();
|
|
2619
|
+
}
|
|
2620
|
+
function handleFocusTargetFocus(event) {
|
|
2621
|
+
const positionerElement = store.select('positionerElement');
|
|
2622
|
+
if (positionerElement && isOutsideEvent(event, positionerElement)) {
|
|
2623
|
+
store.context.beforeContentFocusGuardRef.current?.focus();
|
|
2624
|
+
} else {
|
|
2625
|
+
ReactDOM.flushSync(() => {
|
|
2626
|
+
store.setOpen(false, createChangeEventDetails(focusOut, event.nativeEvent, event.currentTarget));
|
|
2627
|
+
});
|
|
2628
|
+
let nextTabbable = getTabbableAfterElement(store.context.triggerFocusTargetRef.current || triggerElementRef.current);
|
|
2629
|
+
while (nextTabbable !== null && contains(positionerElement, nextTabbable)) {
|
|
2630
|
+
const prevTabbable = nextTabbable;
|
|
2631
|
+
nextTabbable = getNextTabbable(nextTabbable);
|
|
2632
|
+
if (nextTabbable === prevTabbable) {
|
|
2633
|
+
break;
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
nextTabbable?.focus();
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return {
|
|
2640
|
+
preFocusGuardRef,
|
|
2641
|
+
handlePreFocusGuardFocus,
|
|
2642
|
+
handleFocusTargetFocus
|
|
2643
|
+
};
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* Returns `click` and `mousedown` handlers that fix the behavior of triggers of popups that are toggled by different events.
|
|
2648
|
+
* For example, a button that opens a popup on mousedown and closes it on click.
|
|
2649
|
+
* This hook prevents the popup from closing immediately after the mouse button is released.
|
|
2650
|
+
*/
|
|
2651
|
+
function useMixedToggleClickHandler(params) {
|
|
2652
|
+
const {
|
|
2653
|
+
enabled = true,
|
|
2654
|
+
mouseDownAction,
|
|
2655
|
+
open
|
|
2656
|
+
} = params;
|
|
2657
|
+
const ignoreClickRef = React.useRef(false);
|
|
2658
|
+
return React.useMemo(() => {
|
|
2659
|
+
if (!enabled) {
|
|
2660
|
+
return EMPTY_OBJECT;
|
|
2661
|
+
}
|
|
2662
|
+
return {
|
|
2663
|
+
onMouseDown: event => {
|
|
2664
|
+
if (mouseDownAction === 'open' && !open || mouseDownAction === 'close' && open) {
|
|
2665
|
+
ignoreClickRef.current = true;
|
|
2666
|
+
ownerDocument(event.currentTarget).addEventListener('click', () => {
|
|
2667
|
+
ignoreClickRef.current = false;
|
|
2668
|
+
}, {
|
|
2669
|
+
once: true
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
},
|
|
2673
|
+
onClick: event => {
|
|
2674
|
+
if (ignoreClickRef.current) {
|
|
2675
|
+
ignoreClickRef.current = false;
|
|
2676
|
+
event.preventBaseUIHandler();
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2680
|
+
}, [enabled, mouseDownAction, open]);
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2683
|
+
const MenuTrigger = fastComponentRef(function MenuTrigger(componentProps, forwardedRef) {
|
|
2684
|
+
const {
|
|
2685
|
+
render,
|
|
2686
|
+
className,
|
|
2687
|
+
style,
|
|
2688
|
+
disabled: disabledProp = false,
|
|
2689
|
+
nativeButton = true,
|
|
2690
|
+
id: idProp,
|
|
2691
|
+
openOnHover: openOnHoverProp,
|
|
2692
|
+
delay = 100,
|
|
2693
|
+
closeDelay = 0,
|
|
2694
|
+
handle,
|
|
2695
|
+
payload,
|
|
2696
|
+
...elementProps
|
|
2697
|
+
} = componentProps;
|
|
2698
|
+
const rootContext = useMenuRootContext(true);
|
|
2699
|
+
const handleStore = usePopupHandleStore(handle);
|
|
2700
|
+
const store = handleStore ?? rootContext?.store;
|
|
2701
|
+
if (!store) {
|
|
2702
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Menu.Trigger> must be either used within a <Menu.Root> component or provided with a handle.' : formatErrorMessage(85));
|
|
2703
|
+
}
|
|
2704
|
+
const thisTriggerId = useBaseUiId(idProp);
|
|
2705
|
+
const isTriggerActive = store.useState('isTriggerActive', thisTriggerId);
|
|
2706
|
+
const floatingRootContext = store.useState('floatingRootContext');
|
|
2707
|
+
const isOpenedByThisTrigger = store.useState('isOpenedByTrigger', thisTriggerId);
|
|
2708
|
+
const popupId = store.useState('triggerPopupId', thisTriggerId);
|
|
2709
|
+
const triggerElementRef = React.useRef(null);
|
|
2710
|
+
const parent = useMenuParent();
|
|
2711
|
+
const compositeRootContext = useCompositeRootContext(true);
|
|
2712
|
+
const floatingTreeRootFromContext = useFloatingTree();
|
|
2713
|
+
const floatingTreeRoot = React.useMemo(() => {
|
|
2714
|
+
return floatingTreeRootFromContext ?? new FloatingTreeStore();
|
|
2715
|
+
}, [floatingTreeRootFromContext]);
|
|
2716
|
+
const floatingNodeId = useFloatingNodeId(floatingTreeRoot);
|
|
2717
|
+
const floatingParentNodeId = useFloatingParentNodeId();
|
|
2718
|
+
const {
|
|
2719
|
+
registerTrigger,
|
|
2720
|
+
isMountedByThisTrigger
|
|
2721
|
+
} = useTriggerDataForwarding(thisTriggerId, triggerElementRef, store, {
|
|
2722
|
+
payload,
|
|
2723
|
+
closeDelay,
|
|
2724
|
+
parent,
|
|
2725
|
+
floatingTreeRoot,
|
|
2726
|
+
floatingNodeId,
|
|
2727
|
+
floatingParentNodeId,
|
|
2728
|
+
keyboardEventRelay: compositeRootContext?.relayKeyboardEvent
|
|
2729
|
+
});
|
|
2730
|
+
const isInMenubar = parent.type === 'menubar';
|
|
2731
|
+
const rootDisabled = store.useState('disabled');
|
|
2732
|
+
const disabled = disabledProp || rootDisabled || isInMenubar && parent.context.disabled;
|
|
2733
|
+
const {
|
|
2734
|
+
getButtonProps,
|
|
2735
|
+
buttonRef
|
|
2736
|
+
} = useButton({
|
|
2737
|
+
disabled,
|
|
2738
|
+
native: nativeButton
|
|
2739
|
+
});
|
|
2740
|
+
React.useEffect(() => {
|
|
2741
|
+
if (!isOpenedByThisTrigger && parent.type === undefined) {
|
|
2742
|
+
store.context.allowMouseUpTriggerRef.current = false;
|
|
2743
|
+
}
|
|
2744
|
+
}, [store, isOpenedByThisTrigger, parent.type]);
|
|
2745
|
+
const triggerRef = React.useRef(null);
|
|
2746
|
+
const allowMouseUpTriggerTimeout = useTimeout();
|
|
2747
|
+
const handleDocumentMouseUp = useStableCallback(mouseEvent => {
|
|
2748
|
+
if (!triggerRef.current) {
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2751
|
+
allowMouseUpTriggerTimeout.clear();
|
|
2752
|
+
store.context.allowMouseUpTriggerRef.current = false;
|
|
2753
|
+
const mouseUpTarget = mouseEvent.target;
|
|
2754
|
+
if (contains(triggerRef.current, mouseUpTarget) || contains(store.select('positionerElement'), mouseUpTarget) || mouseUpTarget === triggerRef.current) {
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2757
|
+
if (mouseUpTarget != null && findRootOwnerId(mouseUpTarget) === store.select('rootId')) {
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
if (isMouseWithinBounds(mouseEvent, triggerRef.current)) {
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
floatingTreeRoot.events.emit('close', {
|
|
2764
|
+
domEvent: mouseEvent,
|
|
2765
|
+
reason: cancelOpen
|
|
2766
|
+
});
|
|
2767
|
+
});
|
|
2768
|
+
React.useEffect(() => {
|
|
2769
|
+
if (isOpenedByThisTrigger && store.select('lastOpenChangeReason') === triggerHover) {
|
|
2770
|
+
const doc = ownerDocument(triggerRef.current);
|
|
2771
|
+
doc.addEventListener('mouseup', handleDocumentMouseUp, {
|
|
2772
|
+
once: true
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
}, [isOpenedByThisTrigger, handleDocumentMouseUp, store]);
|
|
2776
|
+
const parentMenubarHasSubmenuOpen = isInMenubar && parent.context.hasSubmenuOpen;
|
|
2777
|
+
const openOnHover = openOnHoverProp ?? parentMenubarHasSubmenuOpen;
|
|
2778
|
+
const hoverProps = useHoverReferenceInteraction(floatingRootContext, {
|
|
2779
|
+
enabled: openOnHover && !disabled && (!isInMenubar || parentMenubarHasSubmenuOpen && !isMountedByThisTrigger),
|
|
2780
|
+
handleClose: safePolygon({
|
|
2781
|
+
blockPointerEvents: !isInMenubar
|
|
2782
|
+
}),
|
|
2783
|
+
mouseOnly: true,
|
|
2784
|
+
move: false,
|
|
2785
|
+
restMs: parent.type === undefined ? delay : undefined,
|
|
2786
|
+
delay: {
|
|
2787
|
+
close: closeDelay
|
|
2788
|
+
},
|
|
2789
|
+
triggerElementRef,
|
|
2790
|
+
externalTree: floatingTreeRoot,
|
|
2791
|
+
isActiveTrigger: isTriggerActive,
|
|
2792
|
+
isClosing: () => store.select('transitionStatus') === 'ending'
|
|
2793
|
+
});
|
|
2794
|
+
|
|
2795
|
+
// Whether to ignore clicks to open the menu.
|
|
2796
|
+
// `lastOpenChangeReason` doesn't need to be reactive here, as we need to run this
|
|
2797
|
+
// only when `isOpenedByThisTrigger` changes.
|
|
2798
|
+
const stickIfOpen = useStickIfOpen(isOpenedByThisTrigger, store.select('lastOpenChangeReason'));
|
|
2799
|
+
const click = useClick(floatingRootContext, {
|
|
2800
|
+
enabled: !disabled,
|
|
2801
|
+
event: isOpenedByThisTrigger && isInMenubar ? 'click' : 'mousedown',
|
|
2802
|
+
toggle: true,
|
|
2803
|
+
ignoreMouse: false,
|
|
2804
|
+
stickIfOpen: parent.type === undefined ? stickIfOpen : false
|
|
2805
|
+
});
|
|
2806
|
+
const focus = useFocus(floatingRootContext, {
|
|
2807
|
+
enabled: !disabled && parentMenubarHasSubmenuOpen
|
|
2808
|
+
});
|
|
2809
|
+
const mixedToggleHandlers = useMixedToggleClickHandler({
|
|
2810
|
+
open: isOpenedByThisTrigger,
|
|
2811
|
+
enabled: isInMenubar,
|
|
2812
|
+
mouseDownAction: 'open'
|
|
2813
|
+
});
|
|
2814
|
+
const localInteractionProps = React.useMemo(() => mergeProps(focus.reference, click.reference), [focus.reference, click.reference]);
|
|
2815
|
+
const rootTriggerProps = store.useState('triggerProps', isMountedByThisTrigger);
|
|
2816
|
+
const {
|
|
2817
|
+
preFocusGuardRef,
|
|
2818
|
+
handlePreFocusGuardFocus,
|
|
2819
|
+
handleFocusTargetFocus
|
|
2820
|
+
} = useTriggerFocusGuards(store, triggerElementRef);
|
|
2821
|
+
const state = {
|
|
2822
|
+
disabled,
|
|
2823
|
+
open: isOpenedByThisTrigger
|
|
2824
|
+
};
|
|
2825
|
+
const ref = [triggerRef, forwardedRef, buttonRef, registerTrigger, triggerElementRef];
|
|
2826
|
+
const props = [localInteractionProps, hoverProps ?? EMPTY_OBJECT, rootTriggerProps, {
|
|
2827
|
+
'aria-haspopup': 'menu',
|
|
2828
|
+
'aria-controls': popupId,
|
|
2829
|
+
id: thisTriggerId,
|
|
2830
|
+
onMouseDown: event => {
|
|
2831
|
+
if (store.select('open')) {
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
// mousedown -> mouseup on menu item should not trigger it within 200ms.
|
|
2836
|
+
allowMouseUpTriggerTimeout.start(200, () => {
|
|
2837
|
+
store.context.allowMouseUpTriggerRef.current = true;
|
|
2838
|
+
});
|
|
2839
|
+
const doc = ownerDocument(event.currentTarget);
|
|
2840
|
+
doc.addEventListener('mouseup', handleDocumentMouseUp, {
|
|
2841
|
+
once: true
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
}, isInMenubar ? {
|
|
2845
|
+
role: 'menuitem'
|
|
2846
|
+
} : {}, mixedToggleHandlers, elementProps, getButtonProps];
|
|
2847
|
+
const element = useRenderElement('button', componentProps, {
|
|
2848
|
+
enabled: !isInMenubar,
|
|
2849
|
+
stateAttributesMapping: pressableTriggerOpenStateMapping,
|
|
2850
|
+
state,
|
|
2851
|
+
ref,
|
|
2852
|
+
props
|
|
2853
|
+
});
|
|
2854
|
+
if (isInMenubar) {
|
|
2855
|
+
return /*#__PURE__*/jsx(CompositeItem, {
|
|
2856
|
+
tag: "button",
|
|
2857
|
+
render: render,
|
|
2858
|
+
className: className,
|
|
2859
|
+
style: style,
|
|
2860
|
+
state: state,
|
|
2861
|
+
refs: ref,
|
|
2862
|
+
props: props,
|
|
2863
|
+
stateAttributesMapping: pressableTriggerOpenStateMapping
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
|
|
2867
|
+
// A fragment with key is required to ensure that the `element` is mounted to the same DOM node
|
|
2868
|
+
// regardless of whether the focus guards are rendered or not.
|
|
2869
|
+
|
|
2870
|
+
if (isOpenedByThisTrigger) {
|
|
2871
|
+
return /*#__PURE__*/jsxs(React.Fragment, {
|
|
2872
|
+
children: [/*#__PURE__*/jsx(FocusGuard, {
|
|
2873
|
+
ref: preFocusGuardRef,
|
|
2874
|
+
onFocus: handlePreFocusGuardFocus
|
|
2875
|
+
}, `${thisTriggerId}-pre-focus-guard`), /*#__PURE__*/jsx(React.Fragment, {
|
|
2876
|
+
children: element
|
|
2877
|
+
}, thisTriggerId), /*#__PURE__*/jsx(FocusGuard, {
|
|
2878
|
+
ref: store.context.triggerFocusTargetRef,
|
|
2879
|
+
onFocus: handleFocusTargetFocus
|
|
2880
|
+
}, `${thisTriggerId}-post-focus-guard`)]
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
return /*#__PURE__*/jsx(React.Fragment, {
|
|
2884
|
+
children: element
|
|
2885
|
+
}, thisTriggerId);
|
|
2886
|
+
});
|
|
2887
|
+
if (process.env.NODE_ENV !== "production") MenuTrigger.displayName = "MenuTrigger";
|
|
2888
|
+
/**
|
|
2889
|
+
* Determines whether to ignore clicks after a hover-open.
|
|
2890
|
+
*/
|
|
2891
|
+
function useStickIfOpen(open, openReason) {
|
|
2892
|
+
const stickIfOpenTimeout = useTimeout();
|
|
2893
|
+
const [stickIfOpen, setStickIfOpen] = React.useState(false);
|
|
2894
|
+
useIsoLayoutEffect(() => {
|
|
2895
|
+
if (open && openReason === triggerHover) {
|
|
2896
|
+
// Only allow "patient" clicks to close the menu if it's open.
|
|
2897
|
+
// If they clicked within 500ms of the menu opening, keep it open.
|
|
2898
|
+
setStickIfOpen(true);
|
|
2899
|
+
stickIfOpenTimeout.start(PATIENT_CLICK_THRESHOLD, () => {
|
|
2900
|
+
setStickIfOpen(false);
|
|
2901
|
+
});
|
|
2902
|
+
} else if (!open) {
|
|
2903
|
+
stickIfOpenTimeout.clear();
|
|
2904
|
+
setStickIfOpen(false);
|
|
2905
|
+
}
|
|
2906
|
+
}, [open, openReason, stickIfOpenTimeout]);
|
|
2907
|
+
return stickIfOpen;
|
|
2908
|
+
}
|
|
2909
|
+
function useMenuParent() {
|
|
2910
|
+
const menubarContext = useMenubarContext(true);
|
|
2911
|
+
const parent = React.useMemo(() => {
|
|
2912
|
+
if (menubarContext) {
|
|
2913
|
+
return {
|
|
2914
|
+
type: 'menubar',
|
|
2915
|
+
context: menubarContext
|
|
2916
|
+
};
|
|
2917
|
+
}
|
|
2918
|
+
return {
|
|
2919
|
+
type: undefined
|
|
2920
|
+
};
|
|
2921
|
+
}, [menubarContext]);
|
|
2922
|
+
return parent;
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
const VOICE_OVER_EXPANDED_PROPS = {
|
|
2926
|
+
'aria-expanded': undefined
|
|
2927
|
+
};
|
|
2928
|
+
|
|
2929
|
+
/**
|
|
2930
|
+
* A menu item that opens a submenu.
|
|
2931
|
+
* Renders a `<div>` element.
|
|
2932
|
+
*
|
|
2933
|
+
* Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
|
|
2934
|
+
*/
|
|
2935
|
+
const MenuSubmenuTrigger = /*#__PURE__*/React.forwardRef(function MenuSubmenuTrigger(componentProps, forwardedRef) {
|
|
2936
|
+
const {
|
|
2937
|
+
render,
|
|
2938
|
+
className,
|
|
2939
|
+
style,
|
|
2940
|
+
label,
|
|
2941
|
+
id: idProp,
|
|
2942
|
+
nativeButton = false,
|
|
2943
|
+
openOnHover = true,
|
|
2944
|
+
delay = 100,
|
|
2945
|
+
closeDelay = 0,
|
|
2946
|
+
disabled: disabledProp = false,
|
|
2947
|
+
...elementProps
|
|
2948
|
+
} = componentProps;
|
|
2949
|
+
const submenuRootContext = useMenuSubmenuRootContext();
|
|
2950
|
+
if (!submenuRootContext?.parentMenu) {
|
|
2951
|
+
throw new Error(process.env.NODE_ENV !== "production" ? 'Base UI: <Menu.SubmenuTrigger> must be placed in <Menu.SubmenuRoot>.' : formatErrorMessage(37));
|
|
2952
|
+
}
|
|
2953
|
+
const listItem = useCompositeListItem({
|
|
2954
|
+
guess: true,
|
|
2955
|
+
label
|
|
2956
|
+
});
|
|
2957
|
+
const menuPositionerContext = useMenuPositionerContext();
|
|
2958
|
+
const {
|
|
2959
|
+
store
|
|
2960
|
+
} = useMenuRootContext();
|
|
2961
|
+
const thisTriggerId = useBaseUiId(idProp);
|
|
2962
|
+
const open = store.useState('open');
|
|
2963
|
+
const floatingRootContext = store.useState('floatingRootContext');
|
|
2964
|
+
const floatingTreeRoot = store.useState('floatingTreeRoot');
|
|
2965
|
+
const popupId = store.useState('triggerPopupId', thisTriggerId);
|
|
2966
|
+
const baseRegisterTrigger = useTriggerRegistration(thisTriggerId, store);
|
|
2967
|
+
const registerTrigger = React.useCallback(element => {
|
|
2968
|
+
const cleanup = baseRegisterTrigger(element);
|
|
2969
|
+
if (element !== null && store.select('open') && store.select('activeTriggerId') == null) {
|
|
2970
|
+
store.update({
|
|
2971
|
+
activeTriggerId: thisTriggerId,
|
|
2972
|
+
activeTriggerElement: element,
|
|
2973
|
+
closeDelay
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
return cleanup;
|
|
2977
|
+
}, [baseRegisterTrigger, closeDelay, store, thisTriggerId]);
|
|
2978
|
+
const triggerElementRef = React.useRef(null);
|
|
2979
|
+
const handleTriggerElementRef = React.useCallback(el => {
|
|
2980
|
+
triggerElementRef.current = el;
|
|
2981
|
+
store.set('activeTriggerElement', el);
|
|
2982
|
+
}, [store]);
|
|
2983
|
+
store.useSyncedValue('closeDelay', closeDelay);
|
|
2984
|
+
const parentMenuStore = submenuRootContext.parentMenu;
|
|
2985
|
+
const rootDisabled = store.useState('disabled');
|
|
2986
|
+
const parentDisabled = parentMenuStore.useState('disabled');
|
|
2987
|
+
const disabled = disabledProp || rootDisabled || parentDisabled;
|
|
2988
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2989
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
2990
|
+
React.useEffect(() => {
|
|
2991
|
+
const element = triggerElementRef.current;
|
|
2992
|
+
if (element && isElementDisabled(element) && !disabled) {
|
|
2993
|
+
const ownerStackMessage = SafeReact.captureOwnerStack?.() || '';
|
|
2994
|
+
warn(`A disabled element was detected on <Menu.SubmenuTrigger>. To properly disable the trigger, use the \`disabled\` prop on the component instead of setting it on the rendered element.${ownerStackMessage}`);
|
|
2995
|
+
}
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
const itemProps = parentMenuStore.useState('itemProps');
|
|
2999
|
+
const highlighted = parentMenuStore.useState('isActive', listItem.index);
|
|
3000
|
+
const itemMetadata = React.useMemo(() => ({
|
|
3001
|
+
type: 'submenu-trigger',
|
|
3002
|
+
setActive() {
|
|
3003
|
+
if (parentMenuStore.select('highlightItemOnHover')) {
|
|
3004
|
+
parentMenuStore.set('activeIndex', listItem.index);
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
}), [parentMenuStore, listItem.index]);
|
|
3008
|
+
const {
|
|
3009
|
+
getItemProps,
|
|
3010
|
+
itemRef
|
|
3011
|
+
} = useMenuItem({
|
|
3012
|
+
closeOnClick: false,
|
|
3013
|
+
disabled,
|
|
3014
|
+
highlighted,
|
|
3015
|
+
id: thisTriggerId,
|
|
3016
|
+
store,
|
|
3017
|
+
typingRef: parentMenuStore.context.typingRef,
|
|
3018
|
+
nativeButton,
|
|
3019
|
+
itemMetadata,
|
|
3020
|
+
nodeId: menuPositionerContext?.context.nodeId
|
|
3021
|
+
});
|
|
3022
|
+
const hoverEnabled = store.useState('hoverEnabled');
|
|
3023
|
+
const hoverProps = useHoverReferenceInteraction(floatingRootContext, {
|
|
3024
|
+
enabled: hoverEnabled && openOnHover && !disabled,
|
|
3025
|
+
handleClose: safePolygon({
|
|
3026
|
+
blockPointerEvents: true
|
|
3027
|
+
}),
|
|
3028
|
+
mouseOnly: true,
|
|
3029
|
+
move: true,
|
|
3030
|
+
restMs: delay,
|
|
3031
|
+
delay: {
|
|
3032
|
+
open: delay,
|
|
3033
|
+
close: closeDelay
|
|
3034
|
+
},
|
|
3035
|
+
shouldOpen: delay > 0 ? () => parentMenuStore.select('allowMouseEnter') : undefined,
|
|
3036
|
+
triggerElementRef,
|
|
3037
|
+
externalTree: floatingTreeRoot,
|
|
3038
|
+
isClosing: () => store.select('transitionStatus') === 'ending',
|
|
3039
|
+
// Chrome can drop the trigger's `mouseleave` during a fast pointer sweep,
|
|
3040
|
+
// leaving a stale submenu open (see #5152) — cancel from `mouseout` too.
|
|
3041
|
+
guardStaleOpen: true
|
|
3042
|
+
});
|
|
3043
|
+
const click = useClick(floatingRootContext, {
|
|
3044
|
+
enabled: !disabled,
|
|
3045
|
+
event: 'mousedown',
|
|
3046
|
+
toggle: !openOnHover,
|
|
3047
|
+
ignoreMouse: openOnHover,
|
|
3048
|
+
stickIfOpen: false
|
|
3049
|
+
});
|
|
3050
|
+
const localInteractionProps = click.reference ?? EMPTY_OBJECT;
|
|
3051
|
+
const rootTriggerProps = store.useState('triggerProps', true);
|
|
3052
|
+
delete rootTriggerProps.id;
|
|
3053
|
+
const state = {
|
|
3054
|
+
disabled,
|
|
3055
|
+
highlighted,
|
|
3056
|
+
open
|
|
3057
|
+
};
|
|
3058
|
+
const openMethod = store.useState('openMethod');
|
|
3059
|
+
const lastOpenChangeReason = store.useState('lastOpenChangeReason');
|
|
3060
|
+
// Arrow keys open the submenu through list navigation without dispatching a click, so
|
|
3061
|
+
// `openMethod` stays null there; Enter and Space do dispatch one and report `keyboard`.
|
|
3062
|
+
const openedByKeyboard = lastOpenChangeReason === listNavigation || openMethod === 'keyboard';
|
|
3063
|
+
const shouldOmitExpanded = open && openedByKeyboard && voiceOver;
|
|
3064
|
+
const element = useRenderElement('div', componentProps, {
|
|
3065
|
+
state,
|
|
3066
|
+
stateAttributesMapping: triggerOpenStateMapping,
|
|
3067
|
+
props: [localInteractionProps, hoverProps, rootTriggerProps, itemProps,
|
|
3068
|
+
// Opening a submenu changes the trigger's expanded state while the trigger still holds
|
|
3069
|
+
// focus, and VoiceOver announces that state change instead of the submenu item that focus
|
|
3070
|
+
// moves to a moment later, so the first item is never announced. Dropping the state while
|
|
3071
|
+
// the submenu is open avoids the announcement without claiming the submenu is collapsed;
|
|
3072
|
+
// `aria-haspopup` still conveys that the item opens a submenu.
|
|
3073
|
+
shouldOmitExpanded ? VOICE_OVER_EXPANDED_PROPS : undefined, {
|
|
3074
|
+
'aria-controls': popupId,
|
|
3075
|
+
tabIndex: open || highlighted ? 0 : -1,
|
|
3076
|
+
onBlur() {
|
|
3077
|
+
if (highlighted) {
|
|
3078
|
+
parentMenuStore.set('activeIndex', null);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
}, elementProps, getItemProps],
|
|
3082
|
+
ref: [forwardedRef, listItem.ref, itemRef, registerTrigger, handleTriggerElementRef]
|
|
3083
|
+
});
|
|
3084
|
+
return element;
|
|
3085
|
+
});
|
|
3086
|
+
if (process.env.NODE_ENV !== "production") MenuSubmenuTrigger.displayName = "MenuSubmenuTrigger";
|
|
3087
|
+
|
|
3088
|
+
export { MenuTrigger as M, REGULAR_ITEM as R, MenuLinkItem as a, MenuItem as b, MenuRadioItem as c, MenuRadioItemIndicator as d, MenuSubmenuTrigger as e, MenuRoot as f, MenuPortal as g, MenuBackdrop as h, MenuPositioner as i, MenuPopup as j, MenuRadioGroup as k, MenuGroup as l, MenuSubmenuRoot as m, MenuGroupLabel as n, useMenuPositionerContext as o, useMenuItem as p, itemMapping as q, createNullMenuStore as r, useMenuRootContext as u };
|