@wordpress/components 35.0.1 → 36.0.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/CHANGELOG.md +38 -0
- package/CONTRIBUTING.md +33 -26
- package/build/alignment-matrix-control/cell.cjs +1 -1
- package/build/alignment-matrix-control/cell.cjs.map +2 -2
- package/build/alignment-matrix-control/index.cjs +1 -1
- package/build/alignment-matrix-control/index.cjs.map +2 -2
- package/build/angle-picker-control/angle-circle.cjs +1 -1
- package/build/angle-picker-control/angle-circle.cjs.map +2 -2
- package/build/angle-picker-control/index.cjs +2 -2
- package/build/autocomplete/get-autocomplete-match.cjs.map +1 -1
- package/build/autocomplete/index.cjs.map +1 -1
- package/build/base-control/styles/base-control-styles.cjs +6 -6
- package/build/base-control/styles/base-control-styles.cjs.map +2 -2
- package/build/border-control/styles.cjs +17 -14
- package/build/border-control/styles.cjs.map +2 -2
- package/build/box-control/{input-control.cjs → box-input-control.cjs} +9 -9
- package/build/box-control/box-input-control.cjs.map +7 -0
- package/build/box-control/index.cjs +9 -25
- package/build/box-control/index.cjs.map +3 -3
- package/build/button/index.cjs +3 -7
- package/build/button/index.cjs.map +2 -2
- package/build/card/card-divider/hook.cjs.map +2 -2
- package/build/color-palette/index.cjs.map +1 -1
- package/build/color-picker/component.cjs.map +1 -1
- package/build/date-time/utils.cjs.map +1 -1
- package/build/disabled/index.cjs.map +2 -2
- package/build/divider/component.cjs +108 -3
- package/build/divider/component.cjs.map +4 -4
- package/build/draggable/index.cjs.map +1 -1
- package/build/external-link/index.cjs +1 -1
- package/build/external-link/index.cjs.map +1 -1
- package/build/higher-order/with-fallback-styles/index.cjs +18 -44
- package/build/higher-order/with-fallback-styles/index.cjs.map +2 -2
- package/build/menu/popover.cjs.map +1 -1
- package/build/menu/styles.cjs +17 -17
- package/build/menu/styles.cjs.map +2 -2
- package/build/modal/index.cjs.map +1 -1
- package/build/modal/use-modal-exit-animation.cjs +37 -52
- package/build/modal/use-modal-exit-animation.cjs.map +2 -2
- package/build/palette-edit/index.cjs +1 -1
- package/build/progress-bar/index.cjs +1 -1
- package/build/progress-bar/index.cjs.map +2 -2
- package/build/query-controls/index.cjs +2 -2
- package/build/query-controls/index.cjs.map +2 -2
- package/build/range-control/index.cjs.map +1 -1
- package/build/sandbox/index.cjs +7 -1
- package/build/sandbox/index.cjs.map +2 -2
- package/build/snackbar/index.cjs +1 -1
- package/build/spinner/styles.cjs +4 -4
- package/build/spinner/styles.cjs.map +2 -2
- package/build/tabs/index.cjs +0 -18
- package/build/tabs/index.cjs.map +2 -2
- package/build/tabs/tablist.cjs +5 -15
- package/build/tabs/tablist.cjs.map +2 -2
- package/build/text-control/index.cjs +3 -12
- package/build/text-control/index.cjs.map +3 -3
- package/build/tools-panel/styles.cjs +13 -13
- package/build/tools-panel/styles.cjs.map +2 -2
- package/build/tools-panel/tools-panel/hook.cjs.map +1 -1
- package/build/tree-select/index.cjs +1 -1
- package/build/tree-select/index.cjs.map +1 -1
- package/build/truncate/utils.cjs +1 -1
- package/build/truncate/utils.cjs.map +1 -1
- package/build/utils/colors-values.cjs +12 -12
- package/build/utils/colors-values.cjs.map +2 -2
- package/build/utils/config-values.cjs +2 -2
- package/build/utils/config-values.cjs.map +2 -2
- package/build/utils/dropdown-motion.cjs.map +2 -2
- package/build/utils/strings.cjs.map +1 -1
- package/build/validated-form-controls/components/text-control.cjs +0 -1
- package/build/validated-form-controls/components/text-control.cjs.map +2 -2
- package/build-module/alignment-matrix-control/cell.mjs +1 -1
- package/build-module/alignment-matrix-control/cell.mjs.map +2 -2
- package/build-module/alignment-matrix-control/index.mjs +1 -1
- package/build-module/alignment-matrix-control/index.mjs.map +2 -2
- package/build-module/angle-picker-control/angle-circle.mjs +1 -1
- package/build-module/angle-picker-control/angle-circle.mjs.map +2 -2
- package/build-module/angle-picker-control/index.mjs +2 -2
- package/build-module/autocomplete/get-autocomplete-match.mjs.map +1 -1
- package/build-module/autocomplete/index.mjs.map +1 -1
- package/build-module/base-control/styles/base-control-styles.mjs +6 -6
- package/build-module/base-control/styles/base-control-styles.mjs.map +2 -2
- package/build-module/border-control/styles.mjs +17 -14
- package/build-module/border-control/styles.mjs.map +2 -2
- package/build-module/box-control/{input-control.mjs → box-input-control.mjs} +6 -6
- package/build-module/box-control/box-input-control.mjs.map +7 -0
- package/build-module/box-control/index.mjs +9 -25
- package/build-module/box-control/index.mjs.map +2 -2
- package/build-module/button/index.mjs +2 -5
- package/build-module/button/index.mjs.map +2 -2
- package/build-module/card/card-divider/hook.mjs.map +2 -2
- package/build-module/color-palette/index.mjs.map +1 -1
- package/build-module/color-picker/component.mjs.map +1 -1
- package/build-module/date-time/utils.mjs.map +1 -1
- package/build-module/disabled/index.mjs.map +2 -2
- package/build-module/divider/component.mjs +108 -3
- package/build-module/divider/component.mjs.map +3 -3
- package/build-module/draggable/index.mjs.map +1 -1
- package/build-module/external-link/index.mjs +1 -1
- package/build-module/external-link/index.mjs.map +1 -1
- package/build-module/higher-order/with-fallback-styles/index.mjs +20 -46
- package/build-module/higher-order/with-fallback-styles/index.mjs.map +2 -2
- package/build-module/menu/popover.mjs.map +1 -1
- package/build-module/menu/styles.mjs +17 -17
- package/build-module/menu/styles.mjs.map +2 -2
- package/build-module/modal/index.mjs.map +1 -1
- package/build-module/modal/use-modal-exit-animation.mjs +37 -52
- package/build-module/modal/use-modal-exit-animation.mjs.map +2 -2
- package/build-module/palette-edit/index.mjs +1 -1
- package/build-module/progress-bar/index.mjs +1 -1
- package/build-module/progress-bar/index.mjs.map +2 -2
- package/build-module/query-controls/index.mjs +2 -2
- package/build-module/query-controls/index.mjs.map +2 -2
- package/build-module/range-control/index.mjs.map +1 -1
- package/build-module/sandbox/index.mjs +3 -1
- package/build-module/sandbox/index.mjs.map +2 -2
- package/build-module/snackbar/index.mjs +1 -1
- package/build-module/spinner/styles.mjs +4 -4
- package/build-module/spinner/styles.mjs.map +2 -2
- package/build-module/tabs/index.mjs +1 -19
- package/build-module/tabs/index.mjs.map +2 -2
- package/build-module/tabs/tablist.mjs +5 -15
- package/build-module/tabs/tablist.mjs.map +2 -2
- package/build-module/text-control/index.mjs +3 -12
- package/build-module/text-control/index.mjs.map +2 -2
- package/build-module/tools-panel/styles.mjs +13 -13
- package/build-module/tools-panel/styles.mjs.map +2 -2
- package/build-module/tools-panel/tools-panel/hook.mjs.map +1 -1
- package/build-module/tree-select/index.mjs +1 -1
- package/build-module/tree-select/index.mjs.map +1 -1
- package/build-module/truncate/utils.mjs +1 -1
- package/build-module/truncate/utils.mjs.map +1 -1
- package/build-module/utils/colors-values.mjs +12 -12
- package/build-module/utils/colors-values.mjs.map +2 -2
- package/build-module/utils/config-values.mjs +2 -2
- package/build-module/utils/config-values.mjs.map +2 -2
- package/build-module/utils/dropdown-motion.mjs.map +2 -2
- package/build-module/utils/strings.mjs.map +1 -1
- package/build-module/validated-form-controls/components/text-control.mjs +0 -1
- package/build-module/validated-form-controls/components/text-control.mjs.map +2 -2
- package/build-style/style-rtl.css +85 -101
- package/build-style/style.css +85 -101
- package/build-types/base-control/styles/base-control-styles.d.ts.map +1 -1
- package/build-types/border-control/styles.d.ts.map +1 -1
- package/build-types/box-control/box-input-control.d.ts +3 -0
- package/build-types/box-control/box-input-control.d.ts.map +1 -0
- package/build-types/box-control/index.d.ts +2 -6
- package/build-types/box-control/index.d.ts.map +1 -1
- package/build-types/box-control/stories/index.story.d.ts.map +1 -1
- package/build-types/box-control/types.d.ts +7 -6
- package/build-types/box-control/types.d.ts.map +1 -1
- package/build-types/button/index.d.ts +0 -2
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/card/card-divider/hook.d.ts +1 -274
- package/build-types/card/card-divider/hook.d.ts.map +1 -1
- package/build-types/composite/stories/index.story.d.ts.map +1 -1
- package/build-types/confirm-dialog/stories/index.story.d.ts.map +1 -1
- package/build-types/disabled/index.d.ts +0 -1
- package/build-types/disabled/index.d.ts.map +1 -1
- package/build-types/disabled/stories/index.story.d.ts.map +1 -1
- package/build-types/divider/component.d.ts.map +1 -1
- package/build-types/dropdown/stories/index.story.d.ts.map +1 -1
- package/build-types/higher-order/with-fallback-styles/index.d.ts +1 -35
- package/build-types/higher-order/with-fallback-styles/index.d.ts.map +1 -1
- package/build-types/higher-order/with-fallback-styles/test/index.d.ts.map +1 -0
- package/build-types/icon/stories/index.story.d.ts +0 -1
- package/build-types/icon/stories/index.story.d.ts.map +1 -1
- package/build-types/menu/styles.d.ts.map +1 -1
- package/build-types/menu/types.d.ts +2 -2
- package/build-types/placeholder/stories/index.story.d.ts.map +1 -1
- package/build-types/resizable-box/index.d.ts +0 -2
- package/build-types/resizable-box/index.d.ts.map +1 -1
- package/build-types/resizable-box/stories/index.story.d.ts +0 -2
- package/build-types/resizable-box/stories/index.story.d.ts.map +1 -1
- package/build-types/sandbox/index.d.ts +15 -0
- package/build-types/sandbox/index.d.ts.map +1 -1
- package/build-types/spinner/styles.d.ts.map +1 -1
- package/build-types/tabs/index.d.ts.map +1 -1
- package/build-types/tabs/tablist.d.ts.map +1 -1
- package/build-types/text-control/index.d.ts +0 -1
- package/build-types/text-control/index.d.ts.map +1 -1
- package/build-types/text-control/stories/index.story.d.ts.map +1 -1
- package/build-types/text-control/types.d.ts +2 -1
- package/build-types/text-control/types.d.ts.map +1 -1
- package/build-types/tools-panel/styles.d.ts.map +1 -1
- package/build-types/utils/colors-values.d.ts.map +1 -1
- package/build-types/utils/dropdown-motion.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/combobox-control.d.ts +2 -2
- package/build-types/validated-form-controls/components/text-control.d.ts +2 -2
- package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -1
- package/package.json +34 -28
- package/src/angle-picker-control/angle-circle.tsx +3 -3
- package/src/base-control/README.md +2 -2
- package/src/base-control/styles/base-control-styles.ts +1 -0
- package/src/border-control/styles.ts +1 -0
- package/src/box-control/README.md +1 -13
- package/src/box-control/{input-control.tsx → box-input-control.tsx} +4 -4
- package/src/box-control/index.tsx +5 -23
- package/src/box-control/stories/index.story.tsx +1 -3
- package/src/box-control/test/index.tsx +15 -2
- package/src/box-control/types.ts +7 -6
- package/src/button/index.tsx +2 -4
- package/src/button/style.scss +3 -3
- package/src/card/card-divider/hook.ts +5 -1
- package/src/card/test/__snapshots__/index.tsx.snap +7 -9
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +4 -3
- package/src/composite/stories/index.story.tsx +5 -0
- package/src/confirm-dialog/stories/index.story.tsx +1 -0
- package/src/custom-select-control/test/index.tsx +1 -1
- package/src/disabled/README.md +0 -1
- package/src/disabled/index.tsx +0 -1
- package/src/disabled/stories/index.story.tsx +0 -1
- package/src/divider/component.tsx +27 -3
- package/src/divider/style.module.scss +21 -0
- package/src/divider/test/index.tsx +21 -11
- package/src/dropdown/stories/index.story.tsx +5 -0
- package/src/dropdown-menu/style.scss +1 -1
- package/src/external-link/style.scss +4 -4
- package/src/form-toggle/style.scss +1 -1
- package/src/heading/test/__snapshots__/index.tsx.snap +4 -4
- package/src/higher-order/with-constrained-tabbing/README.md +0 -2
- package/src/higher-order/with-fallback-styles/index.tsx +31 -61
- package/src/higher-order/with-fallback-styles/test/index.tsx +47 -0
- package/src/higher-order/with-focus-return/README.md +0 -2
- package/src/icon/stories/index.story.tsx +0 -15
- package/src/menu/README.md +2 -2
- package/src/menu/styles.ts +2 -0
- package/src/menu/test/index.tsx +104 -87
- package/src/menu/types.ts +2 -2
- package/src/menu-item/test/__snapshots__/index.js.snap +2 -0
- package/src/modal/style.scss +1 -1
- package/src/modal/test/index.tsx +0 -24
- package/src/modal/use-modal-exit-animation.ts +2 -2
- package/src/navigable-container/test/navigable-menu.tsx +0 -16
- package/src/navigable-container/test/tababble-container.tsx +0 -16
- package/src/navigator/test/index.tsx +0 -24
- package/src/notice/style.scss +11 -13
- package/src/notice/test/__snapshots__/index.tsx.snap +1 -0
- package/src/panel/README.md +2 -0
- package/src/panel/stories/index.story.tsx +2 -2
- package/src/panel/style.scss +1 -1
- package/src/placeholder/stories/index.story.tsx +0 -1
- package/src/radio-control/style.scss +1 -1
- package/src/resizable-box/index.tsx +1 -2
- package/src/sandbox/index.tsx +18 -1
- package/src/sandbox/test/index.tsx +44 -1
- package/src/spinner/styles.ts +1 -0
- package/src/tab-panel/style.scss +6 -6
- package/src/tab-panel/test/index.tsx +0 -17
- package/src/tabs/index.tsx +1 -26
- package/src/tabs/tablist.tsx +5 -21
- package/src/tabs/test/index.tsx +16 -44
- package/src/text/test/__snapshots__/index.tsx.snap +3 -3
- package/src/text-control/README.md +0 -9
- package/src/text-control/index.tsx +3 -14
- package/src/text-control/stories/index.story.tsx +0 -2
- package/src/text-control/style.scss +7 -11
- package/src/text-control/test/text-control.tsx +1 -5
- package/src/text-control/types.ts +2 -1
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +38 -26
- package/src/toolbar/toolbar-group/style.scss +2 -2
- package/src/tools-panel/styles.ts +1 -1
- package/src/tools-panel/tools-panel/README.md +0 -2
- package/src/tooltip/stories/index.story.tsx +2 -2
- package/src/tree-grid/test/index.tsx +0 -23
- package/src/utils/colors-values.js +36 -16
- package/src/utils/config-values.js +2 -2
- package/src/utils/dropdown-motion.ts +6 -4
- package/src/utils/theme-variables.scss +18 -13
- package/src/validated-form-controls/components/text-control.tsx +2 -10
- package/build/box-control/input-control.cjs.map +0 -7
- package/build/divider/styles.cjs +0 -98
- package/build/divider/styles.cjs.map +0 -7
- package/build-module/box-control/input-control.mjs.map +0 -7
- package/build-module/divider/styles.mjs +0 -63
- package/build-module/divider/styles.mjs.map +0 -7
- package/build-types/box-control/input-control.d.ts +0 -3
- package/build-types/box-control/input-control.d.ts.map +0 -1
- package/build-types/card/context.d.ts +0 -3
- package/build-types/card/context.d.ts.map +0 -1
- package/build-types/date-time/date/index.d.ts +0 -23
- package/build-types/date-time/date/index.d.ts.map +0 -1
- package/build-types/date-time/date/styles.d.ts +0 -45
- package/build-types/date-time/date/styles.d.ts.map +0 -1
- package/build-types/date-time/date/test/index.d.ts.map +0 -1
- package/build-types/date-time/date/test/use-lilius.d.ts +0 -2
- package/build-types/date-time/date/test/use-lilius.d.ts.map +0 -1
- package/build-types/date-time/date/use-lilius/index.d.ts +0 -169
- package/build-types/date-time/date/use-lilius/index.d.ts.map +0 -1
- package/build-types/date-time/time/index.d.ts +0 -27
- package/build-types/date-time/time/index.d.ts.map +0 -1
- package/build-types/date-time/time/styles.d.ts +0 -93
- package/build-types/date-time/time/styles.d.ts.map +0 -1
- package/build-types/date-time/time/test/index.d.ts +0 -2
- package/build-types/date-time/time/test/index.d.ts.map +0 -1
- package/build-types/date-time/time/time-input/index.d.ts +0 -4
- package/build-types/date-time/time/time-input/index.d.ts.map +0 -1
- package/build-types/date-time/time/time-input/test/index.d.ts +0 -2
- package/build-types/date-time/time/time-input/test/index.d.ts.map +0 -1
- package/build-types/date-time/time/timezone.d.ts +0 -7
- package/build-types/date-time/time/timezone.d.ts.map +0 -1
- package/build-types/divider/styles.d.ts +0 -10
- package/build-types/divider/styles.d.ts.map +0 -1
- package/build-types/mobile/image/constants.d.ts +0 -5
- package/build-types/mobile/image/constants.d.ts.map +0 -1
- package/build-types/navigation/back-button/index.d.ts +0 -7
- package/build-types/navigation/back-button/index.d.ts.map +0 -1
- package/build-types/navigation/constants.d.ts +0 -3
- package/build-types/navigation/constants.d.ts.map +0 -1
- package/build-types/navigation/context.d.ts +0 -4
- package/build-types/navigation/context.d.ts.map +0 -1
- package/build-types/navigation/group/context.d.ts +0 -7
- package/build-types/navigation/group/context.d.ts.map +0 -1
- package/build-types/navigation/group/index.d.ts +0 -7
- package/build-types/navigation/group/index.d.ts.map +0 -1
- package/build-types/navigation/index.d.ts +0 -46
- package/build-types/navigation/index.d.ts.map +0 -1
- package/build-types/navigation/item/base-content.d.ts +0 -3
- package/build-types/navigation/item/base-content.d.ts.map +0 -1
- package/build-types/navigation/item/base.d.ts +0 -3
- package/build-types/navigation/item/base.d.ts.map +0 -1
- package/build-types/navigation/item/index.d.ts +0 -7
- package/build-types/navigation/item/index.d.ts.map +0 -1
- package/build-types/navigation/item/use-navigation-tree-item.d.ts +0 -3
- package/build-types/navigation/item/use-navigation-tree-item.d.ts.map +0 -1
- package/build-types/navigation/menu/context.d.ts +0 -7
- package/build-types/navigation/menu/context.d.ts.map +0 -1
- package/build-types/navigation/menu/index.d.ts +0 -7
- package/build-types/navigation/menu/index.d.ts.map +0 -1
- package/build-types/navigation/menu/menu-title-search.d.ts +0 -3
- package/build-types/navigation/menu/menu-title-search.d.ts.map +0 -1
- package/build-types/navigation/menu/menu-title.d.ts +0 -3
- package/build-types/navigation/menu/menu-title.d.ts.map +0 -1
- package/build-types/navigation/menu/search-no-results-found.d.ts +0 -3
- package/build-types/navigation/menu/search-no-results-found.d.ts.map +0 -1
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts +0 -3
- package/build-types/navigation/menu/use-navigation-tree-menu.d.ts.map +0 -1
- package/build-types/navigation/stories/index.story.d.ts +0 -23
- package/build-types/navigation/stories/index.story.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/controlled-state.d.ts +0 -7
- package/build-types/navigation/stories/utils/controlled-state.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/default.d.ts +0 -10
- package/build-types/navigation/stories/utils/default.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/group.d.ts +0 -10
- package/build-types/navigation/stories/utils/group.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts +0 -10
- package/build-types/navigation/stories/utils/hide-if-empty.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/more-examples.d.ts +0 -10
- package/build-types/navigation/stories/utils/more-examples.d.ts.map +0 -1
- package/build-types/navigation/stories/utils/search.d.ts +0 -10
- package/build-types/navigation/stories/utils/search.d.ts.map +0 -1
- package/build-types/navigation/styles/navigation-styles.d.ts +0 -55
- package/build-types/navigation/styles/navigation-styles.d.ts.map +0 -1
- package/build-types/navigation/test/index.d.ts +0 -2
- package/build-types/navigation/test/index.d.ts.map +0 -1
- package/build-types/navigation/types.d.ts +0 -266
- package/build-types/navigation/types.d.ts.map +0 -1
- package/build-types/navigation/use-create-navigation-tree.d.ts +0 -15
- package/build-types/navigation/use-create-navigation-tree.d.ts.map +0 -1
- package/build-types/navigation/use-navigation-tree-nodes.d.ts +0 -10
- package/build-types/navigation/use-navigation-tree-nodes.d.ts.map +0 -1
- package/build-types/navigation/utils.d.ts +0 -3
- package/build-types/navigation/utils.d.ts.map +0 -1
- package/build-types/visually-hidden/test/index.d.ts +0 -2
- package/build-types/visually-hidden/test/index.d.ts.map +0 -1
- package/src/divider/styles.ts +0 -81
- package/src/divider/test/__snapshots__/index.tsx.snap +0 -71
- /package/build-types/{date-time/date → higher-order/with-fallback-styles}/test/index.d.ts +0 -0
package/src/menu/test/index.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
import
|
|
4
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -14,10 +14,6 @@ import { useState } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
import { Menu } from '..';
|
|
16
16
|
|
|
17
|
-
const delay = ( delayInMs: number ) => {
|
|
18
|
-
return new Promise( ( resolve ) => setTimeout( resolve, delayInMs ) );
|
|
19
|
-
};
|
|
20
|
-
|
|
21
17
|
const waitForFocusedMenu = () =>
|
|
22
18
|
waitFor( () => expect( screen.getByRole( 'menu' ) ).toHaveFocus() );
|
|
23
19
|
|
|
@@ -26,10 +22,20 @@ const waitForFocusedMenuItem = ( name: string ) =>
|
|
|
26
22
|
expect( screen.getByRole( 'menuitem', { name } ) ).toHaveFocus()
|
|
27
23
|
);
|
|
28
24
|
|
|
25
|
+
const resetTypeahead = () => {
|
|
26
|
+
act( () => jest.advanceTimersByTime( 500 ) );
|
|
27
|
+
};
|
|
28
|
+
|
|
29
29
|
// Open dropdown => open menu
|
|
30
30
|
// Submenu trigger item => open submenu
|
|
31
31
|
|
|
32
32
|
describe( 'Menu', () => {
|
|
33
|
+
let user: ReturnType< typeof userEvent.setup >;
|
|
34
|
+
|
|
35
|
+
beforeEach( () => {
|
|
36
|
+
user = userEvent.setup();
|
|
37
|
+
} );
|
|
38
|
+
|
|
33
39
|
// See https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/
|
|
34
40
|
it( 'should follow the WAI-ARIA spec', async () => {
|
|
35
41
|
render(
|
|
@@ -58,7 +64,7 @@ describe( 'Menu', () => {
|
|
|
58
64
|
expect( toggleButton ).toHaveAttribute( 'aria-haspopup', 'menu' );
|
|
59
65
|
expect( toggleButton ).toHaveAttribute( 'aria-expanded', 'false' );
|
|
60
66
|
|
|
61
|
-
await click( toggleButton );
|
|
67
|
+
await user.click( toggleButton );
|
|
62
68
|
|
|
63
69
|
expect( toggleButton ).toHaveAttribute( 'aria-expanded', 'true' );
|
|
64
70
|
|
|
@@ -82,7 +88,7 @@ describe( 'Menu', () => {
|
|
|
82
88
|
expect( submenuTrigger ).toHaveAttribute( 'aria-haspopup', 'menu' );
|
|
83
89
|
expect( submenuTrigger ).toHaveAttribute( 'aria-expanded', 'false' );
|
|
84
90
|
|
|
85
|
-
await hover( submenuTrigger );
|
|
91
|
+
await user.hover( submenuTrigger );
|
|
86
92
|
|
|
87
93
|
// Wait for the open animation after hovering
|
|
88
94
|
await waitFor( () =>
|
|
@@ -119,7 +125,7 @@ describe( 'Menu', () => {
|
|
|
119
125
|
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument();
|
|
120
126
|
|
|
121
127
|
// Click to open the menu
|
|
122
|
-
await click( toggleButton );
|
|
128
|
+
await user.click( toggleButton );
|
|
123
129
|
|
|
124
130
|
// Menu open, focus is on the menu wrapper
|
|
125
131
|
await waitForFocusedMenu();
|
|
@@ -142,14 +148,14 @@ describe( 'Menu', () => {
|
|
|
142
148
|
} );
|
|
143
149
|
|
|
144
150
|
// Move focus on the toggle
|
|
145
|
-
await
|
|
151
|
+
await user.tab();
|
|
146
152
|
|
|
147
153
|
expect( toggleButton ).toHaveFocus();
|
|
148
154
|
|
|
149
155
|
// Menu closed
|
|
150
156
|
expect( screen.queryByRole( 'menuitem' ) ).not.toBeInTheDocument();
|
|
151
157
|
|
|
152
|
-
await
|
|
158
|
+
await user.keyboard( '{ArrowDown}' );
|
|
153
159
|
|
|
154
160
|
// Menu open, focus is on the first focusable item
|
|
155
161
|
// (disabled items are still focusable and accessible)
|
|
@@ -173,16 +179,16 @@ describe( 'Menu', () => {
|
|
|
173
179
|
} );
|
|
174
180
|
|
|
175
181
|
// Move focus on the toggle
|
|
176
|
-
await
|
|
182
|
+
await user.tab();
|
|
177
183
|
|
|
178
184
|
expect( toggleButton ).toHaveFocus();
|
|
179
185
|
|
|
180
186
|
// Menu closed
|
|
181
187
|
expect( screen.queryByRole( 'menuitem' ) ).not.toBeInTheDocument();
|
|
182
188
|
|
|
183
|
-
//
|
|
184
|
-
// distinguish
|
|
185
|
-
await
|
|
189
|
+
// Use keyboard activation so the synthetic click has `detail: 0`,
|
|
190
|
+
// which Ariakit uses to distinguish it from pointer activation.
|
|
191
|
+
await user.keyboard( ' ' );
|
|
186
192
|
|
|
187
193
|
await waitFor( () =>
|
|
188
194
|
expect( toggleButton ).toHaveAttribute(
|
|
@@ -207,16 +213,18 @@ describe( 'Menu', () => {
|
|
|
207
213
|
name: 'Open dropdown',
|
|
208
214
|
} );
|
|
209
215
|
|
|
210
|
-
await click( trigger );
|
|
216
|
+
await user.click( trigger );
|
|
211
217
|
|
|
212
218
|
// Focuses menu on mouse click, focuses first item on keyboard press
|
|
213
219
|
// Can be changed with a custom useEffect
|
|
214
220
|
await waitForFocusedMenu();
|
|
215
221
|
|
|
216
222
|
// Pressing esc will close the menu and move focus to the toggle
|
|
217
|
-
await
|
|
223
|
+
await user.keyboard( '{Escape}' );
|
|
218
224
|
|
|
219
|
-
|
|
225
|
+
await waitFor( () =>
|
|
226
|
+
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument()
|
|
227
|
+
);
|
|
220
228
|
|
|
221
229
|
await waitFor( () =>
|
|
222
230
|
expect(
|
|
@@ -238,9 +246,11 @@ describe( 'Menu', () => {
|
|
|
238
246
|
expect( screen.getByRole( 'menu' ) ).toBeInTheDocument();
|
|
239
247
|
|
|
240
248
|
// Click on the body (ie. outside of the dropdown menu)
|
|
241
|
-
await click( document.body );
|
|
249
|
+
await user.click( document.body );
|
|
242
250
|
|
|
243
|
-
|
|
251
|
+
await waitFor( () =>
|
|
252
|
+
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument()
|
|
253
|
+
);
|
|
244
254
|
} );
|
|
245
255
|
|
|
246
256
|
it( 'should close when clicking on a menu item', async () => {
|
|
@@ -256,9 +266,11 @@ describe( 'Menu', () => {
|
|
|
256
266
|
expect( screen.getByRole( 'menu' ) ).toBeInTheDocument();
|
|
257
267
|
|
|
258
268
|
// Clicking a menu item will close the menu
|
|
259
|
-
await click( screen.getByRole( 'menuitem' ) );
|
|
269
|
+
await user.click( screen.getByRole( 'menuitem' ) );
|
|
260
270
|
|
|
261
|
-
|
|
271
|
+
await waitFor( () =>
|
|
272
|
+
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument()
|
|
273
|
+
);
|
|
262
274
|
} );
|
|
263
275
|
|
|
264
276
|
it( 'should not close when clicking on a menu item when the `hideOnClick` prop is set to `false`', async () => {
|
|
@@ -274,7 +286,7 @@ describe( 'Menu', () => {
|
|
|
274
286
|
expect( screen.getByRole( 'menu' ) ).toBeVisible();
|
|
275
287
|
|
|
276
288
|
// Clicking a menu item will close the menu
|
|
277
|
-
await click( screen.getByRole( 'menuitem' ) );
|
|
289
|
+
await user.click( screen.getByRole( 'menuitem' ) );
|
|
278
290
|
|
|
279
291
|
expect( screen.getByRole( 'menu' ) ).toBeVisible();
|
|
280
292
|
} );
|
|
@@ -292,7 +304,7 @@ describe( 'Menu', () => {
|
|
|
292
304
|
expect( screen.getByRole( 'menu' ) ).toBeInTheDocument();
|
|
293
305
|
|
|
294
306
|
// Clicking a disabled menu item won't close the menu
|
|
295
|
-
await click( screen.getByRole( 'menuitem' ) );
|
|
307
|
+
await user.click( screen.getByRole( 'menuitem' ) );
|
|
296
308
|
|
|
297
309
|
expect( screen.getByRole( 'menu' ) ).toBeInTheDocument();
|
|
298
310
|
} );
|
|
@@ -325,7 +337,7 @@ describe( 'Menu', () => {
|
|
|
325
337
|
} )
|
|
326
338
|
).not.toBeInTheDocument();
|
|
327
339
|
|
|
328
|
-
await hover(
|
|
340
|
+
await user.hover(
|
|
329
341
|
screen.getByRole( 'menuitem', { name: 'Submenu trigger item' } )
|
|
330
342
|
);
|
|
331
343
|
|
|
@@ -358,57 +370,53 @@ describe( 'Menu', () => {
|
|
|
358
370
|
</Menu>
|
|
359
371
|
);
|
|
360
372
|
|
|
361
|
-
// The menu is focused automatically when `defaultOpen` is
|
|
362
|
-
|
|
373
|
+
// The first menu item is focused automatically when `defaultOpen` is
|
|
374
|
+
// set and jsdom reports visible elements as focusable.
|
|
375
|
+
await waitForFocusedMenuItem( 'Menu item 1' );
|
|
363
376
|
|
|
364
377
|
// Arrow up/down selects menu items
|
|
365
378
|
// The selection wraps around from last to first and viceversa
|
|
366
|
-
await
|
|
367
|
-
expect(
|
|
368
|
-
screen.getByRole( 'menuitem', { name: 'Menu item 1' } )
|
|
369
|
-
).toHaveFocus();
|
|
370
|
-
|
|
371
|
-
await press.ArrowDown();
|
|
379
|
+
await user.keyboard( '{ArrowDown}' );
|
|
372
380
|
expect(
|
|
373
381
|
screen.getByRole( 'menuitem', { name: 'Menu item 2' } )
|
|
374
382
|
).toHaveFocus();
|
|
375
383
|
|
|
376
|
-
await
|
|
384
|
+
await user.keyboard( '{ArrowDown}' );
|
|
377
385
|
expect(
|
|
378
386
|
screen.getByRole( 'menuitem', { name: 'Submenu trigger item' } )
|
|
379
387
|
).toHaveFocus();
|
|
380
388
|
|
|
381
|
-
await
|
|
389
|
+
await user.keyboard( '{ArrowDown}' );
|
|
382
390
|
expect(
|
|
383
391
|
screen.getByRole( 'menuitem', { name: 'Menu item 3' } )
|
|
384
392
|
).toHaveFocus();
|
|
385
393
|
|
|
386
|
-
await
|
|
394
|
+
await user.keyboard( '{ArrowDown}' );
|
|
387
395
|
expect(
|
|
388
396
|
screen.getByRole( 'menuitem', { name: 'Menu item 1' } )
|
|
389
397
|
).toHaveFocus();
|
|
390
398
|
|
|
391
|
-
await
|
|
399
|
+
await user.keyboard( '{ArrowUp}' );
|
|
392
400
|
expect(
|
|
393
401
|
screen.getByRole( 'menuitem', { name: 'Menu item 3' } )
|
|
394
402
|
).toHaveFocus();
|
|
395
403
|
|
|
396
|
-
await
|
|
404
|
+
await user.keyboard( '{ArrowUp}' );
|
|
397
405
|
expect(
|
|
398
406
|
screen.getByRole( 'menuitem', { name: 'Submenu trigger item' } )
|
|
399
407
|
).toHaveFocus();
|
|
400
408
|
|
|
401
409
|
// Arrow right/left can be used to enter/leave submenus
|
|
402
410
|
// (focus crosses menu contexts, so wait for it to settle)
|
|
403
|
-
await
|
|
411
|
+
await user.keyboard( '{ArrowRight}' );
|
|
404
412
|
await waitForFocusedMenuItem( 'Submenu item 1' );
|
|
405
413
|
|
|
406
|
-
await
|
|
414
|
+
await user.keyboard( '{ArrowDown}' );
|
|
407
415
|
expect(
|
|
408
416
|
screen.getByRole( 'menuitem', { name: 'Submenu item 2' } )
|
|
409
417
|
).toHaveFocus();
|
|
410
418
|
|
|
411
|
-
await
|
|
419
|
+
await user.keyboard( '{ArrowLeft}' );
|
|
412
420
|
expect(
|
|
413
421
|
screen.getByRole( 'menuitem', {
|
|
414
422
|
name: 'Submenu trigger item',
|
|
@@ -416,20 +424,20 @@ describe( 'Menu', () => {
|
|
|
416
424
|
).toHaveFocus();
|
|
417
425
|
|
|
418
426
|
// Spacebar or enter key can also be used to enter a submenu
|
|
419
|
-
await
|
|
427
|
+
await user.keyboard( '{Enter}' );
|
|
420
428
|
await waitForFocusedMenuItem( 'Submenu item 1' );
|
|
421
429
|
|
|
422
|
-
await
|
|
430
|
+
await user.keyboard( '{ArrowLeft}' );
|
|
423
431
|
expect(
|
|
424
432
|
screen.getByRole( 'menuitem', {
|
|
425
433
|
name: 'Submenu trigger item',
|
|
426
434
|
} )
|
|
427
435
|
).toHaveFocus();
|
|
428
436
|
|
|
429
|
-
await
|
|
437
|
+
await user.keyboard( ' ' );
|
|
430
438
|
await waitForFocusedMenuItem( 'Submenu item 1' );
|
|
431
439
|
|
|
432
|
-
await
|
|
440
|
+
await user.keyboard( '{ArrowLeft}' );
|
|
433
441
|
expect(
|
|
434
442
|
screen.getByRole( 'menuitem', {
|
|
435
443
|
name: 'Submenu trigger item',
|
|
@@ -478,7 +486,7 @@ describe( 'Menu', () => {
|
|
|
478
486
|
render( <ControlledRadioGroup /> );
|
|
479
487
|
|
|
480
488
|
// Open dropdown
|
|
481
|
-
await click(
|
|
489
|
+
await user.click(
|
|
482
490
|
screen.getByRole( 'button', { name: 'Open dropdown' } )
|
|
483
491
|
);
|
|
484
492
|
|
|
@@ -492,7 +500,7 @@ describe( 'Menu', () => {
|
|
|
492
500
|
).not.toBeChecked();
|
|
493
501
|
|
|
494
502
|
// Click first radio item, make sure that the callback fires
|
|
495
|
-
await click(
|
|
503
|
+
await user.click(
|
|
496
504
|
screen.getByRole( 'menuitemradio', { name: 'Radio item one' } )
|
|
497
505
|
);
|
|
498
506
|
expect( onRadioValueChangeSpy ).toHaveBeenCalledTimes( 1 );
|
|
@@ -509,7 +517,7 @@ describe( 'Menu', () => {
|
|
|
509
517
|
).not.toBeChecked();
|
|
510
518
|
|
|
511
519
|
// Click second radio item, make sure that the callback fires
|
|
512
|
-
await click(
|
|
520
|
+
await user.click(
|
|
513
521
|
screen.getByRole( 'menuitemradio', { name: 'Radio item two' } )
|
|
514
522
|
);
|
|
515
523
|
expect( onRadioValueChangeSpy ).toHaveBeenCalledTimes( 2 );
|
|
@@ -558,7 +566,7 @@ describe( 'Menu', () => {
|
|
|
558
566
|
);
|
|
559
567
|
|
|
560
568
|
// Open dropdown
|
|
561
|
-
await click(
|
|
569
|
+
await user.click(
|
|
562
570
|
screen.getByRole( 'button', { name: 'Open dropdown' } )
|
|
563
571
|
);
|
|
564
572
|
|
|
@@ -572,7 +580,7 @@ describe( 'Menu', () => {
|
|
|
572
580
|
).toBeChecked();
|
|
573
581
|
|
|
574
582
|
// Click first radio item, make sure that the callback fires
|
|
575
|
-
await click(
|
|
583
|
+
await user.click(
|
|
576
584
|
screen.getByRole( 'menuitemradio', { name: 'Radio item one' } )
|
|
577
585
|
);
|
|
578
586
|
expect( onRadioValueChangeSpy ).toHaveBeenCalledTimes( 1 );
|
|
@@ -589,7 +597,7 @@ describe( 'Menu', () => {
|
|
|
589
597
|
).not.toBeChecked();
|
|
590
598
|
|
|
591
599
|
// Click second radio item, make sure that the callback fires
|
|
592
|
-
await click(
|
|
600
|
+
await user.click(
|
|
593
601
|
screen.getByRole( 'menuitemradio', { name: 'Radio item two' } )
|
|
594
602
|
);
|
|
595
603
|
expect( onRadioValueChangeSpy ).toHaveBeenCalledTimes( 2 );
|
|
@@ -658,7 +666,7 @@ describe( 'Menu', () => {
|
|
|
658
666
|
render( <ControlledRadioGroup /> );
|
|
659
667
|
|
|
660
668
|
// Open dropdown
|
|
661
|
-
await click(
|
|
669
|
+
await user.click(
|
|
662
670
|
screen.getByRole( 'button', { name: 'Open dropdown' } )
|
|
663
671
|
);
|
|
664
672
|
|
|
@@ -678,7 +686,7 @@ describe( 'Menu', () => {
|
|
|
678
686
|
).not.toBeChecked();
|
|
679
687
|
|
|
680
688
|
// Click first checkbox item, make sure that the callback fires
|
|
681
|
-
await click(
|
|
689
|
+
await user.click(
|
|
682
690
|
screen.getByRole( 'menuitemcheckbox', {
|
|
683
691
|
name: 'Checkbox item one',
|
|
684
692
|
} )
|
|
@@ -698,7 +706,7 @@ describe( 'Menu', () => {
|
|
|
698
706
|
).toBeChecked();
|
|
699
707
|
|
|
700
708
|
// Click second checkbox item, make sure that the callback fires
|
|
701
|
-
await click(
|
|
709
|
+
await user.click(
|
|
702
710
|
screen.getByRole( 'menuitemcheckbox', {
|
|
703
711
|
name: 'Checkbox item two',
|
|
704
712
|
} )
|
|
@@ -718,7 +726,7 @@ describe( 'Menu', () => {
|
|
|
718
726
|
).toBeChecked();
|
|
719
727
|
|
|
720
728
|
// Click second checkbox item, make sure that the callback fires
|
|
721
|
-
await click(
|
|
729
|
+
await user.click(
|
|
722
730
|
screen.getByRole( 'menuitemcheckbox', {
|
|
723
731
|
name: 'Checkbox item two',
|
|
724
732
|
} )
|
|
@@ -778,7 +786,7 @@ describe( 'Menu', () => {
|
|
|
778
786
|
);
|
|
779
787
|
|
|
780
788
|
// Open dropdown
|
|
781
|
-
await click(
|
|
789
|
+
await user.click(
|
|
782
790
|
screen.getByRole( 'button', { name: 'Open dropdown' } )
|
|
783
791
|
);
|
|
784
792
|
|
|
@@ -798,7 +806,7 @@ describe( 'Menu', () => {
|
|
|
798
806
|
).toBeChecked();
|
|
799
807
|
|
|
800
808
|
// Click first checkbox item, make sure that the callback fires
|
|
801
|
-
await click(
|
|
809
|
+
await user.click(
|
|
802
810
|
screen.getByRole( 'menuitemcheckbox', {
|
|
803
811
|
name: 'Checkbox item one',
|
|
804
812
|
} )
|
|
@@ -818,7 +826,7 @@ describe( 'Menu', () => {
|
|
|
818
826
|
).toBeChecked();
|
|
819
827
|
|
|
820
828
|
// Click second checkbox item, make sure that the callback fires
|
|
821
|
-
await click(
|
|
829
|
+
await user.click(
|
|
822
830
|
screen.getByRole( 'menuitemcheckbox', {
|
|
823
831
|
name: 'Checkbox item two',
|
|
824
832
|
} )
|
|
@@ -838,7 +846,7 @@ describe( 'Menu', () => {
|
|
|
838
846
|
).not.toBeChecked();
|
|
839
847
|
|
|
840
848
|
// Click second checkbox item, make sure that the callback fires
|
|
841
|
-
await click(
|
|
849
|
+
await user.click(
|
|
842
850
|
screen.getByRole( 'menuitemcheckbox', {
|
|
843
851
|
name: 'Checkbox item two',
|
|
844
852
|
} )
|
|
@@ -874,7 +882,7 @@ describe( 'Menu', () => {
|
|
|
874
882
|
);
|
|
875
883
|
|
|
876
884
|
// Click to open the menu
|
|
877
|
-
await click(
|
|
885
|
+
await user.click(
|
|
878
886
|
screen.getByRole( 'button', {
|
|
879
887
|
name: 'Open dropdown',
|
|
880
888
|
} )
|
|
@@ -904,7 +912,7 @@ describe( 'Menu', () => {
|
|
|
904
912
|
);
|
|
905
913
|
|
|
906
914
|
// Click to open the menu
|
|
907
|
-
await click(
|
|
915
|
+
await user.click(
|
|
908
916
|
screen.getByRole( 'button', {
|
|
909
917
|
name: 'Open dropdown',
|
|
910
918
|
} )
|
|
@@ -922,9 +930,11 @@ describe( 'Menu', () => {
|
|
|
922
930
|
|
|
923
931
|
// The outer button can be focused by pressing tab. Doing so will cause
|
|
924
932
|
// the Menu to close.
|
|
925
|
-
await
|
|
933
|
+
await user.tab();
|
|
926
934
|
expect( outerButton ).toBeVisible();
|
|
927
|
-
|
|
935
|
+
await waitFor( () =>
|
|
936
|
+
expect( screen.queryByRole( 'menu' ) ).not.toBeInTheDocument()
|
|
937
|
+
);
|
|
928
938
|
} );
|
|
929
939
|
} );
|
|
930
940
|
|
|
@@ -942,7 +952,7 @@ describe( 'Menu', () => {
|
|
|
942
952
|
);
|
|
943
953
|
|
|
944
954
|
// Click to open the menu
|
|
945
|
-
await click(
|
|
955
|
+
await user.click(
|
|
946
956
|
screen.getByRole( 'button', {
|
|
947
957
|
name: 'Open dropdown',
|
|
948
958
|
} )
|
|
@@ -969,7 +979,7 @@ describe( 'Menu', () => {
|
|
|
969
979
|
);
|
|
970
980
|
|
|
971
981
|
// Click to open the menu
|
|
972
|
-
await click(
|
|
982
|
+
await user.click(
|
|
973
983
|
screen.getByRole( 'button', {
|
|
974
984
|
name: 'Open dropdown',
|
|
975
985
|
} )
|
|
@@ -1000,7 +1010,7 @@ describe( 'Menu', () => {
|
|
|
1000
1010
|
);
|
|
1001
1011
|
|
|
1002
1012
|
// Click to open the menu
|
|
1003
|
-
await click(
|
|
1013
|
+
await user.click(
|
|
1004
1014
|
screen.getByRole( 'button', {
|
|
1005
1015
|
name: 'Open dropdown',
|
|
1006
1016
|
} )
|
|
@@ -1031,7 +1041,7 @@ describe( 'Menu', () => {
|
|
|
1031
1041
|
);
|
|
1032
1042
|
|
|
1033
1043
|
// Click to open the menu
|
|
1034
|
-
await click(
|
|
1044
|
+
await user.click(
|
|
1035
1045
|
screen.getByRole( 'button', {
|
|
1036
1046
|
name: 'Open dropdown',
|
|
1037
1047
|
} )
|
|
@@ -1047,6 +1057,17 @@ describe( 'Menu', () => {
|
|
|
1047
1057
|
} );
|
|
1048
1058
|
|
|
1049
1059
|
describe( 'typeahead', () => {
|
|
1060
|
+
beforeEach( () => {
|
|
1061
|
+
jest.useFakeTimers();
|
|
1062
|
+
user = userEvent.setup( {
|
|
1063
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
1064
|
+
} );
|
|
1065
|
+
} );
|
|
1066
|
+
|
|
1067
|
+
afterEach( () => {
|
|
1068
|
+
jest.useRealTimers();
|
|
1069
|
+
} );
|
|
1070
|
+
|
|
1050
1071
|
it( 'should highlight matching item', async () => {
|
|
1051
1072
|
render(
|
|
1052
1073
|
<Menu>
|
|
@@ -1059,7 +1080,7 @@ describe( 'Menu', () => {
|
|
|
1059
1080
|
);
|
|
1060
1081
|
|
|
1061
1082
|
// Click to open the menu
|
|
1062
|
-
await click(
|
|
1083
|
+
await user.click(
|
|
1063
1084
|
screen.getByRole( 'button', {
|
|
1064
1085
|
name: 'Open dropdown',
|
|
1065
1086
|
} )
|
|
@@ -1067,17 +1088,16 @@ describe( 'Menu', () => {
|
|
|
1067
1088
|
await waitForFocusedMenu();
|
|
1068
1089
|
|
|
1069
1090
|
// Type "tw", it should match and focus the item with content "Two"
|
|
1070
|
-
await
|
|
1091
|
+
await user.keyboard( 'tw' );
|
|
1071
1092
|
expect(
|
|
1072
1093
|
screen.getByRole( 'menuitem', { name: 'Two' } )
|
|
1073
1094
|
).toHaveFocus();
|
|
1074
1095
|
|
|
1075
|
-
//
|
|
1076
|
-
|
|
1077
|
-
await delay( 500 );
|
|
1096
|
+
// Reset the typeahead search so the next keystrokes start a new query.
|
|
1097
|
+
resetTypeahead();
|
|
1078
1098
|
|
|
1079
1099
|
// Type "on", it should match and focus the item with content "One"
|
|
1080
|
-
await
|
|
1100
|
+
await user.keyboard( 'on' );
|
|
1081
1101
|
expect(
|
|
1082
1102
|
screen.getByRole( 'menuitem', { name: 'One' } )
|
|
1083
1103
|
).toHaveFocus();
|
|
@@ -1095,7 +1115,7 @@ describe( 'Menu', () => {
|
|
|
1095
1115
|
);
|
|
1096
1116
|
|
|
1097
1117
|
// Click to open the menu
|
|
1098
|
-
await click(
|
|
1118
|
+
await user.click(
|
|
1099
1119
|
screen.getByRole( 'button', {
|
|
1100
1120
|
name: 'Open dropdown',
|
|
1101
1121
|
} )
|
|
@@ -1103,35 +1123,32 @@ describe( 'Menu', () => {
|
|
|
1103
1123
|
await waitForFocusedMenu();
|
|
1104
1124
|
|
|
1105
1125
|
// Type a string that doesn't match any items. Focus shouldn't move.
|
|
1106
|
-
await
|
|
1126
|
+
await user.keyboard( 'abc' );
|
|
1107
1127
|
expect( screen.getByRole( 'menu' ) ).toHaveFocus();
|
|
1108
1128
|
|
|
1109
|
-
//
|
|
1110
|
-
|
|
1111
|
-
await delay( 500 );
|
|
1129
|
+
// Reset the typeahead search so the next keystrokes start a new query.
|
|
1130
|
+
resetTypeahead();
|
|
1112
1131
|
|
|
1113
1132
|
// Type "on", it should match and focus the item with content "One"
|
|
1114
|
-
await
|
|
1133
|
+
await user.keyboard( 'on' );
|
|
1115
1134
|
expect(
|
|
1116
1135
|
screen.getByRole( 'menuitem', { name: 'One' } )
|
|
1117
1136
|
).toHaveFocus();
|
|
1118
1137
|
|
|
1119
|
-
//
|
|
1120
|
-
|
|
1121
|
-
await delay( 500 );
|
|
1138
|
+
// Reset the typeahead search so the next keystrokes start a new query.
|
|
1139
|
+
resetTypeahead();
|
|
1122
1140
|
|
|
1123
1141
|
// Type a string that doesn't match any items. Focus shouldn't move.
|
|
1124
|
-
await
|
|
1142
|
+
await user.keyboard( 'abc' );
|
|
1125
1143
|
expect(
|
|
1126
1144
|
screen.getByRole( 'menuitem', { name: 'One' } )
|
|
1127
1145
|
).toHaveFocus();
|
|
1128
1146
|
|
|
1129
|
-
//
|
|
1130
|
-
|
|
1131
|
-
await delay( 500 );
|
|
1147
|
+
// Reset the typeahead search so the next keystrokes start a new query.
|
|
1148
|
+
resetTypeahead();
|
|
1132
1149
|
|
|
1133
1150
|
// Type "tw", it should match and focus the item with content "Two"
|
|
1134
|
-
await
|
|
1151
|
+
await user.keyboard( 'tw' );
|
|
1135
1152
|
expect(
|
|
1136
1153
|
screen.getByRole( 'menuitem', { name: 'Two' } )
|
|
1137
1154
|
).toHaveFocus();
|
package/src/menu/types.ts
CHANGED
|
@@ -258,7 +258,7 @@ export interface CheckboxItemProps {
|
|
|
258
258
|
* The checked state of the checkbox menu item when it is initially rendered.
|
|
259
259
|
* Use when not wanting to control its checked state.
|
|
260
260
|
*
|
|
261
|
-
* Note: this prop will be
|
|
261
|
+
* Note: this prop will be overridden by the `checked` prop, if it is defined.
|
|
262
262
|
*/
|
|
263
263
|
defaultChecked?: Ariakit.MenuItemCheckboxProps[ 'defaultChecked' ];
|
|
264
264
|
/**
|
|
@@ -321,7 +321,7 @@ export interface RadioItemProps {
|
|
|
321
321
|
* The checked state of the radio menu item when it is initially rendered.
|
|
322
322
|
* Use when not wanting to control its checked state.
|
|
323
323
|
*
|
|
324
|
-
* Note: this prop will be
|
|
324
|
+
* Note: this prop will be overridden by the `checked` prop, if it is defined.
|
|
325
325
|
*/
|
|
326
326
|
defaultChecked?: Ariakit.MenuItemRadioProps[ 'defaultChecked' ];
|
|
327
327
|
/**
|
|
@@ -20,6 +20,7 @@ exports[`MenuItem should match snapshot when all props provided 1`] = `
|
|
|
20
20
|
<svg
|
|
21
21
|
aria-hidden="true"
|
|
22
22
|
class="components-menu-items__item-icon has-icon-right"
|
|
23
|
+
fill="currentColor"
|
|
23
24
|
focusable="false"
|
|
24
25
|
height="24"
|
|
25
26
|
viewBox="0 0 24 24"
|
|
@@ -79,6 +80,7 @@ exports[`MenuItem should match snapshot when isSelected and role are optionally
|
|
|
79
80
|
<svg
|
|
80
81
|
aria-hidden="true"
|
|
81
82
|
class="components-menu-items__item-icon has-icon-right"
|
|
83
|
+
fill="currentColor"
|
|
82
84
|
focusable="false"
|
|
83
85
|
height="24"
|
|
84
86
|
viewBox="0 0 24 24"
|
package/src/modal/style.scss
CHANGED
package/src/modal/test/index.tsx
CHANGED
|
@@ -269,9 +269,6 @@ describe( 'Modal', () => {
|
|
|
269
269
|
} );
|
|
270
270
|
|
|
271
271
|
describe( 'Focus handling', () => {
|
|
272
|
-
const originalGetClientRects =
|
|
273
|
-
window.HTMLElement.prototype.getClientRects;
|
|
274
|
-
|
|
275
272
|
const FocusMountDemo = ( {
|
|
276
273
|
focusOnMount,
|
|
277
274
|
}: Pick< ModalProps, 'focusOnMount' > ) => {
|
|
@@ -300,27 +297,6 @@ describe( 'Modal', () => {
|
|
|
300
297
|
);
|
|
301
298
|
};
|
|
302
299
|
|
|
303
|
-
beforeEach( () => {
|
|
304
|
-
/**
|
|
305
|
-
* The test environment does not have a layout engine, so we need to mock
|
|
306
|
-
* the getClientRects method. This ensures that the focusable elements can be
|
|
307
|
-
* found by the `focusOnMount` logic which depends on layout information
|
|
308
|
-
* to determine if the element is visible or not.
|
|
309
|
-
* See https://github.com/WordPress/gutenberg/blob/trunk/packages/dom/src/focusable.js#L55-L61.
|
|
310
|
-
*/
|
|
311
|
-
// @ts-expect-error We're not trying to comply to the DOM spec, only mocking
|
|
312
|
-
window.HTMLElement.prototype.getClientRects = function () {
|
|
313
|
-
return [ 'trick-jsdom-into-having-size-for-element-rect' ];
|
|
314
|
-
};
|
|
315
|
-
} );
|
|
316
|
-
|
|
317
|
-
afterEach( () => {
|
|
318
|
-
// Restore original HTMLElement prototype.
|
|
319
|
-
// See beforeEach for details.
|
|
320
|
-
window.HTMLElement.prototype.getClientRects =
|
|
321
|
-
originalGetClientRects;
|
|
322
|
-
} );
|
|
323
|
-
|
|
324
300
|
it( 'should focus the Modal dialog by default when `focusOnMount` prop is not provided', async () => {
|
|
325
301
|
const user = userEvent.setup();
|
|
326
302
|
|
|
@@ -14,8 +14,8 @@ import { CONFIG } from '../utils';
|
|
|
14
14
|
* Milliseconds used as a fallback when racing `animationend` against a timeout.
|
|
15
15
|
*
|
|
16
16
|
* Sourced from `CONFIG.transitionDuration`. This value is implicitly coupled to
|
|
17
|
-
* the modal frame’s CSS `animation-duration` in `style.scss`, which uses
|
|
18
|
-
* `
|
|
17
|
+
* the modal frame’s CSS `animation-duration` in `style.scss`, which uses the
|
|
18
|
+
* WPDS `motion-duration-md` token. If either the token, the SCSS, or
|
|
19
19
|
* `CONFIG.transitionDuration` changes, keep them aligned so exit timing stays correct.
|
|
20
20
|
*/
|
|
21
21
|
const FRAME_ANIMATION_DURATION_MS = Number.parseInt(
|
|
@@ -28,23 +28,7 @@ const getNavigableMenuFocusables = () => [
|
|
|
28
28
|
screen.getByRole( 'link', { name: 'Item 4' } ),
|
|
29
29
|
];
|
|
30
30
|
|
|
31
|
-
const originalGetClientRects = window.HTMLElement.prototype.getClientRects;
|
|
32
|
-
|
|
33
31
|
describe( 'NavigableMenu', () => {
|
|
34
|
-
beforeAll( () => {
|
|
35
|
-
// Mocking `getClientRects()` is necessary to pass a check performed by
|
|
36
|
-
// the `focus.tabbable.find()` and by the `focus.focusable.find()` functions
|
|
37
|
-
// from the `@wordpress/dom` package.
|
|
38
|
-
// @ts-expect-error We're not trying to comply to the DOM spec, only mocking
|
|
39
|
-
window.HTMLElement.prototype.getClientRects = function () {
|
|
40
|
-
return [ 'trick-jsdom-into-having-size-for-element-rect' ];
|
|
41
|
-
};
|
|
42
|
-
} );
|
|
43
|
-
|
|
44
|
-
afterAll( () => {
|
|
45
|
-
window.HTMLElement.prototype.getClientRects = originalGetClientRects;
|
|
46
|
-
} );
|
|
47
|
-
|
|
48
32
|
it( 'moves focus on its focusable children by using the up/down arrow keys', async () => {
|
|
49
33
|
const user = userEvent.setup();
|
|
50
34
|
|