@wordpress/components 19.11.0 → 19.12.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 +36 -0
- package/README.md +1 -1
- package/build/alignment-matrix-control/index.js +5 -2
- package/build/alignment-matrix-control/index.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -1
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.native.js +2 -2
- package/build/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build/autocomplete/index.js +12 -10
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +2 -2
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js +13 -4
- package/build/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-visualizer/hook.js +6 -2
- package/build/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build/border-box-control/styles.js +21 -11
- package/build/border-box-control/styles.js.map +1 -1
- package/build/border-control/border-control/hook.js +2 -2
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/color-palette/index.js +9 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +4 -1
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-picker/color-copy-button.js +87 -0
- package/build/color-picker/color-copy-button.js.map +1 -0
- package/build/color-picker/component.js +5 -15
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js +18 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/styles.js +11 -11
- package/build/color-picker/styles.js.map +1 -1
- package/build/custom-gradient-picker/utils.js +1 -1
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/date-time/{date.js → date/index.js} +51 -12
- package/build/date-time/date/index.js.map +1 -0
- package/build/date-time/date/styles.js +70 -0
- package/build/date-time/date/styles.js.map +1 -0
- package/build/date-time/{utils.js → date/utils.js} +0 -0
- package/build/date-time/date/utils.js.map +1 -0
- package/build/date-time/date-time/index.js +175 -0
- package/build/date-time/date-time/index.js.map +1 -0
- package/build/date-time/date-time/styles.js +32 -0
- package/build/date-time/date-time/styles.js.map +1 -0
- package/build/date-time/index.js +2 -109
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +322 -0
- package/build/date-time/time/index.js.map +1 -0
- package/build/date-time/time/styles.js +139 -0
- package/build/date-time/time/styles.js.map +1 -0
- package/build/date-time/{timezone.js → time/timezone.js} +4 -2
- package/build/date-time/time/timezone.js.map +1 -0
- package/build/draggable/index.native.js +10 -5
- package/build/draggable/index.native.js.map +1 -1
- package/build/dropdown/index.js +4 -1
- package/build/dropdown/index.js.map +1 -1
- package/build/input-control/index.js +9 -4
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/input-field.js +1 -26
- package/build/input-control/input-field.js.map +1 -1
- package/build/input-control/reducer/reducer.js +36 -24
- package/build/input-control/reducer/reducer.js.map +1 -1
- package/build/input-control/reducer/state.js +0 -1
- package/build/input-control/reducer/state.js.map +1 -1
- package/build/input-control/utils.js +45 -0
- package/build/input-control/utils.js.map +1 -1
- package/build/popover/index.js +40 -33
- package/build/popover/index.js.map +1 -1
- package/build/search-control/index.js +4 -6
- package/build/search-control/index.js.map +1 -1
- package/build/select-control/index.js +3 -1
- package/build/select-control/index.js.map +1 -1
- package/build/spacer/hook.js +11 -3
- package/build/spacer/hook.js.map +1 -1
- package/build/surface/component.js +7 -7
- package/build/surface/component.js.map +1 -1
- package/build/surface/hook.js +8 -11
- package/build/surface/hook.js.map +1 -1
- package/build/surface/index.js.map +1 -1
- package/build/surface/styles.js +8 -48
- package/build/surface/styles.js.map +1 -1
- package/build/textarea-control/index.js +40 -6
- package/build/textarea-control/index.js.map +1 -1
- package/build/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build/textarea-control/types.js +6 -0
- package/build/textarea-control/types.js.map +1 -0
- package/build/utils/hooks/index.js +0 -8
- package/build/utils/hooks/index.js.map +1 -1
- package/build-module/alignment-matrix-control/index.js +5 -2
- package/build-module/alignment-matrix-control/index.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -1
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.native.js +2 -2
- package/build-module/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build-module/autocomplete/index.js +13 -11
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +2 -2
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build-module/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/hook.js +11 -4
- package/build-module/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-visualizer/hook.js +4 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build-module/border-box-control/styles.js +13 -8
- package/build-module/border-box-control/styles.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +2 -2
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/color-palette/index.js +7 -5
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +4 -1
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-picker/color-copy-button.js +73 -0
- package/build-module/color-picker/color-copy-button.js.map +1 -0
- package/build-module/color-picker/component.js +6 -15
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js +18 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/styles.js +9 -9
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/custom-gradient-picker/utils.js +1 -1
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/date-time/{date.js → date/index.js} +46 -14
- package/build-module/date-time/date/index.js.map +1 -0
- package/build-module/date-time/date/styles.js +61 -0
- package/build-module/date-time/date/styles.js.map +1 -0
- package/build-module/date-time/{utils.js → date/utils.js} +0 -0
- package/build-module/date-time/date/utils.js.map +1 -0
- package/build-module/date-time/date-time/index.js +144 -0
- package/build-module/date-time/date-time/index.js.map +1 -0
- package/build-module/date-time/date-time/styles.js +22 -0
- package/build-module/date-time/date-time/styles.js.map +1 -0
- package/build-module/date-time/index.js +1 -105
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +302 -0
- package/build-module/date-time/time/index.js.map +1 -0
- package/build-module/date-time/time/styles.js +118 -0
- package/build-module/date-time/time/styles.js.map +1 -0
- package/build-module/date-time/{timezone.js → time/timezone.js} +3 -2
- package/build-module/date-time/time/timezone.js.map +1 -0
- package/build-module/draggable/index.native.js +10 -5
- package/build-module/draggable/index.native.js.map +1 -1
- package/build-module/dropdown/index.js +4 -1
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/input-control/index.js +8 -4
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/input-field.js +1 -25
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/input-control/reducer/reducer.js +38 -26
- package/build-module/input-control/reducer/reducer.js.map +1 -1
- package/build-module/input-control/reducer/state.js +0 -1
- package/build-module/input-control/reducer/state.js.map +1 -1
- package/build-module/input-control/utils.js +48 -2
- package/build-module/input-control/utils.js.map +1 -1
- package/build-module/popover/index.js +40 -33
- package/build-module/popover/index.js.map +1 -1
- package/build-module/search-control/index.js +6 -7
- package/build-module/search-control/index.js.map +1 -1
- package/build-module/select-control/index.js +3 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/spacer/hook.js +10 -2
- package/build-module/spacer/hook.js.map +1 -1
- package/build-module/surface/component.js +7 -7
- package/build-module/surface/component.js.map +1 -1
- package/build-module/surface/hook.js +8 -11
- package/build-module/surface/hook.js.map +1 -1
- package/build-module/surface/index.js.map +1 -1
- package/build-module/surface/styles.js +8 -48
- package/build-module/surface/styles.js.map +1 -1
- package/build-module/textarea-control/index.js +36 -5
- package/build-module/textarea-control/index.js.map +1 -1
- package/build-module/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build-module/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build-module/textarea-control/types.js +2 -0
- package/build-module/textarea-control/types.js.map +1 -0
- package/build-module/utils/hooks/index.js +0 -1
- package/build-module/utils/hooks/index.js.map +1 -1
- package/build-style/style-rtl.css +13 -188
- package/build-style/style.css +13 -191
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts.map +1 -1
- package/build-types/border-box-control/styles.d.ts +3 -2
- package/build-types/border-box-control/styles.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/card/types.d.ts +1 -1
- package/build-types/card/types.d.ts.map +1 -1
- package/build-types/checkbox-control/test/index.d.ts +2 -0
- package/build-types/checkbox-control/test/index.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/{date-time → color-palette}/test/utils.d.ts +0 -0
- package/build-types/color-palette/test/utils.d.ts.map +1 -0
- package/build-types/color-picker/color-copy-button.d.ts +4 -0
- package/build-types/color-picker/color-copy-button.d.ts.map +1 -0
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +8 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/date-time/{date.d.ts → date/index.d.ts} +3 -2
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +23 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/utils.d.ts +2 -0
- package/build-types/date-time/date/test/utils.d.ts.map +1 -0
- package/build-types/date-time/{utils.d.ts → date/utils.d.ts} +0 -0
- package/build-types/date-time/date/utils.d.ts.map +1 -0
- package/build-types/date-time/date-time/index.d.ts +33 -0
- package/build-types/date-time/date-time/index.d.ts.map +1 -0
- package/build-types/date-time/date-time/styles.d.ts +6 -0
- package/build-types/date-time/date-time/styles.d.ts.map +1 -0
- package/build-types/date-time/index.d.ts +2 -28
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/{index.d.ts → date-time.d.ts} +2 -2
- package/build-types/date-time/stories/date-time.d.ts.map +1 -0
- package/build-types/date-time/{time.d.ts → time/index.d.ts} +2 -2
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +111 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/{timezone.d.ts → time/timezone.d.ts} +0 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/date-time/types.d.ts +14 -15
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/reducer/reducer.d.ts +5 -3
- package/build-types/input-control/reducer/reducer.d.ts.map +1 -1
- package/build-types/input-control/reducer/state.d.ts +2 -2
- package/build-types/input-control/reducer/state.d.ts.map +1 -1
- package/build-types/input-control/utils.d.ts +17 -0
- package/build-types/input-control/utils.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -0
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +1 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/surface/component.d.ts +3 -2
- package/build-types/surface/component.d.ts.map +1 -1
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts.map +1 -1
- package/build-types/surface/index.d.ts +2 -2
- package/build-types/surface/index.d.ts.map +1 -1
- package/build-types/surface/stories/index.d.ts +12 -0
- package/build-types/surface/stories/index.d.ts.map +1 -0
- package/build-types/surface/styles.d.ts +10 -21
- package/build-types/surface/styles.d.ts.map +1 -1
- package/build-types/surface/test/index.d.ts +2 -0
- package/build-types/surface/test/index.d.ts.map +1 -0
- package/build-types/surface/types.d.ts +1 -1
- package/build-types/surface/types.d.ts.map +1 -1
- package/build-types/textarea-control/index.d.ts +29 -0
- package/build-types/textarea-control/index.d.ts.map +1 -0
- package/build-types/textarea-control/stories/index.d.ts +12 -0
- package/build-types/textarea-control/stories/index.d.ts.map +1 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts +6 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts.map +1 -0
- package/build-types/textarea-control/types.d.ts +26 -0
- package/build-types/textarea-control/types.d.ts.map +1 -0
- package/build-types/utils/hooks/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/alignment-matrix-control/index.js +4 -2
- package/src/autocomplete/autocompleter-ui.js +1 -1
- package/src/autocomplete/autocompleter-ui.native.js +2 -2
- package/src/autocomplete/index.js +21 -9
- package/src/border-box-control/border-box-control/hook.ts +2 -2
- package/src/border-box-control/border-box-control-split-controls/component.tsx +2 -0
- package/src/border-box-control/border-box-control-split-controls/hook.ts +18 -4
- package/src/border-box-control/border-box-control-visualizer/hook.ts +5 -2
- package/src/border-box-control/styles.ts +6 -2
- package/src/border-control/border-control/hook.ts +8 -2
- package/src/box-control/test/index.js +120 -109
- package/src/card/types.ts +1 -1
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +42 -0
- package/src/checkbox-control/test/index.tsx +109 -0
- package/src/color-palette/index.js +11 -4
- package/src/color-palette/index.native.js +3 -0
- package/src/color-palette/stories/index.js +25 -1
- package/src/color-palette/test/utils.ts +24 -0
- package/src/color-picker/color-copy-button.tsx +76 -0
- package/src/color-picker/component.tsx +18 -38
- package/src/color-picker/hex-input.tsx +16 -0
- package/src/color-picker/styles.ts +5 -1
- package/src/color-picker/types.ts +9 -0
- package/src/custom-gradient-picker/utils.js +1 -1
- package/src/date-time/README.md +16 -0
- package/src/date-time/{datepicker.scss → date/datepicker.scss} +0 -0
- package/src/date-time/{date.tsx → date/index.tsx} +38 -15
- package/src/date-time/date/style.scss +75 -0
- package/src/date-time/date/styles.ts +55 -0
- package/src/date-time/{test/date.tsx → date/test/index.tsx} +1 -1
- package/src/date-time/{test → date/test}/utils.ts +0 -0
- package/src/date-time/{utils.ts → date/utils.ts} +0 -0
- package/src/date-time/date-time/index.tsx +217 -0
- package/src/date-time/date-time/styles.ts +8 -0
- package/src/date-time/index.ts +9 -0
- package/src/date-time/stories/{index.tsx → date-time.tsx} +1 -1
- package/src/date-time/style.scss +1 -262
- package/src/date-time/time/index.tsx +356 -0
- package/src/date-time/time/styles.ts +119 -0
- package/src/date-time/{test/time.tsx → time/test/index.tsx} +85 -38
- package/src/date-time/{timezone.tsx → time/timezone.tsx} +5 -2
- package/src/date-time/types.ts +16 -18
- package/src/draggable/index.native.js +14 -3
- package/src/draggable/test/index.native.js +130 -0
- package/src/dropdown/index.js +5 -1
- package/src/input-control/index.tsx +8 -2
- package/src/input-control/input-field.tsx +10 -30
- package/src/input-control/reducer/reducer.ts +40 -26
- package/src/input-control/reducer/state.ts +2 -3
- package/src/input-control/utils.ts +55 -1
- package/src/popover/index.js +42 -27
- package/src/query-controls/README.md +1 -1
- package/src/search-control/index.js +6 -7
- package/src/select-control/README.md +11 -0
- package/src/select-control/index.tsx +6 -1
- package/src/select-control/types.ts +1 -1
- package/src/slot-fill/README.md +1 -1
- package/src/spacer/hook.ts +13 -13
- package/src/surface/README.md +15 -15
- package/src/surface/{component.js → component.tsx} +13 -7
- package/src/surface/{hook.js → hook.ts} +13 -12
- package/src/surface/{index.js → index.ts} +0 -0
- package/src/surface/stories/index.tsx +40 -0
- package/src/surface/{styles.js → styles.ts} +15 -44
- package/src/surface/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/surface/test/{index.js → index.tsx} +2 -1
- package/src/surface/types.ts +1 -1
- package/src/textarea-control/README.md +14 -20
- package/src/textarea-control/index.tsx +86 -0
- package/src/textarea-control/stories/index.tsx +58 -0
- package/src/textarea-control/styles/{textarea-control-styles.js → textarea-control-styles.ts} +0 -0
- package/src/textarea-control/types.ts +30 -0
- package/src/utils/hooks/index.js +0 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-picker/color-display.js +0 -184
- package/build/color-picker/color-display.js.map +0 -1
- package/build/date-time/date.js.map +0 -1
- package/build/date-time/time.js +0 -289
- package/build/date-time/time.js.map +0 -1
- package/build/date-time/timezone.js.map +0 -1
- package/build/date-time/utils.js.map +0 -1
- package/build/utils/hooks/use-combined-ref.js +0 -32
- package/build/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-module/color-picker/color-display.js +0 -170
- package/build-module/color-picker/color-display.js.map +0 -1
- package/build-module/date-time/date.js.map +0 -1
- package/build-module/date-time/time.js +0 -271
- package/build-module/date-time/time.js.map +0 -1
- package/build-module/date-time/timezone.js.map +0 -1
- package/build-module/date-time/utils.js.map +0 -1
- package/build-module/utils/hooks/use-combined-ref.js +0 -28
- package/build-module/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-types/color-picker/color-display.d.ts +0 -14
- package/build-types/color-picker/color-display.d.ts.map +0 -1
- package/build-types/date-time/date.d.ts.map +0 -1
- package/build-types/date-time/stories/index.d.ts.map +0 -1
- package/build-types/date-time/test/date.d.ts +0 -2
- package/build-types/date-time/test/date.d.ts.map +0 -1
- package/build-types/date-time/test/time.d.ts +0 -2
- package/build-types/date-time/test/time.d.ts.map +0 -1
- package/build-types/date-time/test/utils.d.ts.map +0 -1
- package/build-types/date-time/time.d.ts.map +0 -1
- package/build-types/date-time/timezone.d.ts.map +0 -1
- package/build-types/date-time/utils.d.ts.map +0 -1
- package/build-types/utils/hooks/use-combined-ref.d.ts +0 -8
- package/build-types/utils/hooks/use-combined-ref.d.ts.map +0 -1
- package/src/color-picker/color-display.tsx +0 -169
- package/src/date-time/index.tsx +0 -196
- package/src/date-time/time.tsx +0 -321
- package/src/surface/stories/index.js +0 -46
- package/src/textarea-control/index.js +0 -45
- package/src/textarea-control/stories/index.js +0 -48
- package/src/utils/hooks/use-combined-ref.ts +0 -28
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { render,
|
|
4
|
+
import { render, screen } from '@testing-library/react';
|
|
5
|
+
import userEvent from '@testing-library/user-event';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
import TimePicker from '
|
|
10
|
+
import TimePicker from '..';
|
|
10
11
|
|
|
11
12
|
describe( 'TimePicker', () => {
|
|
12
|
-
it( 'should call onChange with updated date values', () => {
|
|
13
|
+
it( 'should call onChange with updated date values', async () => {
|
|
14
|
+
const user = userEvent.setup( {
|
|
15
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
16
|
+
} );
|
|
17
|
+
|
|
13
18
|
const onChangeSpy = jest.fn();
|
|
14
19
|
|
|
15
20
|
render(
|
|
@@ -26,38 +31,46 @@ describe( 'TimePicker', () => {
|
|
|
26
31
|
const hoursInput = screen.getByLabelText( 'Hours' );
|
|
27
32
|
const minutesInput = screen.getByLabelText( 'Minutes' );
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
await user.selectOptions( monthInput, '12' );
|
|
35
|
+
await user.keyboard( '{Tab}' );
|
|
31
36
|
|
|
32
37
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-12-18T11:00:00' );
|
|
33
38
|
onChangeSpy.mockClear();
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
await user.clear( dayInput );
|
|
41
|
+
await user.type( dayInput, '22' );
|
|
42
|
+
await user.keyboard( '{Tab}' );
|
|
37
43
|
|
|
38
44
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-12-22T11:00:00' );
|
|
39
45
|
onChangeSpy.mockClear();
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
await user.clear( yearInput );
|
|
48
|
+
await user.type( yearInput, '2018' );
|
|
49
|
+
await user.keyboard( '{Tab}' );
|
|
43
50
|
|
|
44
51
|
expect( onChangeSpy ).toHaveBeenCalledWith( '2018-12-22T11:00:00' );
|
|
45
52
|
onChangeSpy.mockClear();
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
await user.clear( hoursInput );
|
|
55
|
+
await user.type( hoursInput, '12' );
|
|
56
|
+
await user.keyboard( '{Tab}' );
|
|
49
57
|
|
|
50
58
|
expect( onChangeSpy ).toHaveBeenCalledWith( '2018-12-22T00:00:00' );
|
|
51
59
|
onChangeSpy.mockClear();
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
await user.clear( minutesInput );
|
|
62
|
+
await user.type( minutesInput, '35' );
|
|
63
|
+
await user.keyboard( '{Tab}' );
|
|
55
64
|
|
|
56
65
|
expect( onChangeSpy ).toHaveBeenCalledWith( '2018-12-22T00:35:00' );
|
|
57
66
|
onChangeSpy.mockClear();
|
|
58
67
|
} );
|
|
59
68
|
|
|
60
|
-
it( 'should call onChange with an updated hour (12-hour clock)', () => {
|
|
69
|
+
it( 'should call onChange with an updated hour (12-hour clock)', async () => {
|
|
70
|
+
const user = userEvent.setup( {
|
|
71
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
72
|
+
} );
|
|
73
|
+
|
|
61
74
|
const onChangeSpy = jest.fn();
|
|
62
75
|
|
|
63
76
|
render(
|
|
@@ -70,13 +83,18 @@ describe( 'TimePicker', () => {
|
|
|
70
83
|
|
|
71
84
|
const hoursInput = screen.getByLabelText( 'Hours' );
|
|
72
85
|
|
|
73
|
-
|
|
74
|
-
|
|
86
|
+
await user.clear( hoursInput );
|
|
87
|
+
await user.type( hoursInput, '10' );
|
|
88
|
+
await user.keyboard( '{Tab}' );
|
|
75
89
|
|
|
76
90
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T10:00:00' );
|
|
77
91
|
} );
|
|
78
92
|
|
|
79
|
-
it( 'should
|
|
93
|
+
it( 'should call onChange with a bounded hour (12-hour clock) if the hour is out of bounds', async () => {
|
|
94
|
+
const user = userEvent.setup( {
|
|
95
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
96
|
+
} );
|
|
97
|
+
|
|
80
98
|
const onChangeSpy = jest.fn();
|
|
81
99
|
|
|
82
100
|
render(
|
|
@@ -89,13 +107,18 @@ describe( 'TimePicker', () => {
|
|
|
89
107
|
|
|
90
108
|
const hoursInput = screen.getByLabelText( 'Hours' );
|
|
91
109
|
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
await user.clear( hoursInput );
|
|
111
|
+
await user.type( hoursInput, '22' );
|
|
112
|
+
await user.keyboard( '{Tab}' );
|
|
94
113
|
|
|
95
|
-
expect( onChangeSpy ).
|
|
114
|
+
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T00:00:00' );
|
|
96
115
|
} );
|
|
97
116
|
|
|
98
|
-
it( 'should call onChange with an updated hour (24-hour clock)', () => {
|
|
117
|
+
it( 'should call onChange with an updated hour (24-hour clock)', async () => {
|
|
118
|
+
const user = userEvent.setup( {
|
|
119
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
120
|
+
} );
|
|
121
|
+
|
|
99
122
|
const onChangeSpy = jest.fn();
|
|
100
123
|
|
|
101
124
|
render(
|
|
@@ -108,13 +131,18 @@ describe( 'TimePicker', () => {
|
|
|
108
131
|
|
|
109
132
|
const hoursInput = screen.getByLabelText( 'Hours' );
|
|
110
133
|
|
|
111
|
-
|
|
112
|
-
|
|
134
|
+
await user.clear( hoursInput );
|
|
135
|
+
await user.type( hoursInput, '22' );
|
|
136
|
+
await user.keyboard( '{Tab}' );
|
|
113
137
|
|
|
114
138
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T22:00:00' );
|
|
115
139
|
} );
|
|
116
140
|
|
|
117
|
-
it( 'should
|
|
141
|
+
it( 'should call onChange with a bounded minute if out of bounds', async () => {
|
|
142
|
+
const user = userEvent.setup( {
|
|
143
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
144
|
+
} );
|
|
145
|
+
|
|
118
146
|
const onChangeSpy = jest.fn();
|
|
119
147
|
|
|
120
148
|
render(
|
|
@@ -127,13 +155,18 @@ describe( 'TimePicker', () => {
|
|
|
127
155
|
|
|
128
156
|
const minutesInput = screen.getByLabelText( 'Minutes' );
|
|
129
157
|
|
|
130
|
-
|
|
131
|
-
|
|
158
|
+
await user.clear( minutesInput );
|
|
159
|
+
await user.type( minutesInput, '99' );
|
|
160
|
+
await user.keyboard( '{Tab}' );
|
|
132
161
|
|
|
133
|
-
expect( onChangeSpy ).
|
|
162
|
+
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T11:59:00' );
|
|
134
163
|
} );
|
|
135
164
|
|
|
136
|
-
it( 'should switch to PM correctly', () => {
|
|
165
|
+
it( 'should switch to PM correctly', async () => {
|
|
166
|
+
const user = userEvent.setup( {
|
|
167
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
168
|
+
} );
|
|
169
|
+
|
|
137
170
|
const onChangeSpy = jest.fn();
|
|
138
171
|
|
|
139
172
|
render(
|
|
@@ -146,12 +179,16 @@ describe( 'TimePicker', () => {
|
|
|
146
179
|
|
|
147
180
|
const pmButton = screen.getByText( 'PM' );
|
|
148
181
|
|
|
149
|
-
|
|
182
|
+
await user.click( pmButton );
|
|
150
183
|
|
|
151
184
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T23:00:00' );
|
|
152
185
|
} );
|
|
153
186
|
|
|
154
|
-
it( 'should switch to AM correctly', () => {
|
|
187
|
+
it( 'should switch to AM correctly', async () => {
|
|
188
|
+
const user = userEvent.setup( {
|
|
189
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
190
|
+
} );
|
|
191
|
+
|
|
155
192
|
const onChangeSpy = jest.fn();
|
|
156
193
|
|
|
157
194
|
render(
|
|
@@ -164,12 +201,16 @@ describe( 'TimePicker', () => {
|
|
|
164
201
|
|
|
165
202
|
const amButton = screen.getByText( 'AM' );
|
|
166
203
|
|
|
167
|
-
|
|
204
|
+
await user.click( amButton );
|
|
168
205
|
|
|
169
206
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T11:00:00' );
|
|
170
207
|
} );
|
|
171
208
|
|
|
172
|
-
it( 'should allow to set the time correctly when the PM period is selected', () => {
|
|
209
|
+
it( 'should allow to set the time correctly when the PM period is selected', async () => {
|
|
210
|
+
const user = userEvent.setup( {
|
|
211
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
212
|
+
} );
|
|
213
|
+
|
|
173
214
|
const onChangeSpy = jest.fn();
|
|
174
215
|
|
|
175
216
|
render(
|
|
@@ -181,11 +222,12 @@ describe( 'TimePicker', () => {
|
|
|
181
222
|
);
|
|
182
223
|
|
|
183
224
|
const pmButton = screen.getByText( 'PM' );
|
|
184
|
-
|
|
225
|
+
await user.click( pmButton );
|
|
185
226
|
|
|
186
227
|
const hoursInput = screen.getByLabelText( 'Hours' );
|
|
187
|
-
|
|
188
|
-
|
|
228
|
+
await user.clear( hoursInput );
|
|
229
|
+
await user.type( hoursInput, '6' );
|
|
230
|
+
await user.keyboard( '{Tab}' );
|
|
189
231
|
|
|
190
232
|
// When clicking on 'PM', we expect the time to be 11pm
|
|
191
233
|
expect( onChangeSpy ).toHaveBeenNthCalledWith(
|
|
@@ -199,7 +241,11 @@ describe( 'TimePicker', () => {
|
|
|
199
241
|
);
|
|
200
242
|
} );
|
|
201
243
|
|
|
202
|
-
it( 'should truncate at the minutes on change', () => {
|
|
244
|
+
it( 'should truncate at the minutes on change', async () => {
|
|
245
|
+
const user = userEvent.setup( {
|
|
246
|
+
advanceTimers: jest.advanceTimersByTime,
|
|
247
|
+
} );
|
|
248
|
+
|
|
203
249
|
const onChangeSpy = jest.fn();
|
|
204
250
|
|
|
205
251
|
render(
|
|
@@ -212,8 +258,9 @@ describe( 'TimePicker', () => {
|
|
|
212
258
|
|
|
213
259
|
const minutesInput = screen.getByLabelText( 'Minutes' );
|
|
214
260
|
|
|
215
|
-
|
|
216
|
-
|
|
261
|
+
await user.clear( minutesInput );
|
|
262
|
+
await user.type( minutesInput, '22' );
|
|
263
|
+
await user.keyboard( '{Tab}' );
|
|
217
264
|
|
|
218
265
|
expect( onChangeSpy ).toHaveBeenCalledWith( '1986-10-18T23:22:00' );
|
|
219
266
|
} );
|
|
@@ -7,7 +7,8 @@ import { __experimentalGetSettings as getDateSettings } from '@wordpress/date';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import Tooltip from '
|
|
10
|
+
import Tooltip from '../../tooltip';
|
|
11
|
+
import { TimeZone as StyledComponent } from './styles';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Displays timezone information when user timezone is different from site
|
|
@@ -38,7 +39,9 @@ const TimeZone = () => {
|
|
|
38
39
|
|
|
39
40
|
return (
|
|
40
41
|
<Tooltip position="top center" text={ timezoneDetail }>
|
|
41
|
-
<
|
|
42
|
+
<StyledComponent className="components-datetime__timezone">
|
|
43
|
+
{ zoneAbbr }
|
|
44
|
+
</StyledComponent>
|
|
42
45
|
</Tooltip>
|
|
43
46
|
);
|
|
44
47
|
};
|
package/src/date-time/types.ts
CHANGED
|
@@ -2,24 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import type { Moment } from 'moment';
|
|
5
|
-
import type { ReactNode } from 'react';
|
|
6
|
-
|
|
7
|
-
export type UpdateOnBlurAsIntegerFieldProps = {
|
|
8
|
-
/**
|
|
9
|
-
* The value of the integer field.
|
|
10
|
-
*/
|
|
11
|
-
value: number | string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Called when the field is changed.
|
|
15
|
-
*/
|
|
16
|
-
onUpdate: ( value: number ) => void;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Children to render inside the field.
|
|
20
|
-
*/
|
|
21
|
-
children?: ReactNode;
|
|
22
|
-
};
|
|
23
5
|
|
|
24
6
|
export type TimePickerProps = {
|
|
25
7
|
/**
|
|
@@ -103,4 +85,20 @@ export type DateTimePickerProps = Omit< DatePickerProps, 'onChange' > &
|
|
|
103
85
|
* passed the date and time as an argument.
|
|
104
86
|
*/
|
|
105
87
|
onChange?: ( date: string | null ) => void;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Start opting in to not displaying a Help button which will become the
|
|
91
|
+
* default in a future version.
|
|
92
|
+
*
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
__nextRemoveHelpButton?: boolean;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Start opting in to not displaying a Reset button which will become
|
|
99
|
+
* the default in a future version.
|
|
100
|
+
*
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
__nextRemoveResetButton?: boolean;
|
|
106
104
|
};
|
|
@@ -34,10 +34,17 @@ const { Provider } = Context;
|
|
|
34
34
|
* @param {Function} [props.onDragEnd] Callback when dragging ends.
|
|
35
35
|
* @param {Function} [props.onDragOver] Callback when dragging happens over an element.
|
|
36
36
|
* @param {Function} [props.onDragStart] Callback when dragging starts.
|
|
37
|
+
* @param {string} [props.testID] Id used for querying the pan gesture in tests.
|
|
37
38
|
*
|
|
38
39
|
* @return {JSX.Element} The component to be rendered.
|
|
39
40
|
*/
|
|
40
|
-
const Draggable = ( {
|
|
41
|
+
const Draggable = ( {
|
|
42
|
+
children,
|
|
43
|
+
onDragEnd,
|
|
44
|
+
onDragOver,
|
|
45
|
+
onDragStart,
|
|
46
|
+
testID,
|
|
47
|
+
} ) => {
|
|
41
48
|
const isDragging = useSharedValue( false );
|
|
42
49
|
const isPanActive = useSharedValue( false );
|
|
43
50
|
const draggingId = useSharedValue( '' );
|
|
@@ -130,7 +137,8 @@ const Draggable = ( { children, onDragEnd, onDragOver, onDragStart } ) => {
|
|
|
130
137
|
isDragging.value = false;
|
|
131
138
|
} )
|
|
132
139
|
.withRef( panGestureRef )
|
|
133
|
-
.shouldCancelWhenOutside( false )
|
|
140
|
+
.shouldCancelWhenOutside( false )
|
|
141
|
+
.withTestId( testID );
|
|
134
142
|
|
|
135
143
|
const providerValue = useMemo( () => {
|
|
136
144
|
return { panGestureRef, isDragging, isPanActive, draggingId };
|
|
@@ -158,6 +166,7 @@ const Draggable = ( { children, onDragEnd, onDragOver, onDragStart } ) => {
|
|
|
158
166
|
* @param {number} [props.minDuration] Minimum time, that a finger must remain pressed on the corresponding view.
|
|
159
167
|
* @param {Function} [props.onLongPress] Callback when long-press gesture is triggered over an element.
|
|
160
168
|
* @param {Function} [props.onLongPressEnd] Callback when long-press gesture ends.
|
|
169
|
+
* @param {string} [props.testID] Id used for querying the long-press gesture handler in tests.
|
|
161
170
|
*
|
|
162
171
|
* @return {JSX.Element} The component to be rendered.
|
|
163
172
|
*/
|
|
@@ -169,6 +178,7 @@ const DraggableTrigger = ( {
|
|
|
169
178
|
minDuration = 500,
|
|
170
179
|
onLongPress,
|
|
171
180
|
onLongPressEnd,
|
|
181
|
+
testID,
|
|
172
182
|
} ) => {
|
|
173
183
|
const { panGestureRef, isDragging, isPanActive, draggingId } = useContext(
|
|
174
184
|
Context
|
|
@@ -180,8 +190,8 @@ const DraggableTrigger = ( {
|
|
|
180
190
|
return;
|
|
181
191
|
}
|
|
182
192
|
|
|
183
|
-
isDragging.value = true;
|
|
184
193
|
draggingId.value = id;
|
|
194
|
+
isDragging.value = true;
|
|
185
195
|
if ( onLongPress ) {
|
|
186
196
|
runOnJS( onLongPress )( id );
|
|
187
197
|
}
|
|
@@ -205,6 +215,7 @@ const DraggableTrigger = ( {
|
|
|
205
215
|
simultaneousHandlers={ panGestureRef }
|
|
206
216
|
shouldCancelWhenOutside={ false }
|
|
207
217
|
onGestureEvent={ gestureHandler }
|
|
218
|
+
testID={ testID }
|
|
208
219
|
>
|
|
209
220
|
{ children }
|
|
210
221
|
</LongPressGestureHandler>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { render } from 'test/helpers';
|
|
5
|
+
import {
|
|
6
|
+
fireGestureHandler,
|
|
7
|
+
getByGestureTestId,
|
|
8
|
+
} from 'react-native-gesture-handler/jest-utils';
|
|
9
|
+
import { State } from 'react-native-gesture-handler';
|
|
10
|
+
import Animated from 'react-native-reanimated';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* WordPress dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { Draggable, DraggableTrigger } from '@wordpress/components';
|
|
16
|
+
|
|
17
|
+
// Touch event type constants have been extracted from original source code, as they are not exported in the package.
|
|
18
|
+
// Reference: https://github.com/software-mansion/react-native-gesture-handler/blob/90895e5f38616a6be256fceec6c6a391cd9ad7c7/src/TouchEventType.ts
|
|
19
|
+
const TouchEventType = {
|
|
20
|
+
UNDETERMINED: 0,
|
|
21
|
+
TOUCHES_DOWN: 1,
|
|
22
|
+
TOUCHES_MOVE: 2,
|
|
23
|
+
TOUCHES_UP: 3,
|
|
24
|
+
TOUCHES_CANCELLED: 4,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Reanimated uses "requestAnimationFrame" for notifying shared value updates when using "useAnimatedReaction" hook.
|
|
28
|
+
// For testing, we mock the "requestAnimationFrame" so it calls the callback passed instantly.
|
|
29
|
+
let requestAnimationFrameCopy;
|
|
30
|
+
beforeEach( () => {
|
|
31
|
+
requestAnimationFrameCopy = global.requestAnimationFrame;
|
|
32
|
+
global.requestAnimationFrame = ( callback ) => callback();
|
|
33
|
+
} );
|
|
34
|
+
afterEach( () => {
|
|
35
|
+
global.requestAnimationFrame = requestAnimationFrameCopy;
|
|
36
|
+
} );
|
|
37
|
+
|
|
38
|
+
describe( 'Draggable', () => {
|
|
39
|
+
it( 'triggers onLongPress handler', () => {
|
|
40
|
+
const triggerId = 'trigger-id';
|
|
41
|
+
const onLongPress = jest.fn();
|
|
42
|
+
const { getByTestId } = render(
|
|
43
|
+
<Draggable>
|
|
44
|
+
<DraggableTrigger
|
|
45
|
+
id={ triggerId }
|
|
46
|
+
enabled={ true }
|
|
47
|
+
minDuration={ 500 }
|
|
48
|
+
onLongPress={ onLongPress }
|
|
49
|
+
testID="draggableTrigger"
|
|
50
|
+
>
|
|
51
|
+
<Animated.View />
|
|
52
|
+
</DraggableTrigger>
|
|
53
|
+
</Draggable>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const draggableTrigger = getByTestId( 'draggableTrigger' );
|
|
57
|
+
fireGestureHandler( draggableTrigger, [
|
|
58
|
+
{ oldState: State.BEGAN, state: State.ACTIVE },
|
|
59
|
+
{ state: State.ACTIVE },
|
|
60
|
+
] );
|
|
61
|
+
|
|
62
|
+
expect( onLongPress ).toBeCalledTimes( 1 );
|
|
63
|
+
expect( onLongPress ).toHaveBeenCalledWith( triggerId );
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
it( 'triggers dragging handlers', () => {
|
|
67
|
+
const triggerId = 'trigger-id';
|
|
68
|
+
const onDragStart = jest.fn();
|
|
69
|
+
const onDragOver = jest.fn();
|
|
70
|
+
const onDragEnd = jest.fn();
|
|
71
|
+
const { getByTestId } = render(
|
|
72
|
+
<Draggable
|
|
73
|
+
onDragStart={ onDragStart }
|
|
74
|
+
onDragOver={ onDragOver }
|
|
75
|
+
onDragEnd={ onDragEnd }
|
|
76
|
+
testID="draggable"
|
|
77
|
+
>
|
|
78
|
+
<DraggableTrigger id={ triggerId } testID="draggableTrigger">
|
|
79
|
+
<Animated.View />
|
|
80
|
+
</DraggableTrigger>
|
|
81
|
+
</Draggable>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const draggableTrigger = getByTestId( 'draggableTrigger' );
|
|
85
|
+
const draggable = getByGestureTestId( 'draggable' );
|
|
86
|
+
const touchEventId = 1;
|
|
87
|
+
const touchEvents = [
|
|
88
|
+
{ id: touchEventId, x: 0, y: 0 },
|
|
89
|
+
{ id: touchEventId, x: 100, y: 100 },
|
|
90
|
+
{ id: touchEventId, x: 50, y: 50 },
|
|
91
|
+
];
|
|
92
|
+
fireGestureHandler( draggableTrigger, [
|
|
93
|
+
{ oldState: State.BEGAN, state: State.ACTIVE },
|
|
94
|
+
{ state: State.ACTIVE },
|
|
95
|
+
] );
|
|
96
|
+
fireGestureHandler( draggable, [
|
|
97
|
+
// TOUCHES_DOWN event is only received on ACTIVE state, so we have to fire it manually.
|
|
98
|
+
{ oldState: State.BEGAN, state: State.ACTIVE },
|
|
99
|
+
{
|
|
100
|
+
allTouches: [ touchEvents[ 0 ] ],
|
|
101
|
+
eventType: TouchEventType.TOUCHES_DOWN,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
allTouches: [ touchEvents[ 1 ] ],
|
|
105
|
+
eventType: TouchEventType.TOUCHES_MOVE,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
allTouches: [ touchEvents[ 2 ] ],
|
|
109
|
+
eventType: TouchEventType.TOUCHES_MOVE,
|
|
110
|
+
},
|
|
111
|
+
{ state: State.END },
|
|
112
|
+
] );
|
|
113
|
+
|
|
114
|
+
expect( onDragStart ).toBeCalledTimes( 1 );
|
|
115
|
+
expect( onDragStart ).toHaveBeenCalledWith( {
|
|
116
|
+
id: triggerId,
|
|
117
|
+
x: touchEvents[ 0 ].x,
|
|
118
|
+
y: touchEvents[ 0 ].y,
|
|
119
|
+
} );
|
|
120
|
+
expect( onDragOver ).toBeCalledTimes( 2 );
|
|
121
|
+
expect( onDragOver ).toHaveBeenNthCalledWith( 1, touchEvents[ 1 ] );
|
|
122
|
+
expect( onDragOver ).toHaveBeenNthCalledWith( 2, touchEvents[ 2 ] );
|
|
123
|
+
expect( onDragEnd ).toBeCalledTimes( 1 );
|
|
124
|
+
expect( onDragEnd ).toHaveBeenCalledWith( {
|
|
125
|
+
id: triggerId,
|
|
126
|
+
x: touchEvents[ 2 ].x,
|
|
127
|
+
y: touchEvents[ 2 ].y,
|
|
128
|
+
} );
|
|
129
|
+
} );
|
|
130
|
+
} );
|
package/src/dropdown/index.js
CHANGED
|
@@ -108,7 +108,11 @@ export default function Dropdown( props ) {
|
|
|
108
108
|
// This value is used to ensure that the dropdowns
|
|
109
109
|
// align with the editor header by default.
|
|
110
110
|
offset={ 13 }
|
|
111
|
-
anchorRef={
|
|
111
|
+
anchorRef={
|
|
112
|
+
! hasAnchorRef
|
|
113
|
+
? containerRef?.current?.firstChild // Anchor to the rendered toggle.
|
|
114
|
+
: undefined
|
|
115
|
+
}
|
|
112
116
|
{ ...popoverProps }
|
|
113
117
|
className={ classnames(
|
|
114
118
|
'components-dropdown__content',
|
|
@@ -17,6 +17,7 @@ import { useState, forwardRef } from '@wordpress/element';
|
|
|
17
17
|
import InputBase from './input-base';
|
|
18
18
|
import InputField from './input-field';
|
|
19
19
|
import type { InputControlProps } from './types';
|
|
20
|
+
import { useDraft } from './utils';
|
|
20
21
|
|
|
21
22
|
function useUniqueId( idProp?: string ) {
|
|
22
23
|
const instanceId = useInstanceId( InputControl );
|
|
@@ -52,6 +53,12 @@ export function UnforwardedInputControl(
|
|
|
52
53
|
const id = useUniqueId( idProp );
|
|
53
54
|
const classes = classNames( 'components-input-control', className );
|
|
54
55
|
|
|
56
|
+
const draftHookProps = useDraft( {
|
|
57
|
+
value,
|
|
58
|
+
onBlur: props.onBlur,
|
|
59
|
+
onChange,
|
|
60
|
+
} );
|
|
61
|
+
|
|
55
62
|
return (
|
|
56
63
|
<InputBase
|
|
57
64
|
__unstableInputWidth={ __unstableInputWidth }
|
|
@@ -75,14 +82,13 @@ export function UnforwardedInputControl(
|
|
|
75
82
|
id={ id }
|
|
76
83
|
isFocused={ isFocused }
|
|
77
84
|
isPressEnterToChange={ isPressEnterToChange }
|
|
78
|
-
onChange={ onChange }
|
|
79
85
|
onKeyDown={ onKeyDown }
|
|
80
86
|
onValidate={ onValidate }
|
|
81
87
|
ref={ ref }
|
|
82
88
|
setIsFocused={ setIsFocused }
|
|
83
89
|
size={ size }
|
|
84
90
|
stateReducer={ stateReducer }
|
|
85
|
-
|
|
91
|
+
{ ...draftHookProps }
|
|
86
92
|
/>
|
|
87
93
|
</InputBase>
|
|
88
94
|
);
|
|
@@ -24,7 +24,6 @@ import type { WordPressComponentProps } from '../ui/context';
|
|
|
24
24
|
import { useDragCursor } from './utils';
|
|
25
25
|
import { Input } from './styles/input-control-styles';
|
|
26
26
|
import { useInputControlStateReducer } from './reducer/reducer';
|
|
27
|
-
import { useUpdateEffect } from '../utils';
|
|
28
27
|
import type { InputFieldProps } from './types';
|
|
29
28
|
|
|
30
29
|
function InputField(
|
|
@@ -67,40 +66,21 @@ function InputField(
|
|
|
67
66
|
pressEnter,
|
|
68
67
|
pressUp,
|
|
69
68
|
reset,
|
|
70
|
-
} = useInputControlStateReducer(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
} = useInputControlStateReducer(
|
|
70
|
+
stateReducer,
|
|
71
|
+
{
|
|
72
|
+
isDragEnabled,
|
|
73
|
+
value: valueProp,
|
|
74
|
+
isPressEnterToChange,
|
|
75
|
+
},
|
|
76
|
+
onChange
|
|
77
|
+
);
|
|
75
78
|
|
|
76
|
-
const {
|
|
79
|
+
const { value, isDragging, isDirty } = state;
|
|
77
80
|
const wasDirtyOnBlur = useRef( false );
|
|
78
81
|
|
|
79
82
|
const dragCursor = useDragCursor( isDragging, dragDirection );
|
|
80
83
|
|
|
81
|
-
/*
|
|
82
|
-
* Handles synchronization of external and internal value state.
|
|
83
|
-
* If not focused and did not hold a dirty value[1] on blur
|
|
84
|
-
* updates the value from the props. Otherwise if not holding
|
|
85
|
-
* a dirty value[1] propagates the value and event through onChange.
|
|
86
|
-
* [1] value is only made dirty if isPressEnterToChange is true
|
|
87
|
-
*/
|
|
88
|
-
useUpdateEffect( () => {
|
|
89
|
-
if ( valueProp === value ) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if ( ! isFocused && ! wasDirtyOnBlur.current ) {
|
|
93
|
-
commit( valueProp, _event as SyntheticEvent );
|
|
94
|
-
} else if ( ! isDirty ) {
|
|
95
|
-
onChange( value, {
|
|
96
|
-
event: _event as
|
|
97
|
-
| ChangeEvent< HTMLInputElement >
|
|
98
|
-
| PointerEvent< HTMLInputElement >,
|
|
99
|
-
} );
|
|
100
|
-
wasDirtyOnBlur.current = false;
|
|
101
|
-
}
|
|
102
|
-
}, [ value, isDirty, isFocused, valueProp ] );
|
|
103
|
-
|
|
104
84
|
const handleOnBlur = ( event: FocusEvent< HTMLInputElement > ) => {
|
|
105
85
|
onBlur( event );
|
|
106
86
|
setIsFocused?.( false );
|