@shortfuse/materialdesignweb 0.7.6 → 0.9.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/README.md +87 -90
- package/bin/mdw-css.js +1 -1
- package/components/Badge.js +14 -7
- package/components/Body.js +3 -0
- package/components/BottomAppBar.js +4 -13
- package/components/BottomSheet.js +424 -0
- package/components/Box.js +20 -28
- package/components/Button.js +85 -79
- package/components/Button.md +9 -9
- package/components/Card.js +60 -72
- package/components/Checkbox.js +33 -42
- package/components/CheckboxIcon.js +11 -29
- package/components/Chip.js +13 -11
- package/components/Dialog.js +214 -394
- package/components/DialogActions.js +2 -2
- package/components/Display.js +55 -0
- package/components/Divider.js +3 -3
- package/components/Fab.js +83 -18
- package/components/FabContainer.js +48 -0
- package/components/FilterChip.js +35 -33
- package/components/Grid.js +176 -0
- package/components/Headline.js +5 -28
- package/components/Icon.js +61 -76
- package/components/IconButton.js +72 -126
- package/components/Input.js +859 -1
- package/components/InputChip.js +161 -0
- package/components/Label.js +3 -0
- package/components/List.js +4 -6
- package/components/ListItem.js +46 -30
- package/components/ListOption.js +86 -53
- package/components/Listbox.js +248 -0
- package/components/Menu.js +69 -528
- package/components/MenuItem.js +33 -36
- package/components/NavBar.js +49 -86
- package/components/NavDrawer.js +16 -15
- package/components/NavDrawerItem.js +4 -5
- package/components/NavItem.js +58 -41
- package/components/NavRail.js +30 -20
- package/components/NavRailItem.js +8 -3
- package/components/Page.js +105 -0
- package/components/Pane.js +11 -274
- package/components/Popup.js +29 -0
- package/components/Progress.js +24 -23
- package/components/Radio.js +40 -36
- package/components/RadioIcon.js +12 -16
- package/components/Ripple.js +13 -10
- package/components/Root.js +209 -0
- package/components/Scrim.js +87 -0
- package/components/Search.js +77 -0
- package/components/SegmentedButton.js +33 -45
- package/components/SegmentedButtonGroup.js +25 -13
- package/components/Select.js +10 -11
- package/components/Shape.js +5 -65
- package/components/SideSheet.js +308 -0
- package/components/Slider.js +108 -78
- package/components/Snackbar.js +26 -21
- package/components/SnackbarContainer.js +42 -0
- package/components/Surface.js +17 -12
- package/components/Switch.js +45 -24
- package/components/SwitchIcon.js +49 -39
- package/components/Tab.js +64 -43
- package/components/TabContent.js +5 -3
- package/components/TabList.js +62 -34
- package/components/TabPanel.js +11 -8
- package/components/Table.js +116 -0
- package/components/TextArea.js +54 -50
- package/components/Title.js +4 -9
- package/components/Tooltip.js +44 -22
- package/components/TopAppBar.js +68 -172
- package/constants/shapes.js +36 -0
- package/constants/typography.js +127 -0
- package/core/Composition.js +1164 -645
- package/core/CompositionAdapter.js +314 -0
- package/core/CustomElement.js +701 -286
- package/core/css.js +121 -15
- package/core/customTypes.js +157 -40
- package/core/dom.js +17 -11
- package/{utils → core}/jsonMergePatch.js +42 -18
- package/core/observe.js +343 -244
- package/core/optimizations.js +23 -0
- package/core/template.js +19 -56
- package/core/uid.js +13 -0
- package/dist/index.min.js +85 -184
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +1 -1
- package/dom/HTMLOptionsCollectionProxy.js +106 -0
- package/loaders/palette.js +13 -0
- package/loaders/theme.js +12 -0
- package/mixins/AriaReflectorMixin.js +53 -14
- package/mixins/AriaToolbarMixin.js +5 -3
- package/mixins/ControlMixin.js +92 -41
- package/mixins/DelegatesFocusMixin.js +54 -0
- package/mixins/DensityMixin.js +2 -3
- package/mixins/ElevationMixin.js +62 -0
- package/mixins/FlexableMixin.js +67 -39
- package/mixins/FormAssociatedMixin.js +71 -16
- package/mixins/HyperlinkMixin.js +66 -0
- package/mixins/InputMixin.js +205 -39
- package/mixins/KeyboardNavMixin.js +22 -7
- package/mixins/NavigationListenerMixin.js +33 -0
- package/mixins/PopupMixin.js +725 -0
- package/mixins/RTLObserverMixin.js +0 -1
- package/mixins/ResizeObserverMixin.js +16 -5
- package/mixins/RippleMixin.js +11 -10
- package/mixins/ScrollListenerMixin.js +42 -33
- package/mixins/SemiStickyMixin.js +97 -0
- package/mixins/ShapeMaskedMixin.js +117 -0
- package/mixins/ShapeMixin.js +17 -194
- package/mixins/StateMixin.js +80 -39
- package/mixins/TextFieldMixin.js +139 -183
- package/mixins/ThemableMixin.js +71 -161
- package/mixins/TooltipTriggerMixin.js +292 -366
- package/mixins/TouchTargetMixin.js +5 -4
- package/mixins/TypographyMixin.js +121 -0
- package/package.json +111 -71
- package/services/rtl.js +10 -0
- package/services/svgAlias.js +17 -0
- package/{theming/index.js → services/theme.js} +25 -175
- package/types/bin/mdw-css.d.ts +3 -0
- package/types/bin/mdw-css.d.ts.map +1 -0
- package/types/components/Badge.d.ts +39 -0
- package/types/components/Badge.d.ts.map +1 -0
- package/types/components/Body.d.ts +29 -0
- package/types/components/Body.d.ts.map +1 -0
- package/types/components/BottomAppBar.d.ts +73 -0
- package/types/components/BottomAppBar.d.ts.map +1 -0
- package/types/components/BottomSheet.d.ts +109 -0
- package/types/components/BottomSheet.d.ts.map +1 -0
- package/types/components/Box.d.ts +16 -0
- package/types/components/Box.d.ts.map +1 -0
- package/types/components/Button.d.ts +714 -0
- package/types/components/Button.d.ts.map +1 -0
- package/types/components/Card.d.ts +412 -0
- package/types/components/Card.d.ts.map +1 -0
- package/types/components/Checkbox.d.ts +205 -0
- package/types/components/Checkbox.d.ts.map +1 -0
- package/types/components/CheckboxIcon.d.ts +44 -0
- package/types/components/CheckboxIcon.d.ts.map +1 -0
- package/types/components/Chip.d.ts +1425 -0
- package/types/components/Chip.d.ts.map +1 -0
- package/types/components/Dialog.d.ts +286 -0
- package/types/components/Dialog.d.ts.map +1 -0
- package/types/components/DialogActions.d.ts +4 -0
- package/types/components/DialogActions.d.ts.map +1 -0
- package/types/components/Display.d.ts +45 -0
- package/types/components/Display.d.ts.map +1 -0
- package/types/components/Divider.d.ts +10 -0
- package/types/components/Divider.d.ts.map +1 -0
- package/types/components/Fab.d.ts +741 -0
- package/types/components/Fab.d.ts.map +1 -0
- package/types/components/FabContainer.d.ts +10 -0
- package/types/components/FabContainer.d.ts.map +1 -0
- package/types/components/FilterChip.d.ts +4283 -0
- package/types/components/FilterChip.d.ts.map +1 -0
- package/types/components/Grid.d.ts +37 -0
- package/types/components/Grid.d.ts.map +1 -0
- package/types/components/Headline.d.ts +47 -0
- package/types/components/Headline.d.ts.map +1 -0
- package/types/components/Icon.d.ts +103 -0
- package/types/components/Icon.d.ts.map +1 -0
- package/types/components/IconButton.d.ts +1486 -0
- package/types/components/IconButton.d.ts.map +1 -0
- package/types/components/Input.d.ts +51288 -0
- package/types/components/Input.d.ts.map +1 -0
- package/types/components/InputChip.d.ts +243 -0
- package/types/components/InputChip.d.ts.map +1 -0
- package/types/components/Label.d.ts +29 -0
- package/types/components/Label.d.ts.map +1 -0
- package/types/components/List.d.ts +31 -0
- package/types/components/List.d.ts.map +1 -0
- package/types/components/ListItem.d.ts +349 -0
- package/types/components/ListItem.d.ts.map +1 -0
- package/types/components/ListOption.d.ts +1493 -0
- package/types/components/ListOption.d.ts.map +1 -0
- package/types/components/Listbox.d.ts +12012 -0
- package/types/components/Listbox.d.ts.map +1 -0
- package/types/components/Menu.d.ts +119 -0
- package/types/components/Menu.d.ts.map +1 -0
- package/types/components/MenuItem.d.ts +3109 -0
- package/types/components/MenuItem.d.ts.map +1 -0
- package/types/components/NavBar.d.ts +18 -0
- package/types/components/NavBar.d.ts.map +1 -0
- package/types/components/NavBarItem.d.ts +186 -0
- package/types/components/NavBarItem.d.ts.map +1 -0
- package/types/components/NavDrawer.d.ts +108 -0
- package/types/components/NavDrawer.d.ts.map +1 -0
- package/types/components/NavDrawerItem.d.ts +186 -0
- package/types/components/NavDrawerItem.d.ts.map +1 -0
- package/types/components/NavItem.d.ts +190 -0
- package/types/components/NavItem.d.ts.map +1 -0
- package/types/components/NavRail.d.ts +109 -0
- package/types/components/NavRail.d.ts.map +1 -0
- package/types/components/NavRailItem.d.ts +186 -0
- package/types/components/NavRailItem.d.ts.map +1 -0
- package/types/components/Page.d.ts +24 -0
- package/types/components/Page.d.ts.map +1 -0
- package/types/components/Pane.d.ts +44 -0
- package/types/components/Pane.d.ts.map +1 -0
- package/types/components/Popup.d.ts +76 -0
- package/types/components/Popup.d.ts.map +1 -0
- package/types/components/Progress.d.ts +19 -0
- package/types/components/Progress.d.ts.map +1 -0
- package/types/components/Radio.d.ts +199 -0
- package/types/components/Radio.d.ts.map +1 -0
- package/types/components/RadioIcon.d.ts +46 -0
- package/types/components/RadioIcon.d.ts.map +1 -0
- package/types/components/Ripple.d.ts +34 -0
- package/types/components/Ripple.d.ts.map +1 -0
- package/types/components/Root.d.ts +68 -0
- package/types/components/Root.d.ts.map +1 -0
- package/types/components/Scrim.d.ts +6 -0
- package/types/components/Scrim.d.ts.map +1 -0
- package/types/components/Search.d.ts +16 -0
- package/types/components/Search.d.ts.map +1 -0
- package/types/components/SegmentedButton.d.ts +718 -0
- package/types/components/SegmentedButton.d.ts.map +1 -0
- package/types/components/SegmentedButtonGroup.d.ts +44 -0
- package/types/components/SegmentedButtonGroup.d.ts.map +1 -0
- package/types/components/Select.d.ts +1361 -0
- package/types/components/Select.d.ts.map +1 -0
- package/types/components/Shape.d.ts +10 -0
- package/types/components/Shape.d.ts.map +1 -0
- package/types/components/SideSheet.d.ts +106 -0
- package/types/components/SideSheet.d.ts.map +1 -0
- package/types/components/Slider.d.ts +382 -0
- package/types/components/Slider.d.ts.map +1 -0
- package/types/components/Snackbar.d.ts +65 -0
- package/types/components/Snackbar.d.ts.map +1 -0
- package/types/components/SnackbarContainer.d.ts +6 -0
- package/types/components/SnackbarContainer.d.ts.map +1 -0
- package/types/components/Surface.d.ts +45 -0
- package/types/components/Surface.d.ts.map +1 -0
- package/types/components/Switch.d.ts +183 -0
- package/types/components/Switch.d.ts.map +1 -0
- package/types/components/SwitchIcon.d.ts +169 -0
- package/types/components/SwitchIcon.d.ts.map +1 -0
- package/types/components/Tab.d.ts +879 -0
- package/types/components/Tab.d.ts.map +1 -0
- package/types/components/TabContent.d.ts +122 -0
- package/types/components/TabContent.d.ts.map +1 -0
- package/types/components/TabList.d.ts +6266 -0
- package/types/components/TabList.d.ts.map +1 -0
- package/types/components/TabPanel.d.ts +28 -0
- package/types/components/TabPanel.d.ts.map +1 -0
- package/types/components/Table.d.ts +2 -0
- package/types/components/Table.d.ts.map +1 -0
- package/types/components/TextArea.d.ts +1394 -0
- package/types/components/TextArea.d.ts.map +1 -0
- package/types/components/Title.d.ts +47 -0
- package/types/components/Title.d.ts.map +1 -0
- package/types/components/Tooltip.d.ts +49 -0
- package/types/components/Tooltip.d.ts.map +1 -0
- package/types/components/TopAppBar.d.ts +130 -0
- package/types/components/TopAppBar.d.ts.map +1 -0
- package/types/constants/colorKeywords.d.ts +2 -0
- package/types/constants/colorKeywords.d.ts.map +1 -0
- package/types/constants/shapes.d.ts +38 -0
- package/types/constants/shapes.d.ts.map +1 -0
- package/types/constants/typography.d.ts +212 -0
- package/types/constants/typography.d.ts.map +1 -0
- package/types/core/Composition.d.ts +252 -0
- package/types/core/Composition.d.ts.map +1 -0
- package/types/core/CompositionAdapter.d.ts +92 -0
- package/types/core/CompositionAdapter.d.ts.map +1 -0
- package/types/core/CustomElement.d.ts +302 -0
- package/types/core/CustomElement.d.ts.map +1 -0
- package/types/core/css.d.ts +44 -0
- package/types/core/css.d.ts.map +1 -0
- package/types/core/customTypes.d.ts +26 -0
- package/types/core/customTypes.d.ts.map +1 -0
- package/types/core/dom.d.ts +32 -0
- package/types/core/dom.d.ts.map +1 -0
- package/types/core/jsonMergePatch.d.ts +31 -0
- package/types/core/jsonMergePatch.d.ts.map +1 -0
- package/types/core/observe.d.ts +113 -0
- package/types/core/observe.d.ts.map +1 -0
- package/types/core/optimizations.d.ts +7 -0
- package/types/core/optimizations.d.ts.map +1 -0
- package/types/core/template.d.ts +47 -0
- package/types/core/template.d.ts.map +1 -0
- package/types/core/uid.d.ts +6 -0
- package/types/core/uid.d.ts.map +1 -0
- package/types/dom/HTMLOptionsCollectionProxy.d.ts +18 -0
- package/types/dom/HTMLOptionsCollectionProxy.d.ts.map +1 -0
- package/types/index.d.ts +88 -0
- package/types/index.d.ts.map +1 -0
- package/types/loaders/palette.d.ts +2 -0
- package/types/loaders/palette.d.ts.map +1 -0
- package/types/loaders/theme.d.ts +2 -0
- package/types/loaders/theme.d.ts.map +1 -0
- package/types/mixins/AriaReflectorMixin.d.ts +23 -0
- package/types/mixins/AriaReflectorMixin.d.ts.map +1 -0
- package/types/mixins/AriaToolbarMixin.d.ts +32 -0
- package/types/mixins/AriaToolbarMixin.d.ts.map +1 -0
- package/types/mixins/ControlMixin.d.ts +124 -0
- package/types/mixins/ControlMixin.d.ts.map +1 -0
- package/types/mixins/DelegatesFocusMixin.d.ts +5 -0
- package/types/mixins/DelegatesFocusMixin.d.ts.map +1 -0
- package/types/mixins/DensityMixin.d.ts +5 -0
- package/types/mixins/DensityMixin.d.ts.map +1 -0
- package/types/mixins/ElevationMixin.d.ts +33 -0
- package/types/mixins/ElevationMixin.d.ts.map +1 -0
- package/types/mixins/FlexableMixin.d.ts +13 -0
- package/types/mixins/FlexableMixin.d.ts.map +1 -0
- package/types/mixins/FormAssociatedMixin.d.ts +122 -0
- package/types/mixins/FormAssociatedMixin.d.ts.map +1 -0
- package/types/mixins/HyperlinkMixin.d.ts +22 -0
- package/types/mixins/HyperlinkMixin.d.ts.map +1 -0
- package/types/mixins/InputMixin.d.ts +179 -0
- package/types/mixins/InputMixin.d.ts.map +1 -0
- package/types/mixins/KeyboardNavMixin.d.ts +47 -0
- package/types/mixins/KeyboardNavMixin.d.ts.map +1 -0
- package/types/mixins/NavigationListenerMixin.d.ts +8 -0
- package/types/mixins/NavigationListenerMixin.d.ts.map +1 -0
- package/types/mixins/PopupMixin.d.ts +82 -0
- package/types/mixins/PopupMixin.d.ts.map +1 -0
- package/types/mixins/RTLObserverMixin.d.ts +7 -0
- package/types/mixins/RTLObserverMixin.d.ts.map +1 -0
- package/types/mixins/ResizeObserverMixin.d.ts +12 -0
- package/types/mixins/ResizeObserverMixin.d.ts.map +1 -0
- package/types/mixins/RippleMixin.d.ts +92 -0
- package/types/mixins/RippleMixin.d.ts.map +1 -0
- package/types/mixins/ScrollListenerMixin.d.ts +41 -0
- package/types/mixins/ScrollListenerMixin.d.ts.map +1 -0
- package/types/mixins/SemiStickyMixin.d.ts +50 -0
- package/types/mixins/SemiStickyMixin.d.ts.map +1 -0
- package/types/mixins/ShapeMaskedMixin.d.ts +9 -0
- package/types/mixins/ShapeMaskedMixin.d.ts.map +1 -0
- package/types/mixins/ShapeMixin.d.ts +38 -0
- package/types/mixins/ShapeMixin.d.ts.map +1 -0
- package/types/mixins/StateMixin.d.ts +27 -0
- package/types/mixins/StateMixin.d.ts.map +1 -0
- package/types/mixins/TextFieldMixin.d.ts +1354 -0
- package/types/mixins/TextFieldMixin.d.ts.map +1 -0
- package/types/mixins/ThemableMixin.d.ts +9 -0
- package/types/mixins/ThemableMixin.d.ts.map +1 -0
- package/types/mixins/TooltipTriggerMixin.d.ts +106 -0
- package/types/mixins/TooltipTriggerMixin.d.ts.map +1 -0
- package/types/mixins/TouchTargetMixin.d.ts +3 -0
- package/types/mixins/TouchTargetMixin.d.ts.map +1 -0
- package/types/mixins/TypographyMixin.d.ts +17 -0
- package/types/mixins/TypographyMixin.d.ts.map +1 -0
- package/types/services/rtl.d.ts +3 -0
- package/types/services/rtl.d.ts.map +1 -0
- package/types/services/svgAlias.d.ts +13 -0
- package/types/services/svgAlias.d.ts.map +1 -0
- package/types/services/theme.d.ts +45 -0
- package/types/services/theme.d.ts.map +1 -0
- package/types/utils/cli.d.ts +3 -0
- package/types/utils/cli.d.ts.map +1 -0
- package/types/utils/function.d.ts +3 -0
- package/types/utils/function.d.ts.map +1 -0
- package/types/utils/jsx-runtime.d.ts +20 -0
- package/types/utils/jsx-runtime.d.ts.map +1 -0
- package/types/utils/material-color/blend.d.ts +34 -0
- package/types/utils/material-color/blend.d.ts.map +1 -0
- package/types/utils/material-color/hct/Cam16.d.ts +142 -0
- package/types/utils/material-color/hct/Cam16.d.ts.map +1 -0
- package/types/utils/material-color/hct/Hct.d.ts +93 -0
- package/types/utils/material-color/hct/Hct.d.ts.map +1 -0
- package/types/utils/material-color/hct/ViewingConditions.d.ts +69 -0
- package/types/utils/material-color/hct/ViewingConditions.d.ts.map +1 -0
- package/types/utils/material-color/hct/hctSolver.d.ts +30 -0
- package/types/utils/material-color/hct/hctSolver.d.ts.map +1 -0
- package/types/utils/material-color/helper.d.ts +8 -0
- package/types/utils/material-color/helper.d.ts.map +1 -0
- package/types/utils/material-color/palettes/CorePalette.d.ts +75 -0
- package/types/utils/material-color/palettes/CorePalette.d.ts.map +1 -0
- package/types/utils/material-color/palettes/TonalPalette.d.ts +38 -0
- package/types/utils/material-color/palettes/TonalPalette.d.ts.map +1 -0
- package/types/utils/material-color/scheme/Scheme.d.ts +264 -0
- package/types/utils/material-color/scheme/Scheme.d.ts.map +1 -0
- package/types/utils/material-color/utils/color.d.ts +172 -0
- package/types/utils/material-color/utils/color.d.ts.map +1 -0
- package/types/utils/material-color/utils/math.d.ts +94 -0
- package/types/utils/material-color/utils/math.d.ts.map +1 -0
- package/types/utils/pixelmatch.d.ts +22 -0
- package/types/utils/pixelmatch.d.ts.map +1 -0
- package/types/utils/popup.d.ts +106 -0
- package/types/utils/popup.d.ts.map +1 -0
- package/types/utils/searchParams.d.ts +3 -0
- package/types/utils/searchParams.d.ts.map +1 -0
- package/types/utils/svg.d.ts +7 -0
- package/types/utils/svg.d.ts.map +1 -0
- package/utils/{hct → material-color}/blend.js +8 -10
- package/utils/{hct → material-color/hct}/Cam16.js +196 -69
- package/utils/{hct → material-color/hct}/Hct.js +61 -19
- package/utils/{hct → material-color/hct}/ViewingConditions.js +3 -3
- package/utils/{hct → material-color/hct}/hctSolver.js +9 -16
- package/utils/{hct → material-color}/helper.js +11 -18
- package/utils/{hct → material-color/palettes}/CorePalette.js +79 -19
- package/utils/{hct → material-color/palettes}/TonalPalette.js +12 -4
- package/utils/material-color/scheme/Scheme.js +376 -0
- package/utils/{hct/colorUtils.js → material-color/utils/color.js} +61 -1
- package/utils/pixelmatch.js +360 -0
- package/utils/popup.js +127 -30
- package/utils/searchParams.js +19 -0
- package/components/ExtendedFab.js +0 -36
- package/components/Layout.js +0 -35
- package/components/ListSelect.js +0 -220
- package/components/Nav.js +0 -40
- package/components/Option.js +0 -91
- package/core/ICustomElement.d.ts +0 -291
- package/core/ICustomElement.js +0 -1
- package/core/identify.js +0 -40
- package/core/typings.d.ts +0 -136
- package/core/typings.js +0 -1
- package/mixins/SurfaceMixin.js +0 -181
- package/theming/loader.js +0 -22
- package/utils/hct/Scheme.js +0 -587
- /package/{utils/color_keywords.js → constants/colorKeywords.js} +0 -0
- /package/utils/{hct/mathUtils.js → material-color/utils/math.js} +0 -0
package/components/Menu.js
CHANGED
|
@@ -1,90 +1,29 @@
|
|
|
1
1
|
// https://www.w3.org/TR/wai-aria-practices/#menu
|
|
2
2
|
|
|
3
|
-
import './Surface.js';
|
|
4
3
|
import CustomElement from '../core/CustomElement.js';
|
|
5
4
|
import { attemptFocus } from '../core/dom.js';
|
|
6
5
|
import DensityMixin from '../mixins/DensityMixin.js';
|
|
6
|
+
import ElevationMixin from '../mixins/ElevationMixin.js';
|
|
7
7
|
import KeyboardNavMixin from '../mixins/KeyboardNavMixin.js';
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @typedef {Object} MenuStack
|
|
12
|
-
* @prop {HTMLElement} element
|
|
13
|
-
* @prop {Element} previousFocus
|
|
14
|
-
* @prop {Object} [state]
|
|
15
|
-
* @prop {Object} [previousState]
|
|
16
|
-
* @prop {MouseEvent|PointerEvent|HTMLElement|Element} [originalEvent]
|
|
17
|
-
* @prop {any} [pendingResizeOperation]
|
|
18
|
-
* @prop {window['history']['scrollRestoration']} [scrollRestoration]
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const supportsHTMLDialogElement = typeof HTMLDialogElement !== 'undefined';
|
|
22
|
-
/** @type {MenuStack[]} */
|
|
23
|
-
const OPEN_MENUS = [];
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @return {void}
|
|
27
|
-
*/
|
|
28
|
-
function onWindowResize() {
|
|
29
|
-
const lastOpenMenu = OPEN_MENUS.at(-1);
|
|
30
|
-
if (!lastOpenMenu || !lastOpenMenu.originalEvent) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (lastOpenMenu.pendingResizeOperation) {
|
|
34
|
-
cancelAnimationFrame(lastOpenMenu.pendingResizeOperation);
|
|
35
|
-
}
|
|
36
|
-
lastOpenMenu.pendingResizeOperation = requestAnimationFrame(() => {
|
|
37
|
-
lastOpenMenu.element.updateMenuPosition(lastOpenMenu.originalEvent);
|
|
38
|
-
lastOpenMenu.pendingResizeOperation = null;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {PopStateEvent} event
|
|
44
|
-
*/
|
|
45
|
-
function onPopState(event) {
|
|
46
|
-
if (!event.state) return;
|
|
47
|
-
const lastOpenMenu = OPEN_MENUS.at(-1);
|
|
48
|
-
if (!lastOpenMenu || !lastOpenMenu.previousState) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if ((lastOpenMenu.previousState === event.state) || Object.keys(event.state)
|
|
52
|
-
.every((key) => event.state[key] === lastOpenMenu.previousState[key])) {
|
|
53
|
-
lastOpenMenu.element.close();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** @param {BeforeUnloadEvent} event */
|
|
58
|
-
function onBeforeUnload(event) {
|
|
59
|
-
if (!OPEN_MENUS.length) return;
|
|
60
|
-
console.warn('Menu was open during page unload (refresh?).');
|
|
61
|
-
}
|
|
8
|
+
import PopupMixin from '../mixins/PopupMixin.js';
|
|
9
|
+
import ShapeMixin from '../mixins/ShapeMixin.js';
|
|
10
|
+
import ThemableMixin from '../mixins/ThemableMixin.js';
|
|
62
11
|
|
|
63
12
|
export default CustomElement
|
|
13
|
+
.extend()
|
|
14
|
+
.mixin(ThemableMixin)
|
|
15
|
+
.mixin(ElevationMixin)
|
|
16
|
+
.mixin(ShapeMixin)
|
|
17
|
+
.mixin(PopupMixin)
|
|
64
18
|
.mixin(DensityMixin)
|
|
65
19
|
.mixin(KeyboardNavMixin)
|
|
66
|
-
.extend()
|
|
67
|
-
.observe({
|
|
68
|
-
open: 'boolean',
|
|
69
|
-
flow: {
|
|
70
|
-
type: 'string',
|
|
71
|
-
/** @type {'corner'|'adjacent'|'overflow'|'vcenter'|'hcenter'|'center'} */
|
|
72
|
-
value: null,
|
|
73
|
-
},
|
|
74
|
-
submenu: 'boolean',
|
|
75
|
-
modal: 'boolean',
|
|
76
|
-
_isNativeModal: 'boolean',
|
|
77
|
-
color: { empty: 'surface' },
|
|
78
|
-
ink: 'string',
|
|
79
|
-
elevation: { empty: 2 },
|
|
80
|
-
outlined: 'boolean',
|
|
81
|
-
})
|
|
82
20
|
.set({
|
|
83
|
-
|
|
84
|
-
|
|
21
|
+
flow: 'corner',
|
|
22
|
+
_useScrim: false,
|
|
85
23
|
/** @type {WeakRef<HTMLElement>} */
|
|
86
24
|
_cascader: null,
|
|
87
|
-
|
|
25
|
+
/** @type {WeakRef<HTMLElement>} */
|
|
26
|
+
_submenu: null,
|
|
88
27
|
})
|
|
89
28
|
.define({
|
|
90
29
|
kbdNavChildren() {
|
|
@@ -107,484 +46,87 @@ export default CustomElement
|
|
|
107
46
|
this._cascader = value ? new WeakRef(value) : null;
|
|
108
47
|
},
|
|
109
48
|
},
|
|
49
|
+
submenu: {
|
|
50
|
+
get() {
|
|
51
|
+
return this._submenu?.deref();
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* @param {HTMLElement} value
|
|
55
|
+
*/
|
|
56
|
+
set(value) {
|
|
57
|
+
this._submenu = value ? new WeakRef(value) : null;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
})
|
|
61
|
+
.recompose(({ refs: { scrim } }) => {
|
|
62
|
+
scrim.setAttribute('invisible', '');
|
|
63
|
+
// Wrap slot in scroller
|
|
110
64
|
})
|
|
111
|
-
.html/* html */`
|
|
112
|
-
<dialog id=dialog role=menu aria-hidden=${({ open }) => (open ? 'false' : 'true')}>
|
|
113
|
-
<div id=scrim aria-hidden=true modal={modal}></div>
|
|
114
|
-
<form id=form method=dialog role=none>
|
|
115
|
-
<mdw-surface id=surface elevation={elevation} color={color} ink={ink} outlined={outlined}>
|
|
116
|
-
<div id=scroller>
|
|
117
|
-
<slot id=slot on-slotchange={refreshTabIndexes}></slot>
|
|
118
|
-
</div>
|
|
119
|
-
</mdw-surface>
|
|
120
|
-
<slot id=submenu-slot name=submenu></slot>
|
|
121
|
-
</form>
|
|
122
|
-
</dialog>
|
|
123
|
-
`
|
|
124
65
|
.css`
|
|
125
66
|
/* https://m3.material.io/components/menus/specs */
|
|
126
67
|
|
|
127
68
|
:host {
|
|
128
|
-
--mdw-
|
|
129
|
-
--mdw-
|
|
130
|
-
/* Normal */
|
|
131
|
-
--mdw-menu__transform-origin-x: var(--mdw-menu__transform-origin-inline-start);
|
|
132
|
-
/* Down */
|
|
133
|
-
--mdw-menu__transform-origin-y: top;
|
|
134
|
-
--mdw-menu__inline-base: 56px;
|
|
135
|
-
--mdw-menu__size: 2;
|
|
136
|
-
--mdw-bg: var(--mdw-color__surface);
|
|
69
|
+
--mdw-shape__size: var(--mdw-shape__extra-small);
|
|
70
|
+
--mdw-bg: var(--mdw-color__surface-container);
|
|
137
71
|
--mdw-ink: var(--mdw-color__on-surface);
|
|
138
|
-
position: absolute;
|
|
139
|
-
/* Default position is bottom */
|
|
140
|
-
/* Default direction is start */
|
|
141
|
-
inset-block: 100% auto;
|
|
142
|
-
inset-inline: auto 0;
|
|
143
|
-
|
|
144
72
|
display: block;
|
|
145
|
-
/* Hide scrollbar */
|
|
146
|
-
-ms-overflow-style: none;
|
|
147
|
-
/* Scroll mask */
|
|
148
|
-
overscroll-behavior: none;
|
|
149
|
-
overscroll-behavior: contain;
|
|
150
|
-
scrollbar-width: none;
|
|
151
|
-
|
|
152
|
-
pointer-events: none;
|
|
153
|
-
|
|
154
|
-
transform-origin: var(--mdw-menu__transform-origin-x) var(--mdw-menu__transform-origin-y);
|
|
155
|
-
|
|
156
|
-
transition-duration: motion.$fadeOutDuration;
|
|
157
|
-
transition-property: none;
|
|
158
|
-
transition-timing-function: motion.$decelerateEasing;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
:host(::after) {
|
|
162
|
-
content: '';
|
|
163
|
-
|
|
164
|
-
display: block;
|
|
165
|
-
|
|
166
|
-
block-size: 200%;
|
|
167
|
-
inline-size: 200%;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
:host(::-webkit-scrollbar) {
|
|
171
|
-
display: none;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
dialog {
|
|
175
|
-
position: fixed;
|
|
176
|
-
inset: 0;
|
|
177
|
-
|
|
178
|
-
box-sizing: border-box;
|
|
179
|
-
block-size:100%;
|
|
180
|
-
max-block-size: none;
|
|
181
|
-
inline-size:100%;
|
|
182
|
-
max-inline-size: none;
|
|
183
|
-
margin: 0;
|
|
184
|
-
border: none;
|
|
185
|
-
padding: 0;
|
|
186
|
-
|
|
187
|
-
opacity: 0;
|
|
188
|
-
visibility: hidden;
|
|
189
|
-
z-index: 24;
|
|
190
|
-
|
|
191
|
-
background-color: transparent;
|
|
192
|
-
|
|
193
|
-
transition: none;
|
|
194
|
-
transition-property: opacity;
|
|
195
|
-
will-change: opacity;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
dialog::backdrop {
|
|
199
|
-
/** Use scrim instead */
|
|
200
|
-
display: none;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
dialog[aria-hidden="false"],
|
|
204
|
-
dialog:modal {
|
|
205
|
-
display: block;
|
|
206
|
-
|
|
207
|
-
pointer-events: none;
|
|
208
|
-
|
|
209
|
-
opacity: 1;
|
|
210
|
-
visibility: visible;
|
|
211
|
-
|
|
212
|
-
transition-duration: var(--mdw-dialog__fade-in-duration);
|
|
213
|
-
transition-property: opacity;
|
|
214
|
-
transition-timing-function: var(--mdw-dialog__deceleration-easing);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
#scrim {
|
|
218
|
-
position: fixed;
|
|
219
|
-
inset: 0;
|
|
220
|
-
|
|
221
|
-
overflow-y: scroll;
|
|
222
|
-
overscroll-behavior: none;
|
|
223
|
-
overscroll-behavior: contain;
|
|
224
|
-
scrollbar-width: none;
|
|
225
|
-
|
|
226
|
-
block-size: 100%;
|
|
227
|
-
inline-size: 100%;
|
|
228
|
-
|
|
229
|
-
cursor: default;
|
|
230
|
-
pointer-events: auto;
|
|
231
|
-
-webkit-tap-highlight-color: transparent;
|
|
232
|
-
|
|
233
|
-
visibility: hidden; /* Only show if [modal] */
|
|
234
|
-
|
|
235
|
-
z-index:0;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
#form {
|
|
239
|
-
display: contents;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
#scrim::-webkit-scrollbar {
|
|
243
|
-
display: none;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
#scrim::after {
|
|
247
|
-
content: '';
|
|
248
|
-
|
|
249
|
-
display: block;
|
|
250
|
-
|
|
251
|
-
block-size: 200%;
|
|
252
|
-
inline-size: 200%;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
#surface {
|
|
256
|
-
--mdw-shape__size: var(--mdw-shape__extra-small);
|
|
257
|
-
position: sticky;
|
|
258
73
|
|
|
259
|
-
|
|
260
|
-
flex-direction: column;
|
|
261
|
-
|
|
262
|
-
inline-size: calc(var(--mdw-menu__size) * var(--mdw-menu__inline-base));
|
|
74
|
+
inline-size: auto;
|
|
263
75
|
min-inline-size: calc(var(--mdw-menu__inline-base) * 2);
|
|
264
76
|
max-inline-size: 100vw;
|
|
265
|
-
flex:1;
|
|
266
77
|
|
|
267
|
-
|
|
268
|
-
/* background-color: rgb(var(--mdw-color__surface)); */
|
|
269
|
-
/* color: rgb(var(--mdw-color__on-surface)); */
|
|
270
|
-
/* stylelint-disable-next-line liberty/use-logical-spec */
|
|
271
|
-
will-change: top, left;
|
|
272
|
-
}
|
|
78
|
+
filter: var(--mdw-elevation__drop-shadow__2);
|
|
273
79
|
|
|
274
|
-
|
|
275
|
-
#surface {
|
|
276
|
-
position: absolute;
|
|
277
|
-
}
|
|
80
|
+
background-color: rgb(var(--mdw-bg));
|
|
278
81
|
}
|
|
279
82
|
|
|
280
|
-
#
|
|
281
|
-
display:
|
|
282
|
-
align-items: stretch;
|
|
283
|
-
flex-direction: column;
|
|
284
|
-
overflow-y: auto;
|
|
285
|
-
overscroll-behavior: none;
|
|
286
|
-
overscroll-behavior: contain;
|
|
287
|
-
|
|
288
|
-
flex: 1;
|
|
289
|
-
|
|
290
|
-
padding-block: 8px;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
#scrim[modal] {
|
|
294
|
-
visibility: visible;
|
|
83
|
+
#form {
|
|
84
|
+
display: contents;
|
|
295
85
|
}
|
|
296
86
|
`
|
|
297
87
|
.methods({
|
|
88
|
+
showModal(...args) {
|
|
89
|
+
this._useScrim = true;
|
|
90
|
+
const result = this.showPopup(...args);
|
|
91
|
+
this._useScrim = false;
|
|
92
|
+
return result;
|
|
93
|
+
},
|
|
298
94
|
focus() {
|
|
299
95
|
const [firstItem] = this.kbdNavChildren;
|
|
300
96
|
if (!attemptFocus(firstItem)) {
|
|
301
97
|
this.focusNext(firstItem);
|
|
302
98
|
}
|
|
303
99
|
},
|
|
304
|
-
/**
|
|
305
|
-
* @param {DOMRect|Element} [anchor]
|
|
306
|
-
* @return {void}
|
|
307
|
-
*/
|
|
308
|
-
updateMenuPosition(anchor) {
|
|
309
|
-
const surface = this.refs.surface;
|
|
310
|
-
surface.style.setProperty('max-height', 'none');
|
|
311
|
-
surface.style.setProperty('width', 'auto');
|
|
312
|
-
const newSize = Math.ceil(surface.clientWidth / 56);
|
|
313
|
-
surface.style.removeProperty('width');
|
|
314
|
-
surface.style.setProperty('--mdw-menu__size', newSize.toString(10));
|
|
315
|
-
|
|
316
|
-
/** @type {import('../utils/popup.js').CanAnchorPopUpOptions} */
|
|
317
|
-
const anchorOptions = {
|
|
318
|
-
anchor: anchor ?? this.getBoundingClientRect(),
|
|
319
|
-
width: surface.clientWidth,
|
|
320
|
-
height: surface.clientHeight,
|
|
321
|
-
// margin,
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
const isPageRTL = (getComputedStyle(this).direction === 'rtl');
|
|
325
|
-
const xStart = isPageRTL ? 'right' : 'left';
|
|
326
|
-
const xEnd = isPageRTL ? 'left' : 'right';
|
|
327
|
-
|
|
328
|
-
/* Automatic Positioning
|
|
329
|
-
*
|
|
330
|
-
* Positions:
|
|
331
|
-
* 3 7 4
|
|
332
|
-
* ┌─────────┐
|
|
333
|
-
* │ │
|
|
334
|
-
* 5 │ 9 │ 6
|
|
335
|
-
* │ │
|
|
336
|
-
* └─────────┘
|
|
337
|
-
* 1 8 2
|
|
338
|
-
*
|
|
339
|
-
* 1: Bottom Left
|
|
340
|
-
* 2: Bottom Right
|
|
341
|
-
* 3: Top Left
|
|
342
|
-
* 4: Top Right
|
|
343
|
-
* 5: VCenter Left
|
|
344
|
-
* 6: VCenter Right
|
|
345
|
-
* 7: HCenter Top
|
|
346
|
-
* 8: HCenter Bottom
|
|
347
|
-
* 9: VCenter HCenter
|
|
348
|
-
*
|
|
349
|
-
* Directions:
|
|
350
|
-
* a - Down LTR
|
|
351
|
-
* b - Down RTL
|
|
352
|
-
* c - Up LTR
|
|
353
|
-
* d - Up RTL
|
|
354
|
-
* e - LTR
|
|
355
|
-
* f - RTL
|
|
356
|
-
* g - Down
|
|
357
|
-
* h - Up
|
|
358
|
-
* i - Center
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
* 16 total combos
|
|
362
|
-
* 1a 1b 1c 1d └↘ └↙ └↗ └↖
|
|
363
|
-
* 2a 2b 2c 2d ┘↘ ┘↙ ┘↗ ┘↖
|
|
364
|
-
* 3a 3b 3c 3d ┌↘ ┌↙ ┌↗ ┌↖
|
|
365
|
-
* 4a 4b 4c 4d ┐↘ ┐↙ ┐↗ ┐↖
|
|
366
|
-
*
|
|
367
|
-
* Avoid using opposite angle
|
|
368
|
-
*
|
|
369
|
-
* 1a XX 1c 1d └↘ ██ └↗ └↖
|
|
370
|
-
* XX 2b 2c 2d ██ ┘↙ ┘↗ ┘↖
|
|
371
|
-
* 1a 3b 3c XX ┌↘ ┌↙ ┌↗ ██
|
|
372
|
-
* 4a 4b XX 4d ┐↘ ┐↙ ██ ┐↖
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* Preference Order:
|
|
376
|
-
* - Flow from corner 1a 2b 3c 4d └↘ ┘↙ ┌↗ ┐↖
|
|
377
|
-
* - Open adjacent to target 4a 3b 2c 1d ┐↘ ┌↙ ┘↗ └↖
|
|
378
|
-
* - Overlay target 3a 4b 1c 2d ┌↘ ┐↙ └↗ ┘↖
|
|
379
|
-
* - Open from horizontal side 5e 6f │→ │←
|
|
380
|
-
* - Open from center 9i █·
|
|
381
|
-
*/
|
|
382
|
-
|
|
383
|
-
/** @type {import('../utils/popup.js').CanAnchorPopUpOptions[]} */
|
|
384
|
-
const preferences = [
|
|
385
|
-
(!this.submenu && (this.flow ?? 'corner') === 'corner') ? [
|
|
386
|
-
{ clientY: 'bottom', clientX: xStart },
|
|
387
|
-
{ clientY: 'bottom', clientX: xEnd },
|
|
388
|
-
{ clientY: 'top', clientX: xStart },
|
|
389
|
-
{ clientY: 'top', clientX: xEnd },
|
|
390
|
-
] : [],
|
|
391
|
-
(this.submenu || (this.flow ?? 'adjacent') === 'adjacent') ? [
|
|
392
|
-
{ clientY: 'top', clientX: xEnd, directionX: xEnd, directionY: 'down' },
|
|
393
|
-
{ clientY: 'top', clientX: xStart, directionX: xStart, directionY: 'down' },
|
|
394
|
-
{ clientY: 'bottom', clientX: xEnd, directionX: xEnd, directionY: 'up' },
|
|
395
|
-
{ clientY: 'bottom', clientX: xStart, directionX: xStart, directionY: 'up' },
|
|
396
|
-
] : [],
|
|
397
|
-
(!this.submenu && (this.flow ?? 'overlay') === 'overlay') ? [
|
|
398
|
-
{ clientY: 'top', clientX: xStart, directionX: xEnd, directionY: 'down' },
|
|
399
|
-
{ clientY: 'top', clientX: xEnd, directionX: xStart, directionY: 'down' },
|
|
400
|
-
{ clientY: 'bottom', clientX: xStart, directionX: xEnd, directionY: 'up' },
|
|
401
|
-
{ clientY: 'bottom', clientX: xEnd, directionX: xStart, directionY: 'up' },
|
|
402
|
-
] : [],
|
|
403
|
-
(!this.submenu && (this.flow ?? 'vcenter') === 'vcenter') ? [
|
|
404
|
-
{ clientY: 'center', clientX: xEnd, directionX: xEnd, directionY: 'center' },
|
|
405
|
-
{ clientY: 'center', clientX: xStart, directionX: xStart, directionY: 'center' },
|
|
406
|
-
] : [],
|
|
407
|
-
(!this.submenu && (this.flow ?? 'hcenter') === 'hcenter') ? [
|
|
408
|
-
{ clientY: 'bottom', clientX: 'center', directionX: 'center', directionY: 'down' },
|
|
409
|
-
{ clientY: 'top', clientX: 'center', directionX: 'center', directionY: 'up' },
|
|
410
|
-
] : [],
|
|
411
|
-
(!this.submenu && (this.flow ?? 'center') === 'center') ? [
|
|
412
|
-
{ clientY: 'center', clientX: 'center', directionX: 'center', directionY: 'center' },
|
|
413
|
-
] : [],
|
|
414
|
-
].flat();
|
|
415
|
-
|
|
416
|
-
let anchorResult;
|
|
417
|
-
for (const preference of preferences) {
|
|
418
|
-
anchorResult = canAnchorPopup({
|
|
419
|
-
...anchorOptions,
|
|
420
|
-
...preference,
|
|
421
|
-
});
|
|
422
|
-
if (anchorResult) break;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (!anchorResult) {
|
|
426
|
-
anchorResult = canAnchorPopup({
|
|
427
|
-
...anchorOptions,
|
|
428
|
-
...preferences[0],
|
|
429
|
-
force: true,
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
surface.style.setProperty('inset-block-start', `${anchorResult.pageY}px`);
|
|
434
|
-
surface.style.setProperty('inset-inline-start', `${anchorResult.pageX}px`);
|
|
435
|
-
surface.style.setProperty('margin', '0');
|
|
436
|
-
surface.style.setProperty('transform-origin', `${anchorResult.transformOriginY} ${anchorResult.transformOriginX}`);
|
|
437
|
-
surface.scrollIntoView();
|
|
438
|
-
},
|
|
439
|
-
/**
|
|
440
|
-
* @param {MouseEvent|PointerEvent|HTMLElement|Element} source
|
|
441
|
-
* @return {boolean} handled
|
|
442
|
-
*/
|
|
443
|
-
showModal(source) {
|
|
444
|
-
if (this.open) return false;
|
|
445
|
-
this.modal = true;
|
|
446
|
-
if (supportsHTMLDialogElement) {
|
|
447
|
-
this._dialog.showModal();
|
|
448
|
-
this._isNativeModal = true;
|
|
449
|
-
}
|
|
450
|
-
return this.showPopup(source);
|
|
451
|
-
},
|
|
452
|
-
/**
|
|
453
|
-
* @param {MouseEvent|PointerEvent|HTMLElement|Element} source
|
|
454
|
-
* @return {boolean} handled
|
|
455
|
-
*/
|
|
456
|
-
showPopup(source) {
|
|
457
|
-
if (this.open) return false;
|
|
458
|
-
this.open = true;
|
|
459
|
-
|
|
460
|
-
const previousFocus = source instanceof HTMLElement ? source : document.activeElement;
|
|
461
|
-
this.updateMenuPosition(source);
|
|
462
|
-
if (supportsHTMLDialogElement && !this._dialog.open) {
|
|
463
|
-
this._dialog.show();
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
const newState = { hash: Math.random().toString(36).slice(2, 18) };
|
|
467
|
-
let previousState = null;
|
|
468
|
-
|
|
469
|
-
if (!window.history.state) {
|
|
470
|
-
// Create new previous state
|
|
471
|
-
window.history.replaceState({
|
|
472
|
-
hash: Math.random().toString(36).slice(2, 18),
|
|
473
|
-
}, document.title);
|
|
474
|
-
}
|
|
475
|
-
previousState = window.history.state;
|
|
476
|
-
const scrollRestoration = window.history.scrollRestoration;
|
|
477
|
-
window.history.scrollRestoration = 'manual';
|
|
478
|
-
window.history.pushState(newState, document.title);
|
|
479
|
-
console.debug('Menu pushed page');
|
|
480
|
-
window.addEventListener('popstate', onPopState);
|
|
481
|
-
window.addEventListener('beforeunload', onBeforeUnload);
|
|
482
|
-
|
|
483
|
-
window.addEventListener('resize', onWindowResize);
|
|
484
|
-
window.addEventListener('scroll', onWindowResize);
|
|
485
|
-
|
|
486
|
-
OPEN_MENUS.push({
|
|
487
|
-
element: this,
|
|
488
|
-
previousFocus,
|
|
489
|
-
state: newState,
|
|
490
|
-
previousState,
|
|
491
|
-
originalEvent: source,
|
|
492
|
-
scrollRestoration,
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
this.focus();
|
|
496
|
-
|
|
497
|
-
return true;
|
|
498
|
-
},
|
|
499
|
-
/**
|
|
500
|
-
* @param {boolean} returnFocus Return focus to element focused during open
|
|
501
|
-
* @return {boolean} handled
|
|
502
|
-
*/
|
|
503
|
-
close(returnFocus = true) {
|
|
504
|
-
if (!this.open) return false;
|
|
505
|
-
if (this._closing) return false;
|
|
506
|
-
this._closing = true;
|
|
507
|
-
this.modal = false;
|
|
508
|
-
if (this._isNativeModal) {
|
|
509
|
-
this._isNativeModal = false;
|
|
510
|
-
} else {
|
|
511
|
-
const main = document.querySelector('main');
|
|
512
|
-
if (main) {
|
|
513
|
-
main.removeAttribute('aria-hidden');
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
// if (this.dialogElement.getAttribute('aria-hidden') === 'true') return false;
|
|
517
|
-
if (supportsHTMLDialogElement && this._dialog.open) {
|
|
518
|
-
const previousFocus = document.activeElement;
|
|
519
|
-
// Closing a native dialog will return focus automatically.
|
|
520
|
-
this._dialog.close();
|
|
521
|
-
if (!attemptFocus(previousFocus, { preventScroll: true })) {
|
|
522
|
-
document.activeElement?.blur?.();
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
// Will invoke observed attribute change: ('aria-hidden', 'true');
|
|
527
|
-
|
|
528
|
-
this.open = false;
|
|
529
|
-
this.dispatchEvent(new Event('close'));
|
|
530
|
-
|
|
531
|
-
const len = OPEN_MENUS.length;
|
|
532
|
-
for (let i = len - 1; i >= 0; i--) {
|
|
533
|
-
const entry = OPEN_MENUS[i];
|
|
534
|
-
if (entry.element === this) {
|
|
535
|
-
if (entry.state && window.history && window.history.state && entry.state.hash === window.history.state.hash) {
|
|
536
|
-
window.removeEventListener('popstate', onPopState);
|
|
537
|
-
window.history.back();
|
|
538
|
-
// Back does not set state immediately
|
|
539
|
-
// Needed to track submenu
|
|
540
|
-
// TODO: use window.history.go(indexDelta) instead for Safari (not Wekbit) submenu support
|
|
541
|
-
window.history.replaceState(entry.previousState, document.title);
|
|
542
|
-
window.history.scrollRestoration = entry.scrollRestoration || 'auto';
|
|
543
|
-
window.addEventListener('popstate', onPopState);
|
|
544
|
-
} else {
|
|
545
|
-
console.warn('Menu state mismatch?', entry, window.history.state);
|
|
546
|
-
}
|
|
547
|
-
if (returnFocus) {
|
|
548
|
-
entry.previousFocus?.focus?.({ preventScroll: true });
|
|
549
|
-
}
|
|
550
|
-
OPEN_MENUS.splice(i, 1);
|
|
551
|
-
break;
|
|
552
|
-
} else if (this.contains(entry.element)) {
|
|
553
|
-
console.debug('Closing submenu first');
|
|
554
|
-
entry.element.close(false);
|
|
555
|
-
console.debug('Sub menu closed. Continuing...');
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (!OPEN_MENUS.length) {
|
|
559
|
-
window.removeEventListener('popstate', onPopState);
|
|
560
|
-
window.removeEventListener('beforeunload', onBeforeUnload);
|
|
561
|
-
window.removeEventListener('resize', onWindowResize);
|
|
562
|
-
console.debug('All menus closed');
|
|
563
|
-
}
|
|
564
|
-
this._closing = false;
|
|
565
|
-
return true;
|
|
566
|
-
},
|
|
567
100
|
/**
|
|
568
101
|
* @param {HTMLElement} cascader Element that calls for submenu cascade
|
|
569
102
|
*/
|
|
570
103
|
cascade(cascader) {
|
|
571
104
|
this.cascader = cascader;
|
|
572
|
-
this.showPopup(cascader);
|
|
573
|
-
},
|
|
574
|
-
/**
|
|
575
|
-
* @param {MouseEvent|PointerEvent|HTMLElement|Element} source
|
|
576
|
-
* @return {boolean} handled
|
|
577
|
-
*/
|
|
578
|
-
show(source) {
|
|
579
|
-
// Auto-select type based on default platform convention
|
|
580
|
-
// Mac OS X / iPad does not expect clickthrough
|
|
581
|
-
if (navigator.userAgent.includes('Mac OS X')) {
|
|
582
|
-
return this.showModal(source);
|
|
583
|
-
}
|
|
584
|
-
return this.showPopup(source);
|
|
105
|
+
this.showPopup(cascader, true, 'adjacent');
|
|
585
106
|
},
|
|
586
107
|
})
|
|
587
108
|
.events({
|
|
109
|
+
'mdw-menu-item:cascade'(event) {
|
|
110
|
+
const menuItem = event.target;
|
|
111
|
+
const subMenuId = event.detail;
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
|
|
114
|
+
const submenu = this.getRootNode().getElementById(subMenuId);
|
|
115
|
+
this.submenu = submenu;
|
|
116
|
+
submenu.cascade(menuItem);
|
|
117
|
+
},
|
|
118
|
+
'mdw-menu-item:cascader-blur'() {
|
|
119
|
+
const submenu = this.submenu;
|
|
120
|
+
if (!submenu) return;
|
|
121
|
+
// Wait for focus event (if mouse focus on sub menu item)
|
|
122
|
+
queueMicrotask(() => {
|
|
123
|
+
// Stay open if submenu is focused
|
|
124
|
+
if (submenu && submenu.matches(':focus-within,:focus')) return;
|
|
125
|
+
|
|
126
|
+
submenu.close(false);
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
|
|
588
130
|
'~click'(event) {
|
|
589
131
|
if (this !== event.target) return;
|
|
590
132
|
// Clicked self (scrim-like)
|
|
@@ -608,7 +150,7 @@ export default CustomElement
|
|
|
608
150
|
// Unless menu hiding is cancelled
|
|
609
151
|
case 'ArrowLeft':
|
|
610
152
|
case 'ArrowRight':
|
|
611
|
-
if (!this.submenu) break;
|
|
153
|
+
// if (!this.submenu) break;
|
|
612
154
|
if (getComputedStyle(this).direction === 'rtl') {
|
|
613
155
|
if (event.key === 'ArrowLeft') break;
|
|
614
156
|
} else if (event.key === 'ArrowRight') break;
|
|
@@ -622,17 +164,16 @@ export default CustomElement
|
|
|
622
164
|
default:
|
|
623
165
|
}
|
|
624
166
|
},
|
|
625
|
-
focusout(
|
|
167
|
+
focusout() {
|
|
626
168
|
if (!this.open) return;
|
|
627
169
|
if (this.modal) return;
|
|
628
170
|
// Wait until end of event loop cycle to see if focus really is lost
|
|
629
171
|
queueMicrotask(() => {
|
|
630
172
|
if (this.matches(':focus-within')) return;
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
173
|
+
const { cascader, submenu } = this;
|
|
174
|
+
|
|
175
|
+
if (cascader && cascader.matches(':is(:focus-within,:focus)')) return;
|
|
176
|
+
if (submenu && submenu.matches(':is(:focus-within,:focus)')) return;
|
|
636
177
|
this.close(false);
|
|
637
178
|
});
|
|
638
179
|
},
|