@wordpress/components 23.2.0 → 23.3.1
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 +35 -1
- package/CONTRIBUTING.md +1 -1
- package/build/alignment-matrix-control/utils.js +2 -2
- package/build/alignment-matrix-control/utils.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -3
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
- package/build/border-control/border-control-dropdown/component.js +8 -4
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/button/deprecated.js +8 -6
- package/build/button/deprecated.js.map +1 -1
- package/build/button/index.js +52 -23
- package/build/button/index.js.map +1 -1
- package/build/button/types.js +6 -0
- package/build/button/types.js.map +1 -0
- package/build/color-list-picker/index.js.map +1 -1
- package/build/color-list-picker/types.js +6 -0
- package/build/color-list-picker/types.js.map +1 -0
- package/build/color-palette/index.js +9 -61
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +24 -9
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-palette/utils.js +103 -0
- package/build/color-palette/utils.js.map +1 -0
- package/build/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/dropdown/index.js +20 -8
- package/build/dropdown/index.js.map +1 -1
- package/build/form-token-field/token.js +1 -1
- package/build/form-token-field/token.js.map +1 -1
- package/build/gradient-picker/index.js +9 -1
- package/build/gradient-picker/index.js.map +1 -1
- package/build/h-stack/component.js +0 -1
- package/build/h-stack/component.js.map +1 -1
- package/build/input-control/input-field.js +4 -2
- package/build/input-control/input-field.js.map +1 -1
- package/build/keyboard-shortcuts/index.js +44 -16
- package/build/keyboard-shortcuts/index.js.map +1 -1
- package/build/keyboard-shortcuts/types.js +6 -0
- package/build/keyboard-shortcuts/types.js.map +1 -0
- package/build/modal/index.js +1 -1
- package/build/modal/index.js.map +1 -1
- package/build/notice/index.js +16 -18
- package/build/notice/index.js.map +1 -1
- package/build/notice/list.js +23 -8
- package/build/notice/list.js.map +1 -1
- package/build/notice/types.js +6 -0
- package/build/notice/types.js.map +1 -0
- package/build/number-control/index.js +1 -1
- package/build/number-control/index.js.map +1 -1
- package/build/query-controls/author-select.js +7 -3
- package/build/query-controls/author-select.js.map +1 -1
- package/build/query-controls/category-select.js +7 -3
- package/build/query-controls/category-select.js.map +1 -1
- package/build/query-controls/index.js +68 -20
- package/build/query-controls/index.js.map +1 -1
- package/build/query-controls/terms.js +4 -3
- package/build/query-controls/terms.js.map +1 -1
- package/build/query-controls/types.js +6 -0
- package/build/query-controls/types.js.map +1 -0
- package/build/slot-fill/bubbles-virtually/fill.js +1 -0
- package/build/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build/slot-fill/slot.js +1 -0
- package/build/slot-fill/slot.js.map +1 -1
- package/build/slot-fill/use-slot.js +1 -11
- package/build/slot-fill/use-slot.js.map +1 -1
- package/build/snackbar/index.js.map +1 -1
- package/build/snackbar/list.js.map +1 -1
- package/build/tab-panel/index.js +36 -8
- package/build/tab-panel/index.js.map +1 -1
- package/build/tree-grid/index.js +1 -1
- package/build/tree-grid/index.js.map +1 -1
- package/build/tree-select/index.js +2 -6
- package/build/tree-select/index.js.map +1 -1
- package/build-module/alignment-matrix-control/utils.js +2 -2
- package/build-module/alignment-matrix-control/utils.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -2
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +7 -4
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/button/deprecated.js +8 -5
- package/build-module/button/deprecated.js.map +1 -1
- package/build-module/button/index.js +51 -22
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/types.js +2 -0
- package/build-module/button/types.js.map +1 -0
- package/build-module/color-list-picker/index.js.map +1 -1
- package/build-module/color-list-picker/types.js +2 -0
- package/build-module/color-list-picker/types.js.map +1 -0
- package/build-module/color-palette/index.js +7 -54
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +24 -8
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-palette/utils.js +79 -0
- package/build-module/color-palette/utils.js.map +1 -0
- package/build-module/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build-module/date-time/date/index.js +1 -1
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/dropdown/index.js +19 -8
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/form-token-field/token.js +1 -1
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/gradient-picker/index.js +9 -2
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/h-stack/component.js +0 -1
- package/build-module/h-stack/component.js.map +1 -1
- package/build-module/input-control/input-field.js +4 -2
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/keyboard-shortcuts/index.js +48 -16
- package/build-module/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/keyboard-shortcuts/types.js +2 -0
- package/build-module/keyboard-shortcuts/types.js.map +1 -0
- package/build-module/modal/index.js +1 -1
- package/build-module/modal/index.js.map +1 -1
- package/build-module/notice/index.js +14 -15
- package/build-module/notice/index.js.map +1 -1
- package/build-module/notice/list.js +23 -8
- package/build-module/notice/list.js.map +1 -1
- package/build-module/notice/types.js +2 -0
- package/build-module/notice/types.js.map +1 -0
- package/build-module/number-control/index.js +1 -1
- package/build-module/number-control/index.js.map +1 -1
- package/build-module/query-controls/author-select.js +7 -3
- package/build-module/query-controls/author-select.js.map +1 -1
- package/build-module/query-controls/category-select.js +8 -4
- package/build-module/query-controls/category-select.js.map +1 -1
- package/build-module/query-controls/index.js +64 -20
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/query-controls/terms.js +8 -4
- package/build-module/query-controls/terms.js.map +1 -1
- package/build-module/query-controls/types.js +2 -0
- package/build-module/query-controls/types.js.map +1 -0
- package/build-module/slot-fill/bubbles-virtually/fill.js +1 -0
- package/build-module/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build-module/slot-fill/slot.js +1 -0
- package/build-module/slot-fill/slot.js.map +1 -1
- package/build-module/slot-fill/use-slot.js +2 -12
- package/build-module/slot-fill/use-slot.js.map +1 -1
- package/build-module/snackbar/index.js.map +1 -1
- package/build-module/snackbar/list.js.map +1 -1
- package/build-module/tab-panel/index.js +36 -8
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/tree-grid/index.js +1 -1
- package/build-module/tree-grid/index.js.map +1 -1
- package/build-module/tree-select/index.js +2 -6
- package/build-module/tree-select/index.js.map +1 -1
- package/build-style/style-rtl.css +5 -0
- package/build-style/style.css +5 -0
- package/build-types/border-box-control/border-box-control/hook.d.ts +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/component.d.ts +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +171 -160
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -1
- package/build-types/border-control/border-control/hook.d.ts +1 -1
- package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/hook.d.ts +1 -1
- package/build-types/button/deprecated.d.ts +143 -7
- package/build-types/button/deprecated.d.ts.map +1 -1
- package/build-types/button/index.d.ts +20 -3
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/stories/index.d.ts +20 -0
- package/build-types/button/stories/index.d.ts.map +1 -0
- package/build-types/button/test/index.d.ts +2 -0
- package/build-types/button/test/index.d.ts.map +1 -0
- package/build-types/button/types.d.ts +134 -0
- package/build-types/button/types.d.ts.map +1 -0
- package/build-types/color-list-picker/index.d.ts +5 -0
- package/build-types/color-list-picker/index.d.ts.map +1 -0
- package/build-types/color-list-picker/types.d.ts +42 -0
- package/build-types/color-list-picker/types.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +2 -4
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-palette/stories/index.d.ts +2 -2
- package/build-types/color-palette/styles.d.ts +1 -1
- package/build-types/color-palette/types.d.ts +1 -1
- package/build-types/color-palette/types.d.ts.map +1 -1
- package/build-types/color-palette/utils.d.ts +14 -0
- package/build-types/color-palette/utils.d.ts.map +1 -0
- package/build-types/color-picker/styles.d.ts +2 -2
- package/build-types/date-time/date/index.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +3 -3
- package/build-types/dropdown/index.d.ts +4 -4
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/dropdown/stories/index.d.ts.map +1 -1
- package/build-types/dropdown/types.d.ts +9 -10
- package/build-types/dropdown/types.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +2 -2
- package/build-types/h-stack/component.d.ts +0 -1
- package/build-types/h-stack/component.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/keyboard-shortcuts/index.d.ts +38 -0
- package/build-types/keyboard-shortcuts/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/stories/index.d.ts +12 -0
- package/build-types/keyboard-shortcuts/stories/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/test/index.d.ts +2 -0
- package/build-types/keyboard-shortcuts/test/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/types.d.ts +48 -0
- package/build-types/keyboard-shortcuts/types.d.ts.map +1 -0
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +2 -2
- package/build-types/navigator/navigator-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +2 -2
- package/build-types/notice/index.d.ts +16 -0
- package/build-types/notice/index.d.ts.map +1 -0
- package/build-types/notice/list.d.ts +32 -0
- package/build-types/notice/list.d.ts.map +1 -0
- package/build-types/notice/stories/index.d.ts +17 -0
- package/build-types/notice/stories/index.d.ts.map +1 -0
- package/build-types/notice/test/index.d.ts +2 -0
- package/build-types/notice/test/index.d.ts.map +1 -0
- package/build-types/notice/test/list.d.ts +2 -0
- package/build-types/notice/test/list.d.ts.map +1 -0
- package/build-types/notice/types.d.ts +128 -0
- package/build-types/notice/types.d.ts.map +1 -0
- package/build-types/number-control/styles/number-control-styles.d.ts +2 -2
- package/build-types/number-control/styles/number-control-styles.d.ts.map +1 -1
- package/build-types/placeholder/stories/index.d.ts.map +1 -1
- package/build-types/query-controls/author-select.d.ts +4 -0
- package/build-types/query-controls/author-select.d.ts.map +1 -0
- package/build-types/query-controls/category-select.d.ts +4 -0
- package/build-types/query-controls/category-select.d.ts.map +1 -0
- package/build-types/query-controls/index.d.ts +30 -0
- package/build-types/query-controls/index.d.ts.map +1 -0
- package/build-types/query-controls/stories/index.d.ts +13 -0
- package/build-types/query-controls/stories/index.d.ts.map +1 -0
- package/build-types/query-controls/terms.d.ts +13 -0
- package/build-types/query-controls/terms.d.ts.map +1 -0
- package/build-types/query-controls/test/terms.d.ts +2 -0
- package/build-types/query-controls/test/terms.d.ts.map +1 -0
- package/build-types/query-controls/types.d.ts +131 -0
- package/build-types/query-controls/types.d.ts.map +1 -0
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -1
- package/build-types/slot-fill/use-slot.d.ts.map +1 -1
- package/build-types/snackbar/index.d.ts +9 -2
- package/build-types/snackbar/index.d.ts.map +1 -1
- package/build-types/snackbar/list.d.ts.map +1 -1
- package/build-types/snackbar/types.d.ts +15 -88
- package/build-types/snackbar/types.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/tab-panel/types.d.ts +1 -1
- package/build-types/tab-panel/types.d.ts.map +1 -1
- package/build-types/toggle-group-control/stories/index.d.ts.map +1 -1
- package/build-types/tree-select/index.d.ts.map +1 -1
- package/build-types/ui/form-group/form-group.d.ts +2 -2
- package/package.json +18 -17
- package/src/alignment-matrix-control/utils.tsx +2 -2
- package/src/autocomplete/autocompleter-ui.js +1 -2
- package/src/autocomplete/test/index.js +1 -5
- package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
- package/src/border-box-control/border-box-control-linked-button/hook.ts +1 -1
- package/src/border-control/border-control-dropdown/component.tsx +9 -8
- package/src/box-control/test/index.js +11 -35
- package/src/button/README.md +49 -55
- package/src/button/{deprecated.js → deprecated.tsx} +19 -4
- package/src/button/{index.js → index.tsx} +95 -34
- package/src/button/stories/index.tsx +106 -0
- package/src/button/style.scss +3 -2
- package/src/button/test/{index.js → index.tsx} +30 -7
- package/src/button/types.ts +138 -0
- package/src/checkbox-control/test/index.tsx +1 -5
- package/src/color-list-picker/{index.js → index.tsx} +3 -2
- package/src/color-list-picker/types.ts +46 -0
- package/src/color-palette/README.md +1 -1
- package/src/color-palette/index.native.js +11 -4
- package/src/color-palette/index.tsx +11 -67
- package/src/color-palette/test/index.tsx +4 -14
- package/src/color-palette/test/utils.ts +1 -1
- package/src/color-palette/types.ts +1 -1
- package/src/color-palette/utils.ts +98 -0
- package/src/color-picker/test/index.js +6 -15
- package/src/combobox-control/test/index.js +1 -6
- package/src/confirm-dialog/test/index.js +9 -29
- package/src/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/src/date-time/date/index.tsx +2 -1
- package/src/date-time/date/test/index.tsx +2 -8
- package/src/date-time/time/test/index.tsx +9 -29
- package/src/dimension-control/test/index.test.js +2 -8
- package/src/disabled/test/index.tsx +1 -5
- package/src/draggable/test/index.native.js +4 -4
- package/src/dropdown/README.md +1 -8
- package/src/dropdown/index.tsx +17 -6
- package/src/dropdown/stories/index.tsx +3 -3
- package/src/dropdown/test/index.tsx +2 -8
- package/src/dropdown/types.ts +9 -10
- package/src/dropdown-menu/README.md +1 -1
- package/src/dropdown-menu/stories/index.js +96 -27
- package/src/dropdown-menu/test/index.js +2 -8
- package/src/external-link/test/index.tsx +1 -6
- package/src/focal-point-picker/test/index.js +3 -11
- package/src/font-size-picker/test/index.tsx +14 -44
- package/src/form-file-upload/test/index.tsx +2 -17
- package/src/form-toggle/test/index.tsx +1 -5
- package/src/form-token-field/test/index.tsx +80 -163
- package/src/form-token-field/token.tsx +1 -1
- package/src/gradient-picker/index.js +15 -4
- package/src/guide/test/index.js +5 -17
- package/src/h-stack/component.tsx +0 -1
- package/src/higher-order/with-filters/test/index.js +24 -24
- package/src/higher-order/with-focus-outside/test/index.js +11 -25
- package/src/higher-order/with-focus-return/test/index.js +1 -5
- package/src/input-control/input-field.tsx +3 -1
- package/src/input-control/test/index.js +1 -6
- package/src/isolated-event-container/test/index.js +2 -8
- package/src/keyboard-shortcuts/README.md +1 -1
- package/src/keyboard-shortcuts/index.tsx +93 -0
- package/src/keyboard-shortcuts/stories/index.tsx +60 -0
- package/src/keyboard-shortcuts/test/{index.js → index.tsx} +16 -6
- package/src/keyboard-shortcuts/types.ts +51 -0
- package/src/modal/index.tsx +1 -2
- package/src/navigable-container/test/navigable-menu.js +5 -17
- package/src/navigable-container/test/tababble-container.js +3 -11
- package/src/navigation/test/index.js +3 -11
- package/src/navigator/test/index.tsx +6 -20
- package/src/notice/README.md +89 -42
- package/src/notice/{index.js → index.tsx} +28 -20
- package/src/notice/list.tsx +72 -0
- package/src/notice/stories/index.tsx +119 -0
- package/src/notice/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/notice/test/{index.js → index.tsx} +7 -4
- package/src/notice/test/{list.js → list.tsx} +0 -0
- package/src/notice/types.ts +136 -0
- package/src/number-control/index.tsx +1 -1
- package/src/number-control/test/index.tsx +28 -86
- package/src/panel/test/body.js +2 -8
- package/src/placeholder/stories/index.tsx +1 -0
- package/src/query-controls/README.md +56 -56
- package/src/query-controls/author-select.tsx +37 -0
- package/src/query-controls/category-select.tsx +46 -0
- package/src/query-controls/index.tsx +192 -0
- package/src/query-controls/stories/index.tsx +205 -0
- package/src/query-controls/terms.ts +57 -0
- package/src/query-controls/test/{terms.js → terms.ts} +36 -20
- package/src/query-controls/types.ts +150 -0
- package/src/select-control/test/select-control.tsx +1 -6
- package/src/slot-fill/bubbles-virtually/fill.js +1 -0
- package/src/slot-fill/slot.js +1 -1
- package/src/slot-fill/use-slot.js +6 -16
- package/src/snackbar/index.tsx +6 -5
- package/src/snackbar/list.tsx +4 -2
- package/src/snackbar/types.ts +18 -92
- package/src/tab-panel/index.tsx +38 -16
- package/src/tab-panel/style.scss +8 -0
- package/src/tab-panel/test/index.tsx +35 -7
- package/src/tab-panel/types.ts +1 -1
- package/src/theme/test/index.tsx +4 -4
- package/src/toggle-group-control/stories/index.tsx +1 -0
- package/src/toggle-group-control/test/index.tsx +7 -23
- package/src/toolbar/stories/index.js +75 -72
- package/src/tools-panel/stories/index.js +3 -0
- package/src/tools-panel/test/index.js +1 -1
- package/src/tree-grid/index.js +1 -1
- package/src/tree-select/index.tsx +3 -6
- package/src/ui/context/test/context-connect.tsx +2 -0
- package/src/ui/context/test/wordpress-component.tsx +2 -0
- package/src/unit-control/test/index.tsx +21 -74
- package/src/utils/hooks/test/use-latest-ref.js +15 -18
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/radio-context/index.d.ts +0 -6
- package/build-types/radio-context/index.d.ts.map +0 -1
- package/src/button/stories/index.js +0 -179
- package/src/keyboard-shortcuts/index.js +0 -56
- package/src/notice/list.js +0 -48
- package/src/notice/stories/index.js +0 -46
- package/src/query-controls/author-select.js +0 -23
- package/src/query-controls/category-select.js +0 -31
- package/src/query-controls/index.js +0 -122
- package/src/query-controls/terms.js +0 -40
- package/src/toolbar/stories/toolbar-button.js +0 -32
- package/src/toolbar/stories/toolbar-group.js +0 -33
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { render, waitFor } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -13,8 +13,6 @@ import { addFilter, removeAllFilters, removeFilter } from '@wordpress/hooks';
|
|
|
13
13
|
*/
|
|
14
14
|
import withFilters from '..';
|
|
15
15
|
|
|
16
|
-
jest.useFakeTimers();
|
|
17
|
-
|
|
18
16
|
describe( 'withFilters', () => {
|
|
19
17
|
const hookName = 'EnhancedComponent';
|
|
20
18
|
const MyComponent = () => <div>My component</div>;
|
|
@@ -65,7 +63,7 @@ describe( 'withFilters', () => {
|
|
|
65
63
|
expect( container ).toMatchSnapshot();
|
|
66
64
|
} );
|
|
67
65
|
|
|
68
|
-
it( 'should not re-render component when new filter added before component was mounted', () => {
|
|
66
|
+
it( 'should not re-render component when new filter added before component was mounted', async () => {
|
|
69
67
|
const SpiedComponent = jest.fn( () => <div>Spied component</div> );
|
|
70
68
|
addFilter(
|
|
71
69
|
hookName,
|
|
@@ -81,13 +79,13 @@ describe( 'withFilters', () => {
|
|
|
81
79
|
|
|
82
80
|
const { container } = render( <EnhancedComponent /> );
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
await waitFor( () =>
|
|
83
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 1 )
|
|
84
|
+
);
|
|
87
85
|
expect( container ).toMatchSnapshot();
|
|
88
86
|
} );
|
|
89
87
|
|
|
90
|
-
it( 'should re-render component once when new filter added after component was mounted', () => {
|
|
88
|
+
it( 'should re-render component once when new filter added after component was mounted', async () => {
|
|
91
89
|
const SpiedComponent = jest.fn( () => <div>Spied component</div> );
|
|
92
90
|
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
|
|
93
91
|
|
|
@@ -106,13 +104,13 @@ describe( 'withFilters', () => {
|
|
|
106
104
|
)
|
|
107
105
|
);
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
107
|
+
await waitFor( () =>
|
|
108
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 1 )
|
|
109
|
+
);
|
|
112
110
|
expect( container ).toMatchSnapshot();
|
|
113
111
|
} );
|
|
114
112
|
|
|
115
|
-
it( 'should re-render component once when two filters added in the same animation frame', () => {
|
|
113
|
+
it( 'should re-render component once when two filters added in the same animation frame', async () => {
|
|
116
114
|
const SpiedComponent = jest.fn( () => <div>Spied component</div> );
|
|
117
115
|
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
|
|
118
116
|
|
|
@@ -141,13 +139,13 @@ describe( 'withFilters', () => {
|
|
|
141
139
|
)
|
|
142
140
|
);
|
|
143
141
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
await waitFor( () =>
|
|
143
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 1 )
|
|
144
|
+
);
|
|
147
145
|
expect( container ).toMatchSnapshot();
|
|
148
146
|
} );
|
|
149
147
|
|
|
150
|
-
it( 'should re-render component twice when new filter added and removed in two different animation frames', () => {
|
|
148
|
+
it( 'should re-render component twice when new filter added and removed in two different animation frames', async () => {
|
|
151
149
|
const SpiedComponent = jest.fn( () => <div>Spied component</div> );
|
|
152
150
|
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
|
|
153
151
|
const { container } = render( <EnhancedComponent /> );
|
|
@@ -165,17 +163,19 @@ describe( 'withFilters', () => {
|
|
|
165
163
|
)
|
|
166
164
|
);
|
|
167
165
|
|
|
168
|
-
|
|
166
|
+
await waitFor( () =>
|
|
167
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 1 )
|
|
168
|
+
);
|
|
169
169
|
|
|
170
170
|
removeFilter( hookName, 'test/enhanced-component-spy' );
|
|
171
171
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
await waitFor( () =>
|
|
173
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 2 )
|
|
174
|
+
);
|
|
175
175
|
expect( container ).toMatchSnapshot();
|
|
176
176
|
} );
|
|
177
177
|
|
|
178
|
-
it( 'should re-render both components once each when one filter added', () => {
|
|
178
|
+
it( 'should re-render both components once each when one filter added', async () => {
|
|
179
179
|
const SpiedComponent = jest.fn( () => <div>Spied component</div> );
|
|
180
180
|
const EnhancedComponent = withFilters( hookName )( SpiedComponent );
|
|
181
181
|
|
|
@@ -200,9 +200,9 @@ describe( 'withFilters', () => {
|
|
|
200
200
|
)
|
|
201
201
|
);
|
|
202
202
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
await waitFor( () =>
|
|
204
|
+
expect( SpiedComponent ).toHaveBeenCalledTimes( 2 )
|
|
205
|
+
);
|
|
206
206
|
expect( container ).toMatchSnapshot();
|
|
207
207
|
} );
|
|
208
208
|
} );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
5
5
|
import userEvent from '@testing-library/user-event';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -14,8 +14,6 @@ import { Component } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
import withFocusOutside from '../';
|
|
16
16
|
|
|
17
|
-
jest.useFakeTimers();
|
|
18
|
-
|
|
19
17
|
let onFocusOutside;
|
|
20
18
|
|
|
21
19
|
describe( 'withFocusOutside', () => {
|
|
@@ -57,7 +55,7 @@ describe( 'withFocusOutside', () => {
|
|
|
57
55
|
document.hasFocus = origHasFocus;
|
|
58
56
|
} );
|
|
59
57
|
|
|
60
|
-
it( 'should not call handler if focus shifts to element within component', () => {
|
|
58
|
+
it( 'should not call handler if focus shifts to element within component', async () => {
|
|
61
59
|
render( <TestComponent onFocusOutside={ onFocusOutside } /> );
|
|
62
60
|
|
|
63
61
|
const input = screen.getByRole( 'textbox' );
|
|
@@ -67,15 +65,11 @@ describe( 'withFocusOutside', () => {
|
|
|
67
65
|
input.blur();
|
|
68
66
|
button.focus();
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
expect( onFocusOutside ).not.toHaveBeenCalled();
|
|
68
|
+
await waitFor( () => expect( onFocusOutside ).not.toHaveBeenCalled() );
|
|
73
69
|
} );
|
|
74
70
|
|
|
75
71
|
it( 'should not call handler if focus transitions via click to button', async () => {
|
|
76
|
-
const user = userEvent.setup(
|
|
77
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
78
|
-
} );
|
|
72
|
+
const user = userEvent.setup();
|
|
79
73
|
render( <TestComponent onFocusOutside={ onFocusOutside } /> );
|
|
80
74
|
|
|
81
75
|
const input = screen.getByRole( 'textbox' );
|
|
@@ -84,24 +78,20 @@ describe( 'withFocusOutside', () => {
|
|
|
84
78
|
input.focus();
|
|
85
79
|
await user.click( button );
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
expect( onFocusOutside ).not.toHaveBeenCalled();
|
|
81
|
+
await waitFor( () => expect( onFocusOutside ).not.toHaveBeenCalled() );
|
|
90
82
|
} );
|
|
91
83
|
|
|
92
|
-
it( 'should call handler if focus doesn’t shift to element within component', () => {
|
|
84
|
+
it( 'should call handler if focus doesn’t shift to element within component', async () => {
|
|
93
85
|
render( <TestComponent onFocusOutside={ onFocusOutside } /> );
|
|
94
86
|
|
|
95
87
|
const input = screen.getByRole( 'textbox' );
|
|
96
88
|
input.focus();
|
|
97
89
|
input.blur();
|
|
98
90
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
expect( onFocusOutside ).toHaveBeenCalled();
|
|
91
|
+
await waitFor( () => expect( onFocusOutside ).toHaveBeenCalled() );
|
|
102
92
|
} );
|
|
103
93
|
|
|
104
|
-
it( 'should not call handler if focus shifts outside the component when the document does not have focus', () => {
|
|
94
|
+
it( 'should not call handler if focus shifts outside the component when the document does not have focus', async () => {
|
|
105
95
|
render( <TestComponent onFocusOutside={ onFocusOutside } /> );
|
|
106
96
|
|
|
107
97
|
// Force document.hasFocus() to return false to simulate the window/document losing focus
|
|
@@ -112,12 +102,10 @@ describe( 'withFocusOutside', () => {
|
|
|
112
102
|
input.focus();
|
|
113
103
|
input.blur();
|
|
114
104
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
expect( onFocusOutside ).not.toHaveBeenCalled();
|
|
105
|
+
await waitFor( () => expect( onFocusOutside ).not.toHaveBeenCalled() );
|
|
118
106
|
} );
|
|
119
107
|
|
|
120
|
-
it( 'should cancel check when unmounting while queued', () => {
|
|
108
|
+
it( 'should cancel check when unmounting while queued', async () => {
|
|
121
109
|
const { rerender } = render(
|
|
122
110
|
<TestComponent onFocusOutside={ onFocusOutside } />
|
|
123
111
|
);
|
|
@@ -128,8 +116,6 @@ describe( 'withFocusOutside', () => {
|
|
|
128
116
|
|
|
129
117
|
rerender( <div /> );
|
|
130
118
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
expect( onFocusOutside ).not.toHaveBeenCalled();
|
|
119
|
+
await waitFor( () => expect( onFocusOutside ).not.toHaveBeenCalled() );
|
|
134
120
|
} );
|
|
135
121
|
} );
|
|
@@ -14,8 +14,6 @@ import { Component } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
import withFocusReturn from '../';
|
|
16
16
|
|
|
17
|
-
jest.useFakeTimers();
|
|
18
|
-
|
|
19
17
|
class Test extends Component {
|
|
20
18
|
render() {
|
|
21
19
|
const { className, focusHistory } = this.props;
|
|
@@ -86,9 +84,7 @@ describe( 'withFocusReturn()', () => {
|
|
|
86
84
|
} );
|
|
87
85
|
|
|
88
86
|
it( 'should switch focus back when unmounted while having focus', async () => {
|
|
89
|
-
const user = userEvent.setup(
|
|
90
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
91
|
-
} );
|
|
87
|
+
const user = userEvent.setup();
|
|
92
88
|
|
|
93
89
|
const { unmount } = render( <Composite />, {
|
|
94
90
|
container: document.body.appendChild(
|
|
@@ -226,7 +226,9 @@ function InputField(
|
|
|
226
226
|
onMouseDown={ handleOnMouseDown }
|
|
227
227
|
ref={ ref }
|
|
228
228
|
inputSize={ size }
|
|
229
|
-
|
|
229
|
+
// Fallback to `''` to avoid "uncontrolled to controlled" warning.
|
|
230
|
+
// See https://github.com/WordPress/gutenberg/pull/47250 for details.
|
|
231
|
+
value={ value ?? '' }
|
|
230
232
|
type={ type }
|
|
231
233
|
/>
|
|
232
234
|
);
|
|
@@ -14,12 +14,7 @@ import { useState } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
import BaseInputControl from '../';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const setupUser = () =>
|
|
20
|
-
userEvent.setup( {
|
|
21
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
22
|
-
} );
|
|
17
|
+
const setupUser = () => userEvent.setup();
|
|
23
18
|
|
|
24
19
|
const getInput = () => screen.getByTestId( 'input' );
|
|
25
20
|
|
|
@@ -9,13 +9,9 @@ import userEvent from '@testing-library/user-event';
|
|
|
9
9
|
*/
|
|
10
10
|
import IsolatedEventContainer from '../';
|
|
11
11
|
|
|
12
|
-
jest.useFakeTimers();
|
|
13
|
-
|
|
14
12
|
describe( 'IsolatedEventContainer', () => {
|
|
15
13
|
it( 'should pass props to container', async () => {
|
|
16
|
-
const user = userEvent.setup(
|
|
17
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
18
|
-
} );
|
|
14
|
+
const user = userEvent.setup();
|
|
19
15
|
const clickHandler = jest.fn();
|
|
20
16
|
render(
|
|
21
17
|
<IsolatedEventContainer
|
|
@@ -47,9 +43,7 @@ describe( 'IsolatedEventContainer', () => {
|
|
|
47
43
|
} );
|
|
48
44
|
|
|
49
45
|
it( 'should stop event propagation only for mousedown, but not for keydown', async () => {
|
|
50
|
-
const user = userEvent.setup(
|
|
51
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
52
|
-
} );
|
|
46
|
+
const user = userEvent.setup();
|
|
53
47
|
|
|
54
48
|
const mousedownHandler = jest.fn();
|
|
55
49
|
const keydownHandler = jest.fn();
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useRef, Children } from '@wordpress/element';
|
|
5
|
+
import { useKeyboardShortcut } from '@wordpress/compose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import type { KeyboardShortcutProps, KeyboardShortcutsProps } from './types';
|
|
11
|
+
|
|
12
|
+
function KeyboardShortcut( {
|
|
13
|
+
target,
|
|
14
|
+
callback,
|
|
15
|
+
shortcut,
|
|
16
|
+
bindGlobal,
|
|
17
|
+
eventName,
|
|
18
|
+
}: KeyboardShortcutProps ) {
|
|
19
|
+
useKeyboardShortcut( shortcut, callback, {
|
|
20
|
+
bindGlobal,
|
|
21
|
+
target,
|
|
22
|
+
eventName,
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* `KeyboardShortcuts` is a component which handles keyboard sequences during the lifetime of the rendering element.
|
|
30
|
+
*
|
|
31
|
+
* When passed children, it will capture key events which occur on or within the children. If no children are passed, events are captured on the document.
|
|
32
|
+
*
|
|
33
|
+
* It uses the [Mousetrap](https://craig.is/killing/mice) library to implement keyboard sequence bindings.
|
|
34
|
+
*
|
|
35
|
+
* ```jsx
|
|
36
|
+
* import { KeyboardShortcuts } from '@wordpress/components';
|
|
37
|
+
* import { useState } from '@wordpress/element';
|
|
38
|
+
*
|
|
39
|
+
* const MyKeyboardShortcuts = () => {
|
|
40
|
+
* const [ isAllSelected, setIsAllSelected ] = useState( false );
|
|
41
|
+
* const selectAll = () => {
|
|
42
|
+
* setIsAllSelected( true );
|
|
43
|
+
* };
|
|
44
|
+
*
|
|
45
|
+
* return (
|
|
46
|
+
* <div>
|
|
47
|
+
* <KeyboardShortcuts
|
|
48
|
+
* shortcuts={ {
|
|
49
|
+
* 'mod+a': selectAll,
|
|
50
|
+
* } }
|
|
51
|
+
* />
|
|
52
|
+
* [cmd/ctrl + A] Combination pressed? { isAllSelected ? 'Yes' : 'No' }
|
|
53
|
+
* </div>
|
|
54
|
+
* );
|
|
55
|
+
* };
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function KeyboardShortcuts( {
|
|
59
|
+
children,
|
|
60
|
+
shortcuts,
|
|
61
|
+
bindGlobal,
|
|
62
|
+
eventName,
|
|
63
|
+
}: KeyboardShortcutsProps ) {
|
|
64
|
+
const target = useRef( null );
|
|
65
|
+
|
|
66
|
+
const element = Object.entries( shortcuts ?? {} ).map(
|
|
67
|
+
( [ shortcut, callback ] ) => (
|
|
68
|
+
<KeyboardShortcut
|
|
69
|
+
key={ shortcut }
|
|
70
|
+
shortcut={ shortcut }
|
|
71
|
+
callback={ callback }
|
|
72
|
+
bindGlobal={ bindGlobal }
|
|
73
|
+
eventName={ eventName }
|
|
74
|
+
target={ target }
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// Render as non-visual if there are no children pressed. Keyboard
|
|
80
|
+
// events will be bound to the document instead.
|
|
81
|
+
if ( ! Children.count( children ) ) {
|
|
82
|
+
return <>{ element }</>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div ref={ target }>
|
|
87
|
+
{ element }
|
|
88
|
+
{ children }
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default KeyboardShortcuts;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import KeyboardShortcuts from '..';
|
|
10
|
+
|
|
11
|
+
const meta: ComponentMeta< typeof KeyboardShortcuts > = {
|
|
12
|
+
component: KeyboardShortcuts,
|
|
13
|
+
title: 'Components/KeyboardShortcuts',
|
|
14
|
+
parameters: {
|
|
15
|
+
controls: { expanded: true },
|
|
16
|
+
docs: { source: { state: 'open' } },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export default meta;
|
|
20
|
+
|
|
21
|
+
const Template: ComponentStory< typeof KeyboardShortcuts > = ( props ) => (
|
|
22
|
+
<KeyboardShortcuts { ...props } />
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export const Default = Template.bind( {} );
|
|
26
|
+
Default.args = {
|
|
27
|
+
shortcuts: {
|
|
28
|
+
// eslint-disable-next-line no-alert
|
|
29
|
+
a: () => window.alert( 'You hit "a"!' ),
|
|
30
|
+
// eslint-disable-next-line no-alert
|
|
31
|
+
b: () => window.alert( 'You hit "b"!' ),
|
|
32
|
+
},
|
|
33
|
+
children: (
|
|
34
|
+
<div>
|
|
35
|
+
<p>{ `Hit the "a" or "b" key in this textarea:` }</p>
|
|
36
|
+
<textarea />
|
|
37
|
+
</div>
|
|
38
|
+
),
|
|
39
|
+
};
|
|
40
|
+
Default.parameters = {
|
|
41
|
+
docs: {
|
|
42
|
+
source: {
|
|
43
|
+
code: `
|
|
44
|
+
<KeyboardShortcuts
|
|
45
|
+
shortcuts={{
|
|
46
|
+
a: () => window.alert('You hit "a"!'),
|
|
47
|
+
b: () => window.alert('You hit "b"!'),
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<div>
|
|
51
|
+
<p>
|
|
52
|
+
Hit the "a" or "b" key in this textarea:
|
|
53
|
+
</p>
|
|
54
|
+
<textarea />
|
|
55
|
+
</div>
|
|
56
|
+
</KeyboardShortcuts>
|
|
57
|
+
`,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
+
import { createEvent, fireEvent, render, screen } from '@testing-library/react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import KeyboardShortcuts from '
|
|
9
|
+
import KeyboardShortcuts from '..';
|
|
10
10
|
|
|
11
11
|
describe( 'KeyboardShortcuts', () => {
|
|
12
|
-
function keyPress(
|
|
12
|
+
function keyPress(
|
|
13
|
+
which: KeyboardEvent[ 'which' ],
|
|
14
|
+
target: Parameters< typeof fireEvent >[ 0 ]
|
|
15
|
+
) {
|
|
13
16
|
[ 'keydown', 'keypress', 'keyup' ].forEach( ( eventName ) => {
|
|
14
|
-
const event =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const event = createEvent(
|
|
18
|
+
eventName,
|
|
19
|
+
target,
|
|
20
|
+
{
|
|
21
|
+
bubbles: true,
|
|
22
|
+
keyCode: which,
|
|
23
|
+
which,
|
|
24
|
+
},
|
|
25
|
+
{ EventType: 'KeyboardEvent' }
|
|
26
|
+
);
|
|
17
27
|
fireEvent( target, event );
|
|
18
28
|
} );
|
|
19
29
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { useKeyboardShortcut } from '@wordpress/compose';
|
|
5
|
+
|
|
6
|
+
// TODO: We wouldn't have to do this if this type was exported from `@wordpress/compose`.
|
|
7
|
+
type WPKeyboardShortcutConfig = NonNullable<
|
|
8
|
+
Parameters< typeof useKeyboardShortcut >[ 2 ]
|
|
9
|
+
>;
|
|
10
|
+
|
|
11
|
+
export type KeyboardShortcutProps = {
|
|
12
|
+
shortcut: string | string[];
|
|
13
|
+
/**
|
|
14
|
+
* @see {@link https://craig.is/killing/mice Mousetrap documentation}
|
|
15
|
+
*/
|
|
16
|
+
callback: ( event: Mousetrap.ExtendedKeyboardEvent, combo: string ) => void;
|
|
17
|
+
} & Pick< WPKeyboardShortcutConfig, 'bindGlobal' | 'eventName' | 'target' >;
|
|
18
|
+
|
|
19
|
+
export type KeyboardShortcutsProps = {
|
|
20
|
+
/**
|
|
21
|
+
* Elements to render, upon whom key events are to be monitored.
|
|
22
|
+
*/
|
|
23
|
+
children?: React.ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* An object of shortcut bindings, where each key is a keyboard combination,
|
|
26
|
+
* the value of which is the callback to be invoked when the key combination is pressed.
|
|
27
|
+
*
|
|
28
|
+
* The value of each shortcut should be a consistent function reference, not an anonymous function.
|
|
29
|
+
* Otherwise, the callback will not be correctly unbound when the component unmounts.
|
|
30
|
+
*
|
|
31
|
+
* The `KeyboardShortcuts` component will not update to reflect a changed `shortcuts` prop.
|
|
32
|
+
* If you need to change shortcuts, mount a separate `KeyboardShortcuts` element,
|
|
33
|
+
* which can be achieved by assigning a unique `key` prop.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://craig.is/killing/mice Mousetrap documentation}
|
|
36
|
+
*/
|
|
37
|
+
shortcuts: Record< string, KeyboardShortcutProps[ 'callback' ] >;
|
|
38
|
+
/**
|
|
39
|
+
* By default, a callback will not be invoked if the key combination occurs in an editable field.
|
|
40
|
+
* Pass `bindGlobal` as `true` if the key events should be observed globally, including within editable fields.
|
|
41
|
+
*
|
|
42
|
+
* Tip: If you need some but not all keyboard events to be observed globally,
|
|
43
|
+
* simply render two distinct `KeyboardShortcuts` elements, one with and one without the `bindGlobal` prop.
|
|
44
|
+
*/
|
|
45
|
+
bindGlobal?: KeyboardShortcutProps[ 'bindGlobal' ];
|
|
46
|
+
/**
|
|
47
|
+
* By default, a callback is invoked in response to the `keydown` event.
|
|
48
|
+
* To override this, pass `eventName` with the name of a specific keyboard event.
|
|
49
|
+
*/
|
|
50
|
+
eventName?: KeyboardShortcutProps[ 'eventName' ];
|
|
51
|
+
};
|
package/src/modal/index.tsx
CHANGED
|
@@ -9,8 +9,6 @@ import userEvent from '@testing-library/user-event';
|
|
|
9
9
|
*/
|
|
10
10
|
import { NavigableMenu } from '../menu';
|
|
11
11
|
|
|
12
|
-
jest.useFakeTimers();
|
|
13
|
-
|
|
14
12
|
const NavigableMenuTestCase = ( props ) => (
|
|
15
13
|
<NavigableMenu { ...props }>
|
|
16
14
|
<button>Item 1</button>
|
|
@@ -46,9 +44,7 @@ describe( 'NavigableMenu', () => {
|
|
|
46
44
|
} );
|
|
47
45
|
|
|
48
46
|
it( 'moves focus on its focusable children by using the up/down arrow keys', async () => {
|
|
49
|
-
const user = userEvent.setup(
|
|
50
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
51
|
-
} );
|
|
47
|
+
const user = userEvent.setup();
|
|
52
48
|
|
|
53
49
|
const onNavigateSpy = jest.fn();
|
|
54
50
|
|
|
@@ -87,9 +83,7 @@ describe( 'NavigableMenu', () => {
|
|
|
87
83
|
} );
|
|
88
84
|
|
|
89
85
|
it( 'moves focus on its focusable children by using the left/right arrow keys when the `orientation`prop is set to `horizontal', async () => {
|
|
90
|
-
const user = userEvent.setup(
|
|
91
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
92
|
-
} );
|
|
86
|
+
const user = userEvent.setup();
|
|
93
87
|
|
|
94
88
|
const onNavigateSpy = jest.fn();
|
|
95
89
|
|
|
@@ -133,9 +127,7 @@ describe( 'NavigableMenu', () => {
|
|
|
133
127
|
} );
|
|
134
128
|
|
|
135
129
|
it( 'should stop at the edges when the `cycle` prop is set to `false`', async () => {
|
|
136
|
-
const user = userEvent.setup(
|
|
137
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
138
|
-
} );
|
|
130
|
+
const user = userEvent.setup();
|
|
139
131
|
|
|
140
132
|
const onNavigateSpy = jest.fn();
|
|
141
133
|
|
|
@@ -193,9 +185,7 @@ describe( 'NavigableMenu', () => {
|
|
|
193
185
|
} );
|
|
194
186
|
|
|
195
187
|
it( 'stops keydown event propagation when arrow keys are pressed, regardless of the `orientation` prop', async () => {
|
|
196
|
-
const user = userEvent.setup(
|
|
197
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
198
|
-
} );
|
|
188
|
+
const user = userEvent.setup();
|
|
199
189
|
|
|
200
190
|
const externalWrapperOnKeyDownSpy = jest.fn();
|
|
201
191
|
|
|
@@ -224,9 +214,7 @@ describe( 'NavigableMenu', () => {
|
|
|
224
214
|
} );
|
|
225
215
|
|
|
226
216
|
it( 'skips its internal logic when the tab key is pressed', async () => {
|
|
227
|
-
const user = userEvent.setup(
|
|
228
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
229
|
-
} );
|
|
217
|
+
const user = userEvent.setup();
|
|
230
218
|
|
|
231
219
|
render(
|
|
232
220
|
<>
|
|
@@ -9,8 +9,6 @@ import userEvent from '@testing-library/user-event';
|
|
|
9
9
|
*/
|
|
10
10
|
import { TabbableContainer } from '../tabbable';
|
|
11
11
|
|
|
12
|
-
jest.useFakeTimers();
|
|
13
|
-
|
|
14
12
|
const TabbableContainerTestCase = ( props ) => (
|
|
15
13
|
<TabbableContainer { ...props }>
|
|
16
14
|
<button>Item 1</button>
|
|
@@ -49,9 +47,7 @@ describe( 'TabbableContainer', () => {
|
|
|
49
47
|
} );
|
|
50
48
|
|
|
51
49
|
it( 'moves focus on its tabbable children by using the tab key', async () => {
|
|
52
|
-
const user = userEvent.setup(
|
|
53
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
54
|
-
} );
|
|
50
|
+
const user = userEvent.setup();
|
|
55
51
|
|
|
56
52
|
const onNavigateSpy = jest.fn();
|
|
57
53
|
|
|
@@ -80,9 +76,7 @@ describe( 'TabbableContainer', () => {
|
|
|
80
76
|
} );
|
|
81
77
|
|
|
82
78
|
it( 'should stop at the edges when the `cycle` prop is set to `false`', async () => {
|
|
83
|
-
const user = userEvent.setup(
|
|
84
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
85
|
-
} );
|
|
79
|
+
const user = userEvent.setup();
|
|
86
80
|
|
|
87
81
|
const onNavigateSpy = jest.fn();
|
|
88
82
|
|
|
@@ -141,9 +135,7 @@ describe( 'TabbableContainer', () => {
|
|
|
141
135
|
} );
|
|
142
136
|
|
|
143
137
|
it( 'stops keydown event propagation when the tab key is pressed', async () => {
|
|
144
|
-
const user = userEvent.setup(
|
|
145
|
-
advanceTimers: jest.advanceTimersByTime,
|
|
146
|
-
} );
|
|
138
|
+
const user = userEvent.setup();
|
|
147
139
|
|
|
148
140
|
const externalWrapperOnKeyDownSpy = jest.fn();
|
|
149
141
|
|