@shortfuse/materialdesignweb 0.8.0 → 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 +32 -24
- package/bin/mdw-css.js +1 -1
- package/components/Badge.js +12 -5
- package/components/Body.js +3 -0
- package/components/BottomAppBar.js +1 -8
- package/components/BottomSheet.js +424 -0
- package/components/Box.js +11 -49
- package/components/Button.js +61 -82
- package/components/Card.js +56 -61
- package/components/Checkbox.js +7 -25
- package/components/CheckboxIcon.js +10 -28
- package/components/Chip.js +13 -11
- package/components/Dialog.js +49 -98
- package/components/Display.js +55 -0
- package/components/Fab.js +83 -17
- package/components/FabContainer.js +48 -0
- package/components/FilterChip.js +34 -32
- package/components/Grid.js +176 -0
- package/components/Headline.js +5 -28
- package/components/Icon.js +54 -69
- package/components/IconButton.js +71 -120
- package/components/Input.js +669 -83
- package/components/InputChip.js +161 -0
- package/components/Label.js +3 -0
- package/components/List.js +1 -5
- package/components/ListItem.js +39 -23
- package/components/ListOption.js +79 -62
- package/components/Listbox.js +19 -10
- package/components/Menu.js +8 -18
- package/components/MenuItem.js +25 -26
- package/components/NavBar.js +53 -19
- package/components/NavDrawer.js +15 -15
- package/components/NavDrawerItem.js +2 -4
- package/components/NavItem.js +40 -33
- package/components/NavRail.js +23 -21
- package/components/NavRailItem.js +5 -2
- package/components/Page.js +105 -0
- package/components/Pane.js +18 -0
- package/components/Popup.js +17 -8
- package/components/Radio.js +2 -5
- package/components/RadioIcon.js +10 -14
- package/components/Ripple.js +11 -7
- package/components/Root.js +209 -0
- package/components/Scrim.js +87 -0
- package/components/Search.js +12 -20
- package/components/SegmentedButton.js +33 -36
- package/components/SegmentedButtonGroup.js +9 -3
- package/components/Select.js +6 -7
- package/components/Shape.js +5 -65
- package/components/SideSheet.js +308 -0
- package/components/Slider.js +71 -34
- package/components/Snackbar.js +22 -16
- package/components/SnackbarContainer.js +42 -0
- package/components/Surface.js +15 -10
- package/components/Switch.js +3 -16
- package/components/SwitchIcon.js +40 -32
- package/components/Tab.js +57 -38
- package/components/TabContent.js +1 -0
- package/components/TabList.js +60 -32
- package/components/TabPanel.js +1 -1
- package/components/Table.js +116 -0
- package/components/TextArea.js +16 -15
- package/components/Title.js +4 -9
- package/components/Tooltip.js +43 -21
- package/components/TopAppBar.js +56 -78
- package/constants/shapes.js +36 -0
- package/constants/typography.js +127 -0
- package/core/Composition.js +354 -192
- package/core/CompositionAdapter.js +11 -12
- package/core/CustomElement.js +588 -236
- package/core/css.js +117 -12
- package/core/customTypes.js +120 -25
- package/core/dom.js +17 -11
- package/core/jsonMergePatch.js +12 -10
- package/core/observe.js +298 -253
- package/core/optimizations.js +9 -9
- package/core/template.js +14 -57
- package/dist/index.min.js +85 -115
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +1 -1
- package/dom/HTMLOptionsCollectionProxy.js +106 -0
- package/{theming/themableMixinLoader.js → loaders/palette.js} +4 -3
- package/loaders/theme.js +12 -0
- package/mixins/AriaReflectorMixin.js +53 -13
- package/mixins/AriaToolbarMixin.js +3 -0
- package/mixins/ControlMixin.js +76 -33
- package/mixins/DelegatesFocusMixin.js +54 -0
- package/mixins/DensityMixin.js +2 -2
- package/mixins/ElevationMixin.js +62 -0
- package/mixins/FlexableMixin.js +66 -37
- package/mixins/FormAssociatedMixin.js +60 -8
- package/mixins/HyperlinkMixin.js +66 -0
- package/mixins/InputMixin.js +205 -32
- package/mixins/KeyboardNavMixin.js +8 -6
- package/mixins/NavigationListenerMixin.js +33 -0
- package/mixins/PopupMixin.js +176 -208
- package/mixins/ResizeObserverMixin.js +16 -4
- package/mixins/RippleMixin.js +8 -6
- package/mixins/ScrollListenerMixin.js +1 -1
- package/mixins/SemiStickyMixin.js +44 -98
- package/mixins/ShapeMaskedMixin.js +117 -0
- package/mixins/ShapeMixin.js +22 -204
- package/mixins/StateMixin.js +70 -34
- package/mixins/TextFieldMixin.js +107 -143
- package/mixins/ThemableMixin.js +44 -56
- package/mixins/TooltipTriggerMixin.js +291 -359
- package/mixins/TouchTargetMixin.js +1 -1
- package/mixins/TypographyMixin.js +121 -0
- package/package.json +110 -74
- package/services/rtl.js +10 -0
- package/services/svgAlias.js +17 -0
- package/{theming/index.js → services/theme.js} +24 -174
- 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/material-color/scheme/Scheme.js +1 -1
- package/utils/pixelmatch.js +360 -0
- package/utils/popup.js +86 -10
- package/utils/searchParams.js +19 -0
- package/components/ExtendedFab.js +0 -32
- package/components/Layout.js +0 -504
- package/components/Nav.js +0 -38
- package/core/DomAdapter.js +0 -586
- package/core/ICustomElement.d.ts +0 -291
- package/core/ICustomElement.js +0 -1
- package/core/test.js +0 -126
- package/core/typings.d.ts +0 -142
- package/core/typings.js +0 -1
- package/mixins/SurfaceMixin.js +0 -127
- package/theming/loader.js +0 -22
- /package/{utils/color_keywords.js → constants/colorKeywords.js} +0 -0
package/components/Input.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ */
|
|
2
|
+
/* https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.combobox.iseditable?view=windowsdesktop-7.0#remarks */
|
|
2
3
|
|
|
3
4
|
import CustomElement from '../core/CustomElement.js';
|
|
4
5
|
import InputMixin from '../mixins/InputMixin.js';
|
|
@@ -22,6 +23,8 @@ function getSharedPopup() {
|
|
|
22
23
|
sharedPopup.shapeStyle = 'extra-small';
|
|
23
24
|
sharedPopup.color = 'surface';
|
|
24
25
|
sharedPopup.matchSourceWidth = true;
|
|
26
|
+
sharedPopup.flow = 'corner';
|
|
27
|
+
sharedPopup.elevation = 2;
|
|
25
28
|
}
|
|
26
29
|
return sharedPopup;
|
|
27
30
|
}
|
|
@@ -34,26 +37,57 @@ export default CustomElement
|
|
|
34
37
|
.mixin(TextFieldMixin)
|
|
35
38
|
.mixin(ResizeObserverMixin)
|
|
36
39
|
.observe({
|
|
37
|
-
|
|
40
|
+
autocompleteInline: 'boolean',
|
|
41
|
+
autocompleteList: 'string',
|
|
42
|
+
autosuggestInline: 'boolean',
|
|
43
|
+
/** If true, when listbox is open, arrow navigation will automatically select options. */
|
|
44
|
+
autoSelect: 'boolean',
|
|
38
45
|
_expanded: 'boolean',
|
|
46
|
+
/** If true, when listbox is open, <ESC> accepts current suggestion, same as <Enter>. */
|
|
47
|
+
acceptOnEscape: 'boolean',
|
|
39
48
|
_listbox: {
|
|
40
49
|
type: 'object',
|
|
41
|
-
/** @type {Listbox} */
|
|
50
|
+
/** @type {InstanceType<Listbox>} */
|
|
42
51
|
value: null,
|
|
43
52
|
},
|
|
44
53
|
_focusedValue: 'string',
|
|
45
|
-
_focusedIndex: { value: -1 },
|
|
46
54
|
_focusedPosInSet: { value: -1 },
|
|
47
55
|
_listboxSize: { value: -1 },
|
|
48
56
|
_draftInput: { type: 'string', nullable: false },
|
|
57
|
+
_hasSuggestion: 'boolean',
|
|
58
|
+
_listboxValue: 'string',
|
|
59
|
+
_lastComputedListboxValue: { type: 'string', nullable: false },
|
|
60
|
+
_values: {
|
|
61
|
+
type: 'array',
|
|
62
|
+
/** @type {string[]} */
|
|
63
|
+
value: [],
|
|
64
|
+
},
|
|
65
|
+
_chipSelected: 'boolean',
|
|
49
66
|
})
|
|
50
67
|
.observe({
|
|
51
68
|
_hasListbox({ _listbox }) {
|
|
52
|
-
return _listbox
|
|
69
|
+
return !!_listbox;
|
|
70
|
+
},
|
|
71
|
+
_isSelect({ type }) {
|
|
72
|
+
return type.toLowerCase() === 'select-one' || type.toLocaleLowerCase() === 'select-multiple';
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
.define({
|
|
76
|
+
listbox() {
|
|
77
|
+
return this._listbox;
|
|
53
78
|
},
|
|
54
79
|
})
|
|
55
80
|
.set({
|
|
81
|
+
/** @type {EventListener} */
|
|
56
82
|
_onListboxChangeListener: null,
|
|
83
|
+
/** @type {EventListener} */
|
|
84
|
+
_onListboxClickListener: null,
|
|
85
|
+
/** @type {EventListener} */
|
|
86
|
+
_onPopupFocusoutListener: null,
|
|
87
|
+
_suggestionText: '',
|
|
88
|
+
_suggestionValue: '',
|
|
89
|
+
/** @type {HTMLOptionElement} */
|
|
90
|
+
_suggestionOption: null,
|
|
57
91
|
})
|
|
58
92
|
.define({
|
|
59
93
|
stateTargetElement() { return this.refs.control; },
|
|
@@ -61,35 +95,95 @@ export default CustomElement
|
|
|
61
95
|
.methods({
|
|
62
96
|
onResizeObserved() {
|
|
63
97
|
if (!this._expanded) return;
|
|
64
|
-
|
|
65
|
-
popup.updatePopupPosition(this.refs.shape);
|
|
98
|
+
getSharedPopup().updatePopupPosition(this.refs.shape);
|
|
66
99
|
},
|
|
67
100
|
/**
|
|
101
|
+
* Listbox should close if clicking own selection
|
|
68
102
|
* @param {Event} event
|
|
69
103
|
*/
|
|
70
|
-
|
|
71
|
-
const selectedItem = this._listbox.selectedOptions.item(0);
|
|
72
|
-
this.selectOption(selectedItem);
|
|
104
|
+
onListboxClick(event) {
|
|
73
105
|
this.closeListbox();
|
|
74
106
|
// Revert focus back
|
|
75
107
|
this.refs.control.focus();
|
|
76
108
|
},
|
|
109
|
+
/**
|
|
110
|
+
* @param {Event} event
|
|
111
|
+
*/
|
|
112
|
+
onListboxChange(event) {
|
|
113
|
+
if (this.multiple) {
|
|
114
|
+
const values = [...this._listbox.selectedOptions].map((option) => option.value);
|
|
115
|
+
this._values = values;
|
|
116
|
+
if (this._input.value) {
|
|
117
|
+
this.closeListbox();
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const option = this._listbox.selectedOptions.item(0);
|
|
122
|
+
this.render({
|
|
123
|
+
selectedOption: option,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const { label: suggestionText, value: suggestionValue } = option;
|
|
127
|
+
this._suggestionText = suggestionText;
|
|
128
|
+
this._suggestionValue = suggestionValue;
|
|
129
|
+
this._suggestionOption = option;
|
|
130
|
+
this._hasSuggestion = true;
|
|
131
|
+
this.acceptSuggestion(true);
|
|
132
|
+
this.closeListbox();
|
|
133
|
+
this.refs.control.focus();
|
|
134
|
+
},
|
|
135
|
+
/** @param {FocusEvent} Event */
|
|
136
|
+
onPopupFocusout({ relatedTarget }) {
|
|
137
|
+
if (!this._expanded) return;
|
|
138
|
+
// Ignore if focus lost to pop-up (likely pointerdown).
|
|
139
|
+
if (relatedTarget) {
|
|
140
|
+
if (this === relatedTarget) return;
|
|
141
|
+
if (this.contains(/** @type {any} */ (relatedTarget))) return;
|
|
142
|
+
if (getSharedPopup().contains(/** @type {any} */ (relatedTarget))) return;
|
|
143
|
+
}
|
|
144
|
+
this.closeListbox();
|
|
145
|
+
},
|
|
146
|
+
applyAutocompleteList() {
|
|
147
|
+
const { _listbox, _draftInput } = this;
|
|
148
|
+
if (!_listbox) return;
|
|
149
|
+
|
|
150
|
+
const lowerCase = _draftInput.toLowerCase();
|
|
151
|
+
for (const option of _listbox) {
|
|
152
|
+
option.hidden = !option.label.toLowerCase().startsWith(lowerCase);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
77
155
|
showListbox() {
|
|
78
156
|
// Move contents of list slot into top-layer
|
|
79
157
|
// Should only have one element
|
|
80
158
|
|
|
81
|
-
const
|
|
159
|
+
const _listbox = this._listbox;
|
|
82
160
|
if (!_listbox) return;
|
|
83
161
|
this._expanded = true;
|
|
84
|
-
const {
|
|
85
|
-
control.setAttribute('role', 'combobox');
|
|
162
|
+
const { ariaListbox, shape } = this.refs;
|
|
86
163
|
ariaListbox.setAttribute('aria-hidden', 'false');
|
|
87
164
|
const popup = getSharedPopup();
|
|
88
|
-
|
|
165
|
+
if ('popover' in popup) {
|
|
166
|
+
this.insertAdjacentElement('afterend', popup);
|
|
167
|
+
popup.popover = 'manual';
|
|
168
|
+
popup.showPopover();
|
|
169
|
+
} else {
|
|
170
|
+
document.body.append(popup);
|
|
171
|
+
}
|
|
89
172
|
popup.replaceChildren(_listbox);
|
|
90
|
-
_listbox.selectedIndex = -1;
|
|
91
173
|
popup.showPopup(shape, false);
|
|
174
|
+
popup.addEventListener('focusout', this._onPopupFocusoutListener);
|
|
175
|
+
if (!this._isSelect && !this.multiple) {
|
|
176
|
+
_listbox.value = this._listboxValue;
|
|
177
|
+
}
|
|
178
|
+
const [option] = _listbox.selectedOptions;
|
|
179
|
+
if (option) {
|
|
180
|
+
option.scrollIntoView({
|
|
181
|
+
behavior: 'instant',
|
|
182
|
+
block: 'nearest',
|
|
183
|
+
});
|
|
184
|
+
}
|
|
92
185
|
},
|
|
186
|
+
|
|
93
187
|
closeListbox() {
|
|
94
188
|
this._expanded = false;
|
|
95
189
|
const { _listbox } = this;
|
|
@@ -101,54 +195,271 @@ export default CustomElement
|
|
|
101
195
|
// TODO: Animate
|
|
102
196
|
popup.remove();
|
|
103
197
|
},
|
|
104
|
-
|
|
198
|
+
toggleListbox() {
|
|
199
|
+
if (this._expanded) {
|
|
200
|
+
this.closeListbox();
|
|
201
|
+
} else {
|
|
202
|
+
this.showListbox();
|
|
203
|
+
}
|
|
204
|
+
},
|
|
105
205
|
/**
|
|
106
206
|
* @param {{label:string, value:string}} option
|
|
107
207
|
* @return {void}
|
|
108
208
|
*/
|
|
109
|
-
|
|
209
|
+
suggestOption(option) {
|
|
110
210
|
this.render({
|
|
111
211
|
selectedOption: option,
|
|
112
212
|
});
|
|
113
213
|
|
|
114
|
-
const {
|
|
115
|
-
|
|
214
|
+
const {
|
|
215
|
+
_draftInput: currentInput,
|
|
216
|
+
_input: inputElement,
|
|
217
|
+
_isSelect,
|
|
218
|
+
autocompleteInline,
|
|
219
|
+
_expanded,
|
|
220
|
+
autoSelect,
|
|
221
|
+
} = this;
|
|
222
|
+
const { label: suggestionText, value: suggestionValue } = option;
|
|
116
223
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
224
|
+
this._suggestionText = suggestionText;
|
|
225
|
+
this._suggestionValue = suggestionValue;
|
|
226
|
+
this._suggestionOption = option;
|
|
227
|
+
this._hasSuggestion = true;
|
|
228
|
+
if (autoSelect) {
|
|
229
|
+
this.acceptSuggestion(true);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Autocomplete Inline
|
|
234
|
+
if ((_isSelect && !this.multiple) || autocompleteInline) {
|
|
235
|
+
let valueText = suggestionText;
|
|
236
|
+
let selectionStart = 0;
|
|
237
|
+
if (_expanded) {
|
|
238
|
+
if (!_isSelect && suggestionText.toLowerCase().startsWith(currentInput.toLowerCase())) {
|
|
239
|
+
valueText = currentInput + suggestionText.slice(currentInput.length);
|
|
240
|
+
selectionStart = currentInput.length;
|
|
241
|
+
} else {
|
|
242
|
+
selectionStart = suggestionText.length;
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
selectionStart = 0;
|
|
246
|
+
}
|
|
247
|
+
inputElement.value = valueText; // Displayed value
|
|
248
|
+
if (autocompleteInline) {
|
|
249
|
+
inputElement.setSelectionRange(selectionStart, suggestionText.length);
|
|
250
|
+
}
|
|
251
|
+
if (!_expanded) {
|
|
252
|
+
this.acceptSuggestion(true);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
acceptSuggestion(emitChange = false) {
|
|
257
|
+
if (!this._hasSuggestion) return;
|
|
258
|
+
if (this.readOnly) return;
|
|
259
|
+
const { _suggestionText, _suggestionValue, _input, multiple, _listbox, _values } = this;
|
|
260
|
+
if (multiple) {
|
|
261
|
+
const newArray = [..._values.filter(Boolean), _suggestionValue ?? _suggestionText];
|
|
262
|
+
this._values = [...new Set(newArray)];
|
|
120
263
|
} else {
|
|
121
|
-
|
|
122
|
-
_input.
|
|
264
|
+
this.value = _suggestionValue;
|
|
265
|
+
_input.value = _suggestionText;
|
|
266
|
+
this._draftInput = _suggestionText;
|
|
267
|
+
_listbox.value = _suggestionValue;
|
|
268
|
+
}
|
|
269
|
+
if (emitChange) {
|
|
270
|
+
this.dispatchEvent(new Event('change', { bubbles: true }));
|
|
123
271
|
}
|
|
124
|
-
this._value = value;
|
|
125
272
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
273
|
+
/**
|
|
274
|
+
* @param {Object} options
|
|
275
|
+
* @param {boolean} [options.first] first option
|
|
276
|
+
* @param {boolean} [options.last] first option
|
|
277
|
+
* @param {boolean} [options.next] next fosuable option
|
|
278
|
+
* @param {boolean} [options.previous] previous focusable option
|
|
279
|
+
* @param {string} [options.startsWith] option label starsWith
|
|
280
|
+
* @param {string} [options.value] matches option value
|
|
281
|
+
* @param {string} [options.label] matches option label
|
|
282
|
+
*/
|
|
283
|
+
changeSuggestion({ first, last, next, previous, startsWith, value, label }) {
|
|
129
284
|
const _listbox = this._listbox;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
285
|
+
let suggestion;
|
|
286
|
+
let suggestionIndex;
|
|
287
|
+
let current;
|
|
288
|
+
let currentIndex;
|
|
289
|
+
let backup;
|
|
290
|
+
let backupIndex = -1;
|
|
291
|
+
let optionIndex = -1;
|
|
292
|
+
for (const option of _listbox.options) {
|
|
293
|
+
optionIndex++;
|
|
294
|
+
if (!current && option.focused) {
|
|
295
|
+
current = option;
|
|
296
|
+
currentIndex = optionIndex;
|
|
297
|
+
if (suggestion && (!next && !last)) {
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (option.hidden) continue;
|
|
302
|
+
if (last) {
|
|
303
|
+
suggestion = option;
|
|
304
|
+
suggestionIndex = optionIndex;
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
if (first) {
|
|
308
|
+
if (!suggestion) {
|
|
309
|
+
suggestion = option;
|
|
310
|
+
suggestionIndex = optionIndex;
|
|
311
|
+
}
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
if (startsWith != null) {
|
|
315
|
+
if (!suggestion && option.label.toLowerCase().startsWith(startsWith)) {
|
|
316
|
+
suggestion = option;
|
|
317
|
+
suggestionIndex = optionIndex;
|
|
318
|
+
}
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (value != null) {
|
|
322
|
+
if (!suggestion && option.value === value) {
|
|
323
|
+
suggestion = option;
|
|
324
|
+
suggestionIndex = optionIndex;
|
|
325
|
+
}
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (label != null) {
|
|
329
|
+
if (!suggestion && option.label === label) {
|
|
330
|
+
suggestion = option;
|
|
331
|
+
suggestionIndex = optionIndex;
|
|
332
|
+
}
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
if (currentIndex === optionIndex) continue;
|
|
336
|
+
if (previous) {
|
|
337
|
+
suggestion = option;
|
|
338
|
+
suggestionIndex = optionIndex;
|
|
339
|
+
} else if (next) {
|
|
340
|
+
if (current) {
|
|
341
|
+
suggestion = option;
|
|
342
|
+
suggestionIndex = optionIndex;
|
|
343
|
+
break;
|
|
344
|
+
} else if (!backup) {
|
|
345
|
+
backup = option;
|
|
346
|
+
backupIndex = optionIndex;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (current && current !== suggestion) {
|
|
351
|
+
current.focused = false;
|
|
352
|
+
}
|
|
353
|
+
if (!suggestion) {
|
|
354
|
+
suggestionIndex = backupIndex;
|
|
355
|
+
suggestion = backup;
|
|
356
|
+
this._input.value = this._draftInput;
|
|
357
|
+
}
|
|
358
|
+
if (suggestionIndex === -1) {
|
|
140
359
|
this._focusedPosInSet = -1;
|
|
360
|
+
this._hasSuggestion = false;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this._focusedPosInSet = suggestionIndex + 1;
|
|
364
|
+
suggestion.focused = true;
|
|
365
|
+
suggestion.scrollIntoView({
|
|
366
|
+
behavior: 'instant',
|
|
367
|
+
block: 'nearest',
|
|
368
|
+
});
|
|
369
|
+
this.suggestOption(suggestion);
|
|
370
|
+
},
|
|
371
|
+
resetSuggestion() {
|
|
372
|
+
if (this._isSelect) {
|
|
373
|
+
this.changeSuggestion({ label: this._draftInput });
|
|
374
|
+
} else {
|
|
375
|
+
this.changeSuggestion({ value: this._listboxValue });
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
refreshMultiple() {
|
|
379
|
+
const { _values, multiple } = this;
|
|
380
|
+
if (!multiple) {
|
|
381
|
+
this.refs.chips.replaceChildren();
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
/** @type {InstanceType<import('./InputChip.js').default>} */
|
|
385
|
+
let element = this.refs.chips.firstElementChild;
|
|
386
|
+
|
|
387
|
+
for (let i = 0; i < _values.length; i++) {
|
|
388
|
+
const currentValue = _values[i];
|
|
389
|
+
let foundOption;
|
|
390
|
+
if (this.listbox) {
|
|
391
|
+
for (const option of this.listbox.options) {
|
|
392
|
+
if (option.value === currentValue) {
|
|
393
|
+
foundOption = option;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
element ??= this.refs.chips.appendChild(document.createElement('mdw-input-chip'));
|
|
400
|
+
element.closeButton = true;
|
|
401
|
+
element.textContent = foundOption?.label || currentValue;
|
|
402
|
+
element.textContent = foundOption?.label || currentValue;
|
|
403
|
+
element.disabled = this.disabled;
|
|
404
|
+
element.readOnly = this.readOnly;
|
|
405
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener
|
|
406
|
+
element.onclose ??= this.onChipClose.bind(this);
|
|
407
|
+
element = element.nextElementSibling;
|
|
408
|
+
}
|
|
409
|
+
while (element) {
|
|
410
|
+
const prev = element;
|
|
411
|
+
element = element.nextElementSibling;
|
|
412
|
+
prev.remove();
|
|
413
|
+
}
|
|
414
|
+
this._chipSelected = false;
|
|
415
|
+
this._input.value = '';
|
|
416
|
+
this._draftInput = '';
|
|
417
|
+
this._listboxValue = '';
|
|
418
|
+
if (this.listbox) {
|
|
419
|
+
for (const option of this.listbox.options) {
|
|
420
|
+
option.selected = _values.includes(option.value);
|
|
421
|
+
}
|
|
141
422
|
}
|
|
142
423
|
},
|
|
424
|
+
populateInputFromListbox() {
|
|
425
|
+
if (this.multiple) {
|
|
426
|
+
this.refreshMultiple();
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (!this._isSelect) return;
|
|
430
|
+
if (!this._listbox) return;
|
|
431
|
+
|
|
432
|
+
this._listbox.value = this._value;
|
|
433
|
+
const [option] = this._listbox.selectedOptions;
|
|
434
|
+
if (option) {
|
|
435
|
+
this._input.value = option.label;
|
|
436
|
+
this._draftInput = option.label;
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
onChipClose({ currentTarget }) {
|
|
440
|
+
let prev = currentTarget;
|
|
441
|
+
let elementIndex = 0;
|
|
442
|
+
while ((prev = prev.previousSibling)) {
|
|
443
|
+
elementIndex++;
|
|
444
|
+
}
|
|
445
|
+
currentTarget.remove();
|
|
446
|
+
this._values.splice(elementIndex, 1);
|
|
447
|
+
this._values = [...this._values];
|
|
448
|
+
},
|
|
143
449
|
})
|
|
144
450
|
.childEvents({
|
|
145
451
|
control: {
|
|
452
|
+
click() {
|
|
453
|
+
if (!this._isSelect) return;
|
|
454
|
+
if (this.readOnly) return;
|
|
455
|
+
this.toggleListbox();
|
|
456
|
+
},
|
|
146
457
|
input(event) {
|
|
147
|
-
if (!this.
|
|
458
|
+
if (!this._hasListbox) return;
|
|
148
459
|
// Intercept event and dispatch a new one.
|
|
149
460
|
// This allow authors to modify listbox (filter) and value (custom pattern)
|
|
150
461
|
event.stopPropagation();
|
|
151
|
-
this.dispatchEvent(new InputEvent('input', {
|
|
462
|
+
const performDefault = this.dispatchEvent(new InputEvent('input', {
|
|
152
463
|
composed: true,
|
|
153
464
|
data: event.data,
|
|
154
465
|
bubbles: true,
|
|
@@ -159,46 +470,124 @@ export default CustomElement
|
|
|
159
470
|
targetRanges: event.getTargetRanges(),
|
|
160
471
|
isComposing: event.isComposing,
|
|
161
472
|
}));
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
473
|
+
if (!performDefault) {
|
|
474
|
+
event.preventDefault();
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const value = /** @type {HTMLInputElement} */ (event.currentTarget).value;
|
|
478
|
+
this._draftInput = value;
|
|
479
|
+
if (this.autocompleteList != null && this.autocompleteList !== 'custom') {
|
|
480
|
+
this.applyAutocompleteList();
|
|
481
|
+
}
|
|
482
|
+
this.resetSuggestion();
|
|
483
|
+
if (value && !this._expanded && this._listbox.length) {
|
|
165
484
|
this.showListbox();
|
|
166
485
|
}
|
|
486
|
+
// Only inline suggest if appending characters
|
|
487
|
+
if (event.data != null && this.autosuggestInline) {
|
|
488
|
+
this.changeSuggestion({ startsWith: this._draftInput.toLocaleLowerCase() });
|
|
489
|
+
}
|
|
167
490
|
},
|
|
168
491
|
keydown(event) {
|
|
492
|
+
if (!this._listbox) return;
|
|
493
|
+
// Calls to return will not prevent default.
|
|
169
494
|
switch (event.key) {
|
|
495
|
+
case 'Home':
|
|
496
|
+
if (!this._isSelect) return;
|
|
497
|
+
if (this.readOnly) return;
|
|
498
|
+
this.changeSuggestion({ first: true });
|
|
499
|
+
break;
|
|
500
|
+
case 'End':
|
|
501
|
+
this._chipSelected = false;
|
|
502
|
+
if (!this._isSelect) return;
|
|
503
|
+
if (this.readOnly) return;
|
|
504
|
+
this.changeSuggestion({ last: true });
|
|
505
|
+
break;
|
|
506
|
+
case 'ArrowDown':
|
|
507
|
+
case 'Down':
|
|
508
|
+
if (this.disabled) return;
|
|
509
|
+
if (this.readOnly) return;
|
|
510
|
+
this._chipSelected = false;
|
|
511
|
+
if (this.readOnly) return;
|
|
512
|
+
if (event.altKey) {
|
|
513
|
+
this.toggleListbox();
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
if (!this._expanded && !this.autocompleteInline && !this._isSelect) return;
|
|
517
|
+
this.changeSuggestion({ next: true });
|
|
518
|
+
break;
|
|
170
519
|
case 'ArrowUp':
|
|
171
520
|
case 'Up':
|
|
521
|
+
if (this.disabled) return;
|
|
522
|
+
if (this.readOnly) return;
|
|
523
|
+
if (event.altKey) {
|
|
524
|
+
this.toggleListbox();
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
this._chipSelected = false;
|
|
528
|
+
if (!this._expanded && !this.autocompleteInline && !this._isSelect) return;
|
|
529
|
+
this.changeSuggestion({ previous: true });
|
|
530
|
+
break;
|
|
531
|
+
case 'Escape':
|
|
172
532
|
if (!this._expanded) return;
|
|
173
|
-
|
|
174
|
-
|
|
533
|
+
event.stopImmediatePropagation();
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
if (this.acceptOnEscape) {
|
|
536
|
+
this.acceptSuggestion(true);
|
|
175
537
|
} else {
|
|
176
|
-
this.
|
|
538
|
+
this.resetSuggestion();
|
|
177
539
|
}
|
|
540
|
+
this.closeListbox();
|
|
178
541
|
break;
|
|
179
|
-
case '
|
|
180
|
-
|
|
542
|
+
case 'Space':
|
|
543
|
+
if (this.disabled) return;
|
|
544
|
+
if (this.readOnly) return;
|
|
545
|
+
if (!this._isSelect) return;
|
|
546
|
+
if (!this._listbox) return;
|
|
181
547
|
if (this._expanded) {
|
|
182
|
-
if (this.
|
|
183
|
-
this.
|
|
184
|
-
|
|
185
|
-
this._focusedIndex++;
|
|
548
|
+
if (this.multiple && this._suggestionOption) {
|
|
549
|
+
this._suggestionOption.selected = !this._suggestionOption.selected;
|
|
550
|
+
this.closeListbox();
|
|
186
551
|
}
|
|
187
552
|
} else {
|
|
188
|
-
if (!this._listbox) return;
|
|
189
553
|
this.showListbox();
|
|
190
|
-
this._focusedIndex = 0;
|
|
191
554
|
}
|
|
192
555
|
break;
|
|
193
|
-
case '
|
|
194
|
-
if (
|
|
195
|
-
this.
|
|
196
|
-
|
|
556
|
+
case 'Backspace':
|
|
557
|
+
if (this.disabled) return;
|
|
558
|
+
if (this.readOnly) return;
|
|
559
|
+
if (!this.multiple) return;
|
|
560
|
+
if (this._isSelect) return;
|
|
561
|
+
if (!this._input.value) {
|
|
562
|
+
if (this._chipSelected) {
|
|
563
|
+
this._values.pop();
|
|
564
|
+
this._values = [...this._values];
|
|
565
|
+
} else if (this._values.length) {
|
|
566
|
+
this._chipSelected = true;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return;
|
|
197
570
|
case 'Tab':
|
|
571
|
+
if (!this._expanded && this.multiple) return;
|
|
198
572
|
this.closeListbox();
|
|
573
|
+
this.acceptSuggestion(true);
|
|
199
574
|
event.stopPropagation();
|
|
200
|
-
return;
|
|
575
|
+
return;
|
|
576
|
+
case 'Enter':
|
|
577
|
+
this._chipSelected = false;
|
|
578
|
+
if (!this._expanded) return;
|
|
579
|
+
event.stopImmediatePropagation();
|
|
580
|
+
event.preventDefault();
|
|
581
|
+
this.acceptSuggestion(true);
|
|
582
|
+
this.closeListbox();
|
|
583
|
+
break;
|
|
584
|
+
case ' ':
|
|
585
|
+
return;
|
|
201
586
|
default:
|
|
587
|
+
if (this._isSelect && event.key.length === 1) {
|
|
588
|
+
this.changeSuggestion({ startsWith: event.key.toLocaleLowerCase() });
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
202
591
|
return;
|
|
203
592
|
}
|
|
204
593
|
event.stopPropagation(); // Avoid kbd within kbd (sub menus)
|
|
@@ -212,9 +601,9 @@ export default CustomElement
|
|
|
212
601
|
*/
|
|
213
602
|
slotchange({ currentTarget }) {
|
|
214
603
|
if (this._expanded) return;
|
|
215
|
-
/** @type {Listbox[]} */
|
|
604
|
+
/** @type {InstanceType<Listbox>[]} */
|
|
216
605
|
const [listbox] = currentTarget.assignedElements();
|
|
217
|
-
const
|
|
606
|
+
const _listbox = this._listbox;
|
|
218
607
|
if (_listbox === listbox) {
|
|
219
608
|
// Internal already matches
|
|
220
609
|
return;
|
|
@@ -222,58 +611,203 @@ export default CustomElement
|
|
|
222
611
|
if (_listbox) {
|
|
223
612
|
// Unbind and release
|
|
224
613
|
_listbox.removeEventListener('change', this._onListboxChangeListener);
|
|
225
|
-
this.
|
|
614
|
+
_listbox.removeEventListener('click', this._onListboxClickListener);
|
|
615
|
+
_listbox._handleFormReset = true;
|
|
226
616
|
}
|
|
617
|
+
this._listbox = listbox;
|
|
227
618
|
if (listbox) {
|
|
228
619
|
// Bind and store
|
|
229
|
-
|
|
620
|
+
if (!this.multiple) {
|
|
621
|
+
listbox.required = true; // Don't allow unclick
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
_listbox._handleFormReset = false;
|
|
230
625
|
listbox.addEventListener('change', this._onListboxChangeListener);
|
|
626
|
+
listbox.addEventListener('click', this._onListboxChangeListener);
|
|
627
|
+
this.populateInputFromListbox();
|
|
231
628
|
}
|
|
232
|
-
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
trailingIcon: {
|
|
632
|
+
'~click'() {
|
|
633
|
+
if (!this._listbox) return;
|
|
634
|
+
this.toggleListbox();
|
|
635
|
+
this.refs.control.focus();
|
|
233
636
|
},
|
|
234
637
|
},
|
|
235
638
|
})
|
|
236
639
|
.events({
|
|
237
640
|
blur({ relatedTarget }) {
|
|
641
|
+
this._chipSelected = false;
|
|
238
642
|
if (!this._expanded) return;
|
|
239
643
|
// Ignore if focus lost to pop-up (likely pointerdown).
|
|
240
|
-
|
|
644
|
+
const popup = getSharedPopup();
|
|
645
|
+
if (popup === relatedTarget) return;
|
|
646
|
+
if (relatedTarget && popup.contains(/** @type {Node} */ (relatedTarget))) return;
|
|
647
|
+
if (popup.matches(':focus-within,:focus')) return;
|
|
241
648
|
this.closeListbox();
|
|
242
649
|
},
|
|
243
650
|
})
|
|
244
651
|
.expressions({
|
|
652
|
+
showTrailingIcon({ trailingIcon, _listbox, _expanded, readOnly }) {
|
|
653
|
+
if (trailingIcon != null) {
|
|
654
|
+
return trailingIcon;
|
|
655
|
+
}
|
|
656
|
+
if (_listbox && !readOnly) {
|
|
657
|
+
return _expanded ? 'arrow_drop_up' : 'arrow_drop_down';
|
|
658
|
+
}
|
|
659
|
+
return null;
|
|
660
|
+
},
|
|
661
|
+
computedTrailingIcon({ trailingIcon, _listbox, _expanded }) {
|
|
662
|
+
if (trailingIcon != null) {
|
|
663
|
+
return trailingIcon;
|
|
664
|
+
}
|
|
665
|
+
if (_listbox) {
|
|
666
|
+
return _expanded ? 'arrow_drop_up' : 'arrow_drop_down';
|
|
667
|
+
}
|
|
668
|
+
return null;
|
|
669
|
+
},
|
|
670
|
+
controlTypeAttrValue({ _isSelect, type }) {
|
|
671
|
+
if (_isSelect) return 'text';
|
|
672
|
+
return type;
|
|
673
|
+
},
|
|
674
|
+
controlReadonlyAttrValue({ _isSelect, type, readOnly }) {
|
|
675
|
+
if (_isSelect) return true;
|
|
676
|
+
return readOnly;
|
|
677
|
+
},
|
|
678
|
+
controlIsSelect({ _isSelect, type }) {
|
|
679
|
+
return _isSelect;
|
|
680
|
+
},
|
|
245
681
|
ariaExpandedAttrValue({ _hasListbox, _expanded }) {
|
|
246
|
-
|
|
682
|
+
if (!_hasListbox) return null;
|
|
683
|
+
return `${_expanded}`;
|
|
247
684
|
},
|
|
248
685
|
ariaControlsAttrValue({ _hasListbox }) {
|
|
249
|
-
|
|
686
|
+
if (!_hasListbox) return null;
|
|
687
|
+
return 'aria-listbox';
|
|
250
688
|
},
|
|
251
|
-
ariaAutocompleteAttrValue({ _hasListbox,
|
|
252
|
-
return
|
|
253
|
-
|
|
254
|
-
|
|
689
|
+
ariaAutocompleteAttrValue({ _hasListbox, autocompleteList, _isSelect }) {
|
|
690
|
+
if (!_hasListbox) return null;
|
|
691
|
+
if (_isSelect) return null;
|
|
692
|
+
if (autocompleteList != null) {
|
|
693
|
+
return 'both';
|
|
694
|
+
}
|
|
695
|
+
return 'inline';
|
|
255
696
|
},
|
|
256
697
|
ariaActiveDescendantAttrValue({ _hasListbox, _expanded, _focusedValue }) {
|
|
257
|
-
return
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
698
|
+
if (!_hasListbox) return null;
|
|
699
|
+
if (_expanded && _focusedValue) return 'aria-active';
|
|
700
|
+
return '';
|
|
701
|
+
},
|
|
702
|
+
controlRoleAttrValue({ _hasListbox }) {
|
|
703
|
+
if (_hasListbox) return 'combobox';
|
|
704
|
+
return null;
|
|
705
|
+
},
|
|
706
|
+
populatedState({ value, _badInput, _draftInput, type }) {
|
|
707
|
+
return !!value || _badInput || !!_draftInput || type === 'datetime-local';
|
|
708
|
+
},
|
|
709
|
+
})
|
|
710
|
+
.recompose(({ refs: { control, trailingIcon, shape, labelText } }) => {
|
|
711
|
+
// Can't cross DOM boundaries
|
|
712
|
+
control.setAttribute('aria-activedescendant', '{ariaActiveDescendantAttrValue}');
|
|
713
|
+
control.setAttribute('aria-autocomplete', '{ariaAutocompleteAttrValue}');
|
|
714
|
+
control.setAttribute('aria-controls', '{ariaControlsAttrValue}');
|
|
715
|
+
control.setAttribute('aria-expanded', '{ariaExpandedAttrValue}');
|
|
716
|
+
control.setAttribute('type', '{controlTypeAttrValue}');
|
|
717
|
+
control.setAttribute('role', '{controlRoleAttrValue}');
|
|
718
|
+
control.setAttribute('readonly', '{controlReadonlyAttrValue}');
|
|
719
|
+
control.setAttribute('autocomplete', 'off');
|
|
720
|
+
control.setAttribute('is-select', '{controlIsSelect}');
|
|
721
|
+
trailingIcon.setAttribute('mdw-if', '{showTrailingIcon}');
|
|
722
|
+
trailingIcon.setAttribute('icon', '{computedTrailingIcon}');
|
|
723
|
+
shape.setAttribute('trailing-icon', '{computedTrailingIcon}');
|
|
724
|
+
labelText.setAttribute('trailing-icon', '{computedTrailingIcon}');
|
|
725
|
+
})
|
|
726
|
+
.overrides({
|
|
727
|
+
_onSetValue(value) {
|
|
728
|
+
if (this.multiple) {
|
|
729
|
+
this._values = value.split(',').filter(Boolean);
|
|
730
|
+
} else if (this._isSelect) {
|
|
731
|
+
this._value = value;
|
|
732
|
+
} else {
|
|
733
|
+
// Apply user value to input and read back result to apply control to parse
|
|
734
|
+
this._input.value = value;
|
|
735
|
+
this._value = this._input.value;
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
_onControlValue(value) {
|
|
739
|
+
// Only accept values from accepted suggestions
|
|
740
|
+
if (this.multiple) {
|
|
741
|
+
if (value) {
|
|
742
|
+
this._chipSelected = false;
|
|
743
|
+
}
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this._value = value;
|
|
261
747
|
},
|
|
262
748
|
})
|
|
263
749
|
.on({
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
750
|
+
_valueChanged(previous, current) {
|
|
751
|
+
if (this.multiple) return; // Handled by _values
|
|
752
|
+
if (this._isSelect) {
|
|
753
|
+
this.populateInputFromListbox();
|
|
754
|
+
} else {
|
|
755
|
+
this._listboxValue = current;
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
_valuesChanged(previous, current) {
|
|
759
|
+
if (this.multiple && current) {
|
|
760
|
+
this._value = current.join(',');
|
|
761
|
+
this.refreshMultiple();
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
_chipSelectedChanged(previous, current) {
|
|
765
|
+
if (!this.multiple) return;
|
|
766
|
+
const element = this.refs.chips.lastElementChild;
|
|
767
|
+
if (element) {
|
|
768
|
+
element.selected = current;
|
|
769
|
+
}
|
|
770
|
+
},
|
|
771
|
+
_listboxValueChanged(previous, current) {
|
|
772
|
+
if (!this._hasListbox) return;
|
|
773
|
+
this._listbox.value = current;
|
|
774
|
+
this._draftInput = current;
|
|
775
|
+
this.changeSuggestion({ value: current });
|
|
776
|
+
},
|
|
777
|
+
_expandedChanged(previous, current) {
|
|
778
|
+
this._useFormImplicitSubmission = !current;
|
|
779
|
+
},
|
|
780
|
+
constructed() {
|
|
781
|
+
this._onListboxChangeListener = this.onListboxChange.bind(this);
|
|
782
|
+
this._onListboxClickListener = this.onListboxClick.bind(this);
|
|
783
|
+
this._onPopupFocusoutListener = this.onPopupFocusout.bind(this);
|
|
784
|
+
document.addEventListener('DOMContentLoaded', () => this.populateInputFromListbox(), { once: true });
|
|
785
|
+
},
|
|
786
|
+
multipleChanged(previous, current) {
|
|
787
|
+
if (this.listbox) {
|
|
788
|
+
this.listbox.multiple = current;
|
|
789
|
+
}
|
|
790
|
+
if (current) {
|
|
791
|
+
this._onSetValue(this._input.value);
|
|
792
|
+
}
|
|
793
|
+
},
|
|
794
|
+
disabledStateChanged() {
|
|
795
|
+
this.refreshMultiple();
|
|
796
|
+
this._chipSelected = false;
|
|
797
|
+
this.closeListbox();
|
|
798
|
+
},
|
|
799
|
+
readOnlyChanged() {
|
|
800
|
+
this.refreshMultiple();
|
|
801
|
+
this._chipSelected = false;
|
|
802
|
+
this.closeListbox();
|
|
271
803
|
},
|
|
272
804
|
})
|
|
273
805
|
.html`
|
|
806
|
+
<div id=chips mdw-if={multiple}></div>
|
|
274
807
|
<slot id=slot></slot>
|
|
275
|
-
<div id=aria-listbox role=listbox>
|
|
276
|
-
<div id=aria-active role=option aria-
|
|
808
|
+
<div id=aria-listbox role=listbox mdw-if={_hasListbox}>
|
|
809
|
+
<div id=aria-active role=option aria-hidden=false aria-label={selectedOption.label}
|
|
810
|
+
aria-setsize="{_listbox.length}" aria-posinset={_focusedPosInSet}></div>
|
|
277
811
|
</div>
|
|
278
812
|
`
|
|
279
813
|
.css`
|
|
@@ -284,5 +818,57 @@ export default CustomElement
|
|
|
284
818
|
#aria-listbox {
|
|
285
819
|
display: none;
|
|
286
820
|
}
|
|
821
|
+
|
|
822
|
+
#trailing-icon {
|
|
823
|
+
align-self: center;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
#control:where([type="button"], [is-select]) {
|
|
827
|
+
cursor: pointer;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
#inline[multiple] {
|
|
831
|
+
gap: 8px;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
mdw-input-chip {
|
|
835
|
+
align-self: baseline;
|
|
836
|
+
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
#control[multiple] {
|
|
840
|
+
align-self: baseline;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
#chips {
|
|
844
|
+
display: contents;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
#inline {
|
|
848
|
+
flex-wrap: wrap;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
#inline:where([filled],[outlined]) {
|
|
852
|
+
padding-inline: 16px;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
#control {
|
|
856
|
+
flex: 1 1 8ch;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
#control[is-select][multiple] {
|
|
860
|
+
flex: 1 1 0px;
|
|
861
|
+
}
|
|
287
862
|
`
|
|
863
|
+
.recompose(({ refs: { inline, chips } }) => {
|
|
864
|
+
inline.prepend(chips);
|
|
865
|
+
inline.setAttribute('multiple', '{multiple}');
|
|
866
|
+
})
|
|
867
|
+
.extend((Base) => class Input extends Base {
|
|
868
|
+
/** @type {InstanceType<ReturnType<RippleMixin>>['addRipple']} */
|
|
869
|
+
addRipple(...args) {
|
|
870
|
+
if (!this.active) return null;
|
|
871
|
+
return super.addRipple(...args);
|
|
872
|
+
}
|
|
873
|
+
})
|
|
288
874
|
.autoRegister('mdw-input');
|