@wordpress/components 32.2.1-next.v.202602191100.0 → 32.2.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 -0
- package/build/alignment-matrix-control/cell.cjs +2 -2
- package/build/alignment-matrix-control/cell.cjs.map +1 -1
- package/build/alignment-matrix-control/index.cjs +2 -2
- package/build/alignment-matrix-control/index.cjs.map +1 -1
- package/build/angle-picker-control/angle-circle.cjs +2 -2
- package/build/angle-picker-control/angle-circle.cjs.map +1 -1
- package/build/autocomplete/index.cjs +15 -7
- package/build/autocomplete/index.cjs.map +2 -2
- package/build/date-time/time/index.cjs +1 -1
- package/build/date-time/time/index.cjs.map +2 -2
- package/build/date-time/utils.cjs +9 -0
- package/build/date-time/utils.cjs.map +2 -2
- package/build/private-apis.cjs +0 -4
- package/build/private-apis.cjs.map +3 -3
- package/build/sandbox/index.cjs +125 -1
- package/build/sandbox/index.cjs.map +2 -2
- package/build/select-control/styles/select-control-styles.cjs +8 -8
- package/build/select-control/styles/select-control-styles.cjs.map +2 -2
- package/build/snackbar/list.cjs +4 -1
- package/build/snackbar/list.cjs.map +2 -2
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs +8 -8
- package/build/toggle-group-control/toggle-group-control-option-base/styles.cjs.map +2 -2
- package/build/validated-form-controls/control-with-error.cjs +26 -3
- package/build/validated-form-controls/control-with-error.cjs.map +2 -2
- package/build/validated-form-controls/validity-indicator.cjs +2 -0
- package/build/validated-form-controls/validity-indicator.cjs.map +2 -2
- package/build-module/alignment-matrix-control/cell.mjs +2 -2
- package/build-module/alignment-matrix-control/cell.mjs.map +1 -1
- package/build-module/alignment-matrix-control/index.mjs +2 -2
- package/build-module/alignment-matrix-control/index.mjs.map +1 -1
- package/build-module/angle-picker-control/angle-circle.mjs +2 -2
- package/build-module/angle-picker-control/angle-circle.mjs.map +1 -1
- package/build-module/autocomplete/index.mjs +13 -6
- package/build-module/autocomplete/index.mjs.map +2 -2
- package/build-module/date-time/time/index.mjs +2 -2
- package/build-module/date-time/time/index.mjs.map +2 -2
- package/build-module/date-time/utils.mjs +8 -0
- package/build-module/date-time/utils.mjs.map +2 -2
- package/build-module/private-apis.mjs +0 -4
- package/build-module/private-apis.mjs.map +2 -2
- package/build-module/sandbox/index.mjs +126 -2
- package/build-module/sandbox/index.mjs.map +2 -2
- package/build-module/select-control/styles/select-control-styles.mjs +8 -8
- package/build-module/select-control/styles/select-control-styles.mjs.map +2 -2
- package/build-module/snackbar/list.mjs +4 -1
- package/build-module/snackbar/list.mjs.map +2 -2
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs +8 -8
- package/build-module/toggle-group-control/toggle-group-control-option-base/styles.mjs.map +2 -2
- package/build-module/validated-form-controls/control-with-error.mjs +27 -4
- package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
- package/build-module/validated-form-controls/validity-indicator.mjs +2 -0
- package/build-module/validated-form-controls/validity-indicator.mjs.map +2 -2
- package/build-style/style-rtl.css +7 -183
- package/build-style/style.css +7 -183
- package/build-types/alignment-matrix-control/styles/alignment-matrix-control-icon-styles.d.ts +19 -0
- package/build-types/alignment-matrix-control/styles/alignment-matrix-control-icon-styles.d.ts.map +1 -0
- package/build-types/alignment-matrix-control/styles/alignment-matrix-control-styles.d.ts +23 -0
- package/build-types/alignment-matrix-control/styles/alignment-matrix-control-styles.d.ts.map +1 -0
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +25 -0
- package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +1 -0
- package/build-types/autocomplete/get-autocomplete-match.d.ts +20 -0
- package/build-types/autocomplete/get-autocomplete-match.d.ts.map +1 -0
- package/build-types/autocomplete/index.d.ts +8 -0
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/autocomplete/test/get-autocomplete-match.d.ts +2 -0
- package/build-types/autocomplete/test/get-autocomplete-match.d.ts.map +1 -0
- package/build-types/badge/stories/e2e/index.story.d.ts +7 -0
- package/build-types/badge/stories/e2e/index.story.d.ts.map +1 -0
- package/build-types/border-control/border-control-style-picker/hook.d.ts +267 -0
- package/build-types/border-control/border-control-style-picker/hook.d.ts.map +1 -0
- package/build-types/box-control/all-input-control.d.ts +4 -0
- package/build-types/box-control/all-input-control.d.ts.map +1 -0
- package/build-types/box-control/axial-input-controls.d.ts +4 -0
- package/build-types/box-control/axial-input-controls.d.ts.map +1 -0
- package/build-types/box-control/input-controls.d.ts +4 -0
- package/build-types/box-control/input-controls.d.ts.map +1 -0
- package/build-types/box-control/styles/box-control-visualizer-styles.d.ts +46 -0
- package/build-types/box-control/styles/box-control-visualizer-styles.d.ts.map +1 -0
- package/build-types/box-control/unit-control.d.ts +4 -0
- package/build-types/box-control/unit-control.d.ts.map +1 -0
- package/build-types/custom-gradient-picker/test/index.d.ts +2 -0
- package/build-types/custom-gradient-picker/test/index.d.ts.map +1 -0
- package/build-types/custom-select-control/styles.d.ts +11 -0
- package/build-types/custom-select-control/styles.d.ts.map +1 -0
- package/build-types/date-time/date-picker/index.d.ts +23 -0
- package/build-types/date-time/date-picker/index.d.ts.map +1 -0
- package/build-types/date-time/date-picker/styles.d.ts +45 -0
- package/build-types/date-time/date-picker/styles.d.ts.map +1 -0
- package/build-types/date-time/date-picker/test/index.d.ts +2 -0
- package/build-types/date-time/date-picker/test/index.d.ts.map +1 -0
- package/build-types/date-time/date-picker/test/use-lilius.d.ts +2 -0
- package/build-types/date-time/date-picker/test/use-lilius.d.ts.map +1 -0
- package/build-types/date-time/date-picker/use-lilius/index.d.ts +169 -0
- package/build-types/date-time/date-picker/use-lilius/index.d.ts.map +1 -0
- package/build-types/date-time/time/index.d.ts.map +1 -1
- package/build-types/date-time/time-picker/index.d.ts +27 -0
- package/build-types/date-time/time-picker/index.d.ts.map +1 -0
- package/build-types/date-time/time-picker/styles.d.ts +93 -0
- package/build-types/date-time/time-picker/styles.d.ts.map +1 -0
- package/build-types/date-time/time-picker/test/index.d.ts +2 -0
- package/build-types/date-time/time-picker/test/index.d.ts.map +1 -0
- package/build-types/date-time/time-picker/time-input/index.d.ts +4 -0
- package/build-types/date-time/time-picker/time-input/index.d.ts.map +1 -0
- package/build-types/date-time/time-picker/time-input/test/index.d.ts +2 -0
- package/build-types/date-time/time-picker/time-input/test/index.d.ts.map +1 -0
- package/build-types/date-time/time-picker/timezone.d.ts +7 -0
- package/build-types/date-time/time-picker/timezone.d.ts.map +1 -0
- package/build-types/date-time/utils.d.ts +9 -0
- package/build-types/date-time/utils.d.ts.map +1 -1
- package/build-types/dimension-control/index.d.ts +28 -0
- package/build-types/dimension-control/index.d.ts.map +1 -0
- package/build-types/dimension-control/sizes.d.ts +26 -0
- package/build-types/dimension-control/sizes.d.ts.map +1 -0
- package/build-types/dimension-control/stories/index.story.d.ts +4 -0
- package/build-types/dimension-control/stories/index.story.d.ts.map +1 -0
- package/build-types/dimension-control/types.d.ts +47 -0
- package/build-types/dimension-control/types.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/index.d.ts +17 -0
- package/build-types/dropdown-menu-v2/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/stories/index.story.d.ts +11 -0
- package/build-types/dropdown-menu-v2/stories/index.story.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/styles.d.ts +42 -0
- package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/test/index.d.ts +2 -0
- package/build-types/dropdown-menu-v2/test/index.d.ts.map +1 -0
- package/build-types/dropdown-menu-v2/types.d.ts +252 -0
- package/build-types/dropdown-menu-v2/types.d.ts.map +1 -0
- package/build-types/external-link/styles/external-link-styles.d.ts +10 -0
- package/build-types/external-link/styles/external-link-styles.d.ts.map +1 -0
- package/build-types/mobile/inserter-button/sparkles.d.ts +3 -0
- package/build-types/mobile/inserter-button/sparkles.d.ts.map +1 -0
- package/build-types/navigator/navigator-back-button/index.d.ts +2 -0
- package/build-types/navigator/navigator-back-button/index.d.ts.map +1 -0
- package/build-types/navigator/navigator-button/index.d.ts +2 -0
- package/build-types/navigator/navigator-button/index.d.ts.map +1 -0
- package/build-types/navigator/navigator-provider/component.d.ts +38 -0
- package/build-types/navigator/navigator-provider/component.d.ts.map +1 -0
- package/build-types/navigator/navigator-provider/index.d.ts +2 -0
- package/build-types/navigator/navigator-provider/index.d.ts.map +1 -0
- package/build-types/navigator/navigator-screen/index.d.ts +2 -0
- package/build-types/navigator/navigator-screen/index.d.ts.map +1 -0
- package/build-types/navigator/navigator-to-parent-button/index.d.ts +2 -0
- package/build-types/navigator/navigator-to-parent-button/index.d.ts.map +1 -0
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/radio-group/radio/index.d.ts +7 -0
- package/build-types/radio-group/radio/index.d.ts.map +1 -0
- package/build-types/radio-group/radio-context/index.d.ts +6 -0
- package/build-types/radio-group/radio-context/index.d.ts.map +1 -0
- package/build-types/sandbox/index.d.ts +1 -1
- package/build-types/sandbox/index.d.ts.map +1 -1
- package/build-types/sandbox/types.d.ts +11 -0
- package/build-types/sandbox/types.d.ts.map +1 -1
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/fill.d.ts +5 -0
- package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -0
- package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts +12 -0
- package/build-types/slot-fill/bubbles-virtually/slot-fill-context.d.ts.map +1 -0
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts +4 -0
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -0
- package/build-types/slot-fill/use-slot.d.ts +9 -0
- package/build-types/slot-fill/use-slot.d.ts.map +1 -0
- package/build-types/snackbar/list.d.ts.map +1 -1
- package/build-types/style-provider/test/index.d.ts +2 -0
- package/build-types/style-provider/test/index.d.ts.map +1 -0
- package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
- package/build-types/ui/context/constants.d.ts +8 -0
- package/build-types/ui/context/constants.d.ts.map +1 -0
- package/build-types/ui/context/context-connect.d.ts +40 -0
- package/build-types/ui/context/context-connect.d.ts.map +1 -0
- package/build-types/ui/context/context-system-provider.d.ts +7 -0
- package/build-types/ui/context/context-system-provider.d.ts.map +1 -0
- package/build-types/ui/context/get-styled-class-name-from-key.d.ts +2 -0
- package/build-types/ui/context/get-styled-class-name-from-key.d.ts.map +1 -0
- package/build-types/ui/context/index.d.ts +5 -0
- package/build-types/ui/context/index.d.ts.map +1 -0
- package/build-types/ui/context/test/context-connect.d.ts +2 -0
- package/build-types/ui/context/test/context-connect.d.ts.map +1 -0
- package/build-types/ui/context/test/wordpress-component.d.ts +2 -0
- package/build-types/ui/context/test/wordpress-component.d.ts.map +1 -0
- package/build-types/ui/context/use-context-system.d.ts +20 -0
- package/build-types/ui/context/use-context-system.d.ts.map +1 -0
- package/build-types/ui/context/utils.d.ts +26 -0
- package/build-types/ui/context/utils.d.ts.map +1 -0
- package/build-types/ui/context/wordpress-component.d.ts +32 -0
- package/build-types/ui/context/wordpress-component.d.ts.map +1 -0
- package/build-types/ui/shortcut/component.d.ts +12 -0
- package/build-types/ui/shortcut/component.d.ts.map +1 -0
- package/build-types/ui/shortcut/index.d.ts +3 -0
- package/build-types/ui/shortcut/index.d.ts.map +1 -0
- package/build-types/ui/tooltip/component.d.ts +29 -0
- package/build-types/ui/tooltip/component.d.ts.map +1 -0
- package/build-types/ui/tooltip/content.d.ts +9 -0
- package/build-types/ui/tooltip/content.d.ts.map +1 -0
- package/build-types/ui/tooltip/context.d.ts +10 -0
- package/build-types/ui/tooltip/context.d.ts.map +1 -0
- package/build-types/ui/tooltip/index.d.ts +3 -0
- package/build-types/ui/tooltip/index.d.ts.map +1 -0
- package/build-types/ui/tooltip/styles.d.ts +12 -0
- package/build-types/ui/tooltip/styles.d.ts.map +1 -0
- package/build-types/ui/tooltip/types.d.ts +62 -0
- package/build-types/ui/tooltip/types.d.ts.map +1 -0
- package/build-types/ui/utils/colors.d.ts +17 -0
- package/build-types/ui/utils/colors.d.ts.map +1 -0
- package/build-types/ui/utils/font-size.d.ts +18 -0
- package/build-types/ui/utils/font-size.d.ts.map +1 -0
- package/build-types/ui/utils/get-valid-children.d.ts +13 -0
- package/build-types/ui/utils/get-valid-children.d.ts.map +1 -0
- package/build-types/ui/utils/index.d.ts +2 -0
- package/build-types/ui/utils/index.d.ts.map +1 -0
- package/build-types/ui/utils/space.d.ts +23 -0
- package/build-types/ui/utils/space.d.ts.map +1 -0
- package/build-types/ui/utils/types.d.ts +14 -0
- package/build-types/ui/utils/types.d.ts.map +1 -0
- package/build-types/ui/utils/use-responsive-value.d.ts +5 -0
- package/build-types/ui/utils/use-responsive-value.d.ts.map +1 -0
- package/build-types/utils/hooks/use-latest-ref.d.ts +15 -0
- package/build-types/utils/hooks/use-latest-ref.d.ts.map +1 -0
- package/build-types/utils/input/base.d.ts +3 -0
- package/build-types/utils/input/base.d.ts.map +1 -0
- package/build-types/utils/input/index.d.ts +2 -0
- package/build-types/utils/input/index.d.ts.map +1 -0
- package/build-types/utils/input/input-control.d.ts +2 -0
- package/build-types/utils/input/input-control.d.ts.map +1 -0
- package/build-types/utils/reduce-motion.d.ts +8 -0
- package/build-types/utils/reduce-motion.d.ts.map +1 -0
- package/build-types/utils/z-index.d.ts +3 -0
- package/build-types/utils/z-index.d.ts.map +1 -0
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
- package/build-types/validated-form-controls/test/checkbox-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/checkbox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/combobox-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/combobox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/custom-select-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/custom-select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/form-token-field.d.ts +2 -0
- package/build-types/validated-form-controls/test/form-token-field.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/input-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/input-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/number-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/number-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/radio-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/radio-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/range-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/range-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/select-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/text-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/text-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/textarea-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/textarea-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/toggle-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/toggle-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/test/toggle-group-control.d.ts +2 -0
- package/build-types/validated-form-controls/test/toggle-group-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/validity-indicator.d.ts +2 -1
- package/build-types/validated-form-controls/validity-indicator.d.ts.map +1 -1
- package/build-types/view/types.d.ts +8 -0
- package/build-types/view/types.d.ts.map +1 -0
- package/package.json +21 -21
- package/src/autocomplete/index.tsx +30 -6
- package/src/autocomplete/test/index.tsx +110 -1
- package/src/button/style.scss +8 -5
- package/src/date-time/test/utils.test.ts +8 -11
- package/src/date-time/time/index.tsx +2 -12
- package/src/date-time/time/test/index.tsx +69 -0
- package/src/date-time/utils.ts +18 -0
- package/src/form-token-field/style.scss +1 -0
- package/src/private-apis.ts +0 -4
- package/src/sandbox/index.tsx +189 -9
- package/src/sandbox/test/index.tsx +65 -24
- package/src/sandbox/types.ts +11 -0
- package/src/select-control/styles/select-control-styles.ts +1 -0
- package/src/snackbar/list.tsx +6 -1
- package/src/style.scss +0 -2
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +18 -16
- package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +4 -6
- package/src/validated-form-controls/control-with-error.tsx +44 -4
- package/src/validated-form-controls/test/checkbox-control.tsx +49 -0
- package/src/validated-form-controls/test/combobox-control.tsx +61 -0
- package/src/validated-form-controls/test/control-with-error.tsx +182 -1
- package/src/validated-form-controls/test/custom-select-control.tsx +60 -0
- package/src/validated-form-controls/test/form-token-field.tsx +52 -0
- package/src/validated-form-controls/test/input-control.tsx +42 -0
- package/src/validated-form-controls/test/number-control.tsx +44 -0
- package/src/validated-form-controls/test/radio-control.tsx +61 -0
- package/src/validated-form-controls/test/range-control.tsx +73 -0
- package/src/validated-form-controls/test/select-control.tsx +57 -0
- package/src/validated-form-controls/test/text-control.tsx +49 -0
- package/src/validated-form-controls/test/textarea-control.tsx +51 -0
- package/src/validated-form-controls/test/toggle-control.tsx +49 -0
- package/src/validated-form-controls/test/toggle-group-control.tsx +28 -0
- package/src/validated-form-controls/validity-indicator.tsx +3 -0
- package/build/avatar/component.cjs +0 -99
- package/build/avatar/component.cjs.map +0 -7
- package/build/avatar/index.cjs +0 -37
- package/build/avatar/index.cjs.map +0 -7
- package/build/avatar/types.cjs +0 -19
- package/build/avatar/types.cjs.map +0 -7
- package/build/avatar-group/component.cjs +0 -60
- package/build/avatar-group/component.cjs.map +0 -7
- package/build/avatar-group/index.cjs +0 -37
- package/build/avatar-group/index.cjs.map +0 -7
- package/build/avatar-group/types.cjs +0 -19
- package/build/avatar-group/types.cjs.map +0 -7
- package/build-module/avatar/component.mjs +0 -68
- package/build-module/avatar/component.mjs.map +0 -7
- package/build-module/avatar/index.mjs +0 -6
- package/build-module/avatar/index.mjs.map +0 -7
- package/build-module/avatar/types.mjs +0 -1
- package/build-module/avatar/types.mjs.map +0 -7
- package/build-module/avatar-group/component.mjs +0 -29
- package/build-module/avatar-group/component.mjs.map +0 -7
- package/build-module/avatar-group/index.mjs +0 -6
- package/build-module/avatar-group/index.mjs.map +0 -7
- package/build-module/avatar-group/types.mjs +0 -1
- package/build-module/avatar-group/types.mjs.map +0 -7
- package/build-types/avatar/component.d.ts +0 -5
- package/build-types/avatar/component.d.ts.map +0 -1
- package/build-types/avatar/index.d.ts +0 -3
- package/build-types/avatar/index.d.ts.map +0 -1
- package/build-types/avatar/types.d.ts +0 -59
- package/build-types/avatar/types.d.ts.map +0 -1
- package/build-types/avatar-group/component.d.ts +0 -8
- package/build-types/avatar-group/component.d.ts.map +0 -1
- package/build-types/avatar-group/index.d.ts +0 -3
- package/build-types/avatar-group/index.d.ts.map +0 -1
- package/build-types/avatar-group/types.d.ts +0 -14
- package/build-types/avatar-group/types.d.ts.map +0 -1
- package/src/avatar/component.tsx +0 -82
- package/src/avatar/index.ts +0 -2
- package/src/avatar/styles.scss +0 -152
- package/src/avatar/types.ts +0 -59
- package/src/avatar-group/component.tsx +0 -46
- package/src/avatar-group/index.ts +0 -2
- package/src/avatar-group/styles.scss +0 -32
- package/src/avatar-group/types.ts +0 -13
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedComboboxControl } from '../components';
|
|
4
|
+
|
|
5
|
+
// The `help` prop is rendered visually by BaseControl but is not
|
|
6
|
+
// programmatically associated with the combobox input via aria-describedby.
|
|
7
|
+
// This is a pre-existing bug in ComboboxControl, not caused by ControlWithError.
|
|
8
|
+
describe( 'ValidatedComboboxControl', () => {
|
|
9
|
+
const options = [
|
|
10
|
+
{ label: 'Apple', value: 'apple' },
|
|
11
|
+
{ label: 'Banana', value: 'banana' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
15
|
+
it.skip( 'should preserve the help description', () => {
|
|
16
|
+
render(
|
|
17
|
+
<ValidatedComboboxControl
|
|
18
|
+
label="Fruit"
|
|
19
|
+
help="Pick a fruit."
|
|
20
|
+
options={ options }
|
|
21
|
+
onChange={ () => {} }
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(
|
|
26
|
+
screen.getByRole( 'combobox', { name: 'Fruit' } )
|
|
27
|
+
).toHaveAccessibleDescription( 'Pick a fruit.' );
|
|
28
|
+
} );
|
|
29
|
+
|
|
30
|
+
// eslint-disable-next-line jest/no-disabled-tests
|
|
31
|
+
it.skip( 'should append the validation error alongside the help description', async () => {
|
|
32
|
+
const user = userEvent.setup();
|
|
33
|
+
render(
|
|
34
|
+
<form>
|
|
35
|
+
<ValidatedComboboxControl
|
|
36
|
+
label="Fruit"
|
|
37
|
+
help="Pick a fruit."
|
|
38
|
+
options={ options }
|
|
39
|
+
onChange={ () => {} }
|
|
40
|
+
required
|
|
41
|
+
/>
|
|
42
|
+
<button type="submit">Submit</button>
|
|
43
|
+
</form>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const combobox = screen.getByRole( 'combobox', {
|
|
47
|
+
name: /^Fruit/,
|
|
48
|
+
} );
|
|
49
|
+
|
|
50
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
51
|
+
|
|
52
|
+
await waitFor( () => {
|
|
53
|
+
expect( combobox ).toHaveAccessibleDescription(
|
|
54
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
55
|
+
);
|
|
56
|
+
} );
|
|
57
|
+
expect( combobox ).toHaveAccessibleDescription(
|
|
58
|
+
expect.stringContaining( 'Pick a fruit.' )
|
|
59
|
+
);
|
|
60
|
+
} );
|
|
61
|
+
} );
|
|
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
import { useState, useCallback, useRef } from '@wordpress/element';
|
|
10
|
+
import { useState, useCallback, useId, useRef } from '@wordpress/element';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
@@ -283,6 +283,187 @@ describe( 'ControlWithError', () => {
|
|
|
283
283
|
} );
|
|
284
284
|
} );
|
|
285
285
|
|
|
286
|
+
describe( 'aria-describedby', () => {
|
|
287
|
+
it( 'should connect the error message to the input via aria-describedby', async () => {
|
|
288
|
+
const user = userEvent.setup();
|
|
289
|
+
render(
|
|
290
|
+
<form>
|
|
291
|
+
<ValidatedInputControl label="URL" required />
|
|
292
|
+
<button type="submit">Submit</button>
|
|
293
|
+
</form>
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const input = screen.getByRole( 'textbox', { name: /^URL/ } );
|
|
297
|
+
|
|
298
|
+
expect( input ).not.toHaveAttribute( 'aria-describedby' );
|
|
299
|
+
|
|
300
|
+
await user.click(
|
|
301
|
+
screen.getByRole( 'button', { name: 'Submit' } )
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
await waitFor( () => {
|
|
305
|
+
expect( input ).toHaveAccessibleDescription(
|
|
306
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
307
|
+
);
|
|
308
|
+
} );
|
|
309
|
+
} );
|
|
310
|
+
|
|
311
|
+
it( 'should preserve existing aria-describedby values', async () => {
|
|
312
|
+
const user = userEvent.setup();
|
|
313
|
+
|
|
314
|
+
function TestComponent() {
|
|
315
|
+
const hintId = useId();
|
|
316
|
+
return (
|
|
317
|
+
<form>
|
|
318
|
+
<ValidatedInputControl
|
|
319
|
+
label="URL"
|
|
320
|
+
required
|
|
321
|
+
aria-describedby={ hintId }
|
|
322
|
+
/>
|
|
323
|
+
<p id={ hintId }>Enter a full URL.</p>
|
|
324
|
+
<button type="submit">Submit</button>
|
|
325
|
+
</form>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
render( <TestComponent /> );
|
|
330
|
+
|
|
331
|
+
const input = screen.getByRole( 'textbox', { name: /^URL/ } );
|
|
332
|
+
|
|
333
|
+
expect( input ).toHaveAccessibleDescription( 'Enter a full URL.' );
|
|
334
|
+
|
|
335
|
+
await user.click(
|
|
336
|
+
screen.getByRole( 'button', { name: 'Submit' } )
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
await waitFor( () => {
|
|
340
|
+
expect( input ).toHaveAccessibleDescription(
|
|
341
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
342
|
+
);
|
|
343
|
+
} );
|
|
344
|
+
expect( input ).toHaveAccessibleDescription(
|
|
345
|
+
expect.stringContaining( 'Enter a full URL.' )
|
|
346
|
+
);
|
|
347
|
+
} );
|
|
348
|
+
|
|
349
|
+
it( 'should connect a custom validity error to the input via aria-describedby', async () => {
|
|
350
|
+
const user = userEvent.setup();
|
|
351
|
+
|
|
352
|
+
function TestComponent() {
|
|
353
|
+
const [ customValidity, setCustomValidity ] =
|
|
354
|
+
useState<
|
|
355
|
+
React.ComponentProps<
|
|
356
|
+
typeof ValidatedInputControl
|
|
357
|
+
>[ 'customValidity' ]
|
|
358
|
+
>( undefined );
|
|
359
|
+
const inputRef = useRef< HTMLInputElement >( null );
|
|
360
|
+
|
|
361
|
+
return (
|
|
362
|
+
<>
|
|
363
|
+
<ValidatedInputControl
|
|
364
|
+
ref={ inputRef }
|
|
365
|
+
label="URL"
|
|
366
|
+
customValidity={ customValidity }
|
|
367
|
+
/>
|
|
368
|
+
<button
|
|
369
|
+
type="button"
|
|
370
|
+
onClick={ () => {
|
|
371
|
+
setCustomValidity( {
|
|
372
|
+
type: 'invalid',
|
|
373
|
+
message: 'Please enter a valid URL.',
|
|
374
|
+
} );
|
|
375
|
+
requestAnimationFrame(
|
|
376
|
+
() => inputRef.current?.reportValidity()
|
|
377
|
+
);
|
|
378
|
+
} }
|
|
379
|
+
>
|
|
380
|
+
Validate
|
|
381
|
+
</button>
|
|
382
|
+
</>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
render( <TestComponent /> );
|
|
387
|
+
|
|
388
|
+
const input = screen.getByRole( 'textbox', { name: 'URL' } );
|
|
389
|
+
expect( input ).not.toHaveAttribute( 'aria-describedby' );
|
|
390
|
+
|
|
391
|
+
await user.click(
|
|
392
|
+
screen.getByRole( 'button', { name: 'Validate' } )
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
await waitFor( () => {
|
|
396
|
+
expect( input ).toHaveAccessibleDescription(
|
|
397
|
+
expect.stringContaining( 'Please enter a valid URL.' )
|
|
398
|
+
);
|
|
399
|
+
} );
|
|
400
|
+
} );
|
|
401
|
+
|
|
402
|
+
it( 'should remove aria-describedby when the error is resolved', async () => {
|
|
403
|
+
const user = userEvent.setup();
|
|
404
|
+
|
|
405
|
+
function TestComponent() {
|
|
406
|
+
const [ customValidity, setCustomValidity ] =
|
|
407
|
+
useState<
|
|
408
|
+
React.ComponentProps<
|
|
409
|
+
typeof ValidatedInputControl
|
|
410
|
+
>[ 'customValidity' ]
|
|
411
|
+
>( undefined );
|
|
412
|
+
const inputRef = useRef< HTMLInputElement >( null );
|
|
413
|
+
|
|
414
|
+
return (
|
|
415
|
+
<>
|
|
416
|
+
<ValidatedInputControl
|
|
417
|
+
ref={ inputRef }
|
|
418
|
+
label="URL"
|
|
419
|
+
customValidity={ customValidity }
|
|
420
|
+
/>
|
|
421
|
+
<button
|
|
422
|
+
type="button"
|
|
423
|
+
onClick={ () => {
|
|
424
|
+
setCustomValidity( {
|
|
425
|
+
type: 'invalid',
|
|
426
|
+
message: 'Please enter a valid URL.',
|
|
427
|
+
} );
|
|
428
|
+
requestAnimationFrame(
|
|
429
|
+
() => inputRef.current?.reportValidity()
|
|
430
|
+
);
|
|
431
|
+
} }
|
|
432
|
+
>
|
|
433
|
+
Validate
|
|
434
|
+
</button>
|
|
435
|
+
<button
|
|
436
|
+
type="button"
|
|
437
|
+
onClick={ () => setCustomValidity( undefined ) }
|
|
438
|
+
>
|
|
439
|
+
Clear
|
|
440
|
+
</button>
|
|
441
|
+
</>
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
render( <TestComponent /> );
|
|
446
|
+
|
|
447
|
+
const input = screen.getByRole( 'textbox', { name: 'URL' } );
|
|
448
|
+
|
|
449
|
+
await user.click(
|
|
450
|
+
screen.getByRole( 'button', { name: 'Validate' } )
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
await waitFor( () => {
|
|
454
|
+
expect( input ).toHaveAccessibleDescription(
|
|
455
|
+
expect.stringContaining( 'Please enter a valid URL.' )
|
|
456
|
+
);
|
|
457
|
+
} );
|
|
458
|
+
|
|
459
|
+
await user.click( screen.getByRole( 'button', { name: 'Clear' } ) );
|
|
460
|
+
|
|
461
|
+
await waitFor( () => {
|
|
462
|
+
expect( input ).not.toHaveAttribute( 'aria-describedby' );
|
|
463
|
+
} );
|
|
464
|
+
} );
|
|
465
|
+
} );
|
|
466
|
+
|
|
286
467
|
describe( 'Focus behavior', () => {
|
|
287
468
|
it( 'should focus the first error in the form', async () => {
|
|
288
469
|
const user = userEvent.setup();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedCustomSelectControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedCustomSelectControl', () => {
|
|
6
|
+
const options = [
|
|
7
|
+
{ key: 'small', name: 'Small' },
|
|
8
|
+
{ key: 'large', name: 'Large' },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
it( 'should preserve the built-in "Currently selected" description', async () => {
|
|
12
|
+
render(
|
|
13
|
+
<ValidatedCustomSelectControl
|
|
14
|
+
label="Font Size"
|
|
15
|
+
options={ options }
|
|
16
|
+
value={ options[ 0 ] }
|
|
17
|
+
onChange={ () => {} }
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
await waitFor( () => {
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByRole( 'combobox', { name: 'Font Size' } )
|
|
24
|
+
).toHaveAccessibleDescription( 'Currently selected: Small' );
|
|
25
|
+
} );
|
|
26
|
+
} );
|
|
27
|
+
|
|
28
|
+
it( 'should preserve the built-in description when validation is active', async () => {
|
|
29
|
+
const user = userEvent.setup();
|
|
30
|
+
render(
|
|
31
|
+
<form onSubmit={ ( e ) => e.preventDefault() }>
|
|
32
|
+
<ValidatedCustomSelectControl
|
|
33
|
+
label="Font Size"
|
|
34
|
+
options={ options }
|
|
35
|
+
value={ options[ 0 ] }
|
|
36
|
+
onChange={ () => {} }
|
|
37
|
+
required
|
|
38
|
+
/>
|
|
39
|
+
<button type="submit">Submit</button>
|
|
40
|
+
</form>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const combobox = await waitFor( () => {
|
|
44
|
+
return screen.getByRole( 'combobox', {
|
|
45
|
+
name: /^Font Size/,
|
|
46
|
+
} );
|
|
47
|
+
} );
|
|
48
|
+
|
|
49
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
50
|
+
|
|
51
|
+
// The validation error targets the hidden delegate <select>, not
|
|
52
|
+
// the interactive combobox. The combobox's built-in description
|
|
53
|
+
// should be unaffected.
|
|
54
|
+
await waitFor( () => {
|
|
55
|
+
expect( combobox ).toHaveAccessibleDescription(
|
|
56
|
+
'Currently selected: Small'
|
|
57
|
+
);
|
|
58
|
+
} );
|
|
59
|
+
} );
|
|
60
|
+
} );
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedFormTokenField } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedFormTokenField', () => {
|
|
6
|
+
it( 'should preserve the built-in howto description', () => {
|
|
7
|
+
render(
|
|
8
|
+
<ValidatedFormTokenField
|
|
9
|
+
label="Tags"
|
|
10
|
+
value={ [] }
|
|
11
|
+
onChange={ () => {} }
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(
|
|
16
|
+
screen.getByRole( 'combobox', { name: 'Tags' } )
|
|
17
|
+
).toHaveAccessibleDescription(
|
|
18
|
+
expect.stringContaining( 'Separate with commas or the Enter key.' )
|
|
19
|
+
);
|
|
20
|
+
} );
|
|
21
|
+
|
|
22
|
+
it( 'should preserve the built-in howto description when validation is active', async () => {
|
|
23
|
+
const user = userEvent.setup();
|
|
24
|
+
render(
|
|
25
|
+
<form>
|
|
26
|
+
<ValidatedFormTokenField
|
|
27
|
+
label="Tags"
|
|
28
|
+
value={ [] }
|
|
29
|
+
onChange={ () => {} }
|
|
30
|
+
required
|
|
31
|
+
/>
|
|
32
|
+
<button type="submit">Submit</button>
|
|
33
|
+
</form>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const input = screen.getByRole( 'combobox', { name: /^Tags/ } );
|
|
37
|
+
|
|
38
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
39
|
+
|
|
40
|
+
// The validation error targets the hidden delegate input, not the
|
|
41
|
+
// interactive combobox. The combobox's built-in description should
|
|
42
|
+
// be unaffected.
|
|
43
|
+
await waitFor( () => {
|
|
44
|
+
expect(
|
|
45
|
+
screen.getByText( 'Constraints not satisfied' )
|
|
46
|
+
).toBeVisible();
|
|
47
|
+
} );
|
|
48
|
+
expect( input ).toHaveAccessibleDescription(
|
|
49
|
+
expect.stringContaining( 'Separate with commas or the Enter key.' )
|
|
50
|
+
);
|
|
51
|
+
} );
|
|
52
|
+
} );
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedInputControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedInputControl', () => {
|
|
6
|
+
it( 'should preserve the help description', () => {
|
|
7
|
+
render(
|
|
8
|
+
<ValidatedInputControl label="URL" help="Enter a full URL." />
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
screen.getByRole( 'textbox', { name: 'URL' } )
|
|
13
|
+
).toHaveAccessibleDescription( 'Enter a full URL.' );
|
|
14
|
+
} );
|
|
15
|
+
|
|
16
|
+
it( 'should append the validation error alongside the help description', async () => {
|
|
17
|
+
const user = userEvent.setup();
|
|
18
|
+
render(
|
|
19
|
+
<form>
|
|
20
|
+
<ValidatedInputControl
|
|
21
|
+
label="URL"
|
|
22
|
+
help="Enter a full URL."
|
|
23
|
+
required
|
|
24
|
+
/>
|
|
25
|
+
<button type="submit">Submit</button>
|
|
26
|
+
</form>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const input = screen.getByRole( 'textbox', { name: /^URL/ } );
|
|
30
|
+
|
|
31
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
32
|
+
|
|
33
|
+
await waitFor( () => {
|
|
34
|
+
expect( input ).toHaveAccessibleDescription(
|
|
35
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
36
|
+
);
|
|
37
|
+
} );
|
|
38
|
+
expect( input ).toHaveAccessibleDescription(
|
|
39
|
+
expect.stringContaining( 'Enter a full URL.' )
|
|
40
|
+
);
|
|
41
|
+
} );
|
|
42
|
+
} );
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedNumberControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedNumberControl', () => {
|
|
6
|
+
it( 'should preserve the help description', () => {
|
|
7
|
+
render(
|
|
8
|
+
<ValidatedNumberControl label="Quantity" help="Enter a quantity." />
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
screen.getByRole( 'spinbutton', { name: 'Quantity' } )
|
|
13
|
+
).toHaveAccessibleDescription( 'Enter a quantity.' );
|
|
14
|
+
} );
|
|
15
|
+
|
|
16
|
+
it( 'should append the validation error alongside the help description', async () => {
|
|
17
|
+
const user = userEvent.setup();
|
|
18
|
+
render(
|
|
19
|
+
<form>
|
|
20
|
+
<ValidatedNumberControl
|
|
21
|
+
label="Quantity"
|
|
22
|
+
help="Enter a quantity."
|
|
23
|
+
required
|
|
24
|
+
/>
|
|
25
|
+
<button type="submit">Submit</button>
|
|
26
|
+
</form>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const input = screen.getByRole( 'spinbutton', {
|
|
30
|
+
name: /^Quantity/,
|
|
31
|
+
} );
|
|
32
|
+
|
|
33
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
34
|
+
|
|
35
|
+
await waitFor( () => {
|
|
36
|
+
expect( input ).toHaveAccessibleDescription(
|
|
37
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
38
|
+
);
|
|
39
|
+
} );
|
|
40
|
+
expect( input ).toHaveAccessibleDescription(
|
|
41
|
+
expect.stringContaining( 'Enter a quantity.' )
|
|
42
|
+
);
|
|
43
|
+
} );
|
|
44
|
+
} );
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedRadioControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedRadioControl', () => {
|
|
6
|
+
const options = [
|
|
7
|
+
{ label: 'Small', value: 'small' },
|
|
8
|
+
{ label: 'Medium', value: 'medium' },
|
|
9
|
+
{ label: 'Large', value: 'large' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
it( 'should preserve the help description on the radio group', () => {
|
|
13
|
+
render(
|
|
14
|
+
<ValidatedRadioControl
|
|
15
|
+
label="Size"
|
|
16
|
+
help="Choose a size."
|
|
17
|
+
options={ options }
|
|
18
|
+
onChange={ () => {} }
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByRole( 'group', { name: 'Size' } )
|
|
24
|
+
).toHaveAccessibleDescription( 'Choose a size.' );
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
it( 'should append the validation error to the first radio input', async () => {
|
|
28
|
+
const user = userEvent.setup();
|
|
29
|
+
render(
|
|
30
|
+
<form>
|
|
31
|
+
<ValidatedRadioControl
|
|
32
|
+
label="Size"
|
|
33
|
+
help="Choose a size."
|
|
34
|
+
options={ options }
|
|
35
|
+
onChange={ () => {} }
|
|
36
|
+
required
|
|
37
|
+
/>
|
|
38
|
+
<button type="submit">Submit</button>
|
|
39
|
+
</form>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
43
|
+
|
|
44
|
+
// The validation error targets the first radio input (the validity
|
|
45
|
+
// target), while the help description stays on the group.
|
|
46
|
+
const firstRadio = screen.getByRole( 'radio', {
|
|
47
|
+
name: 'Small',
|
|
48
|
+
} );
|
|
49
|
+
await waitFor( () => {
|
|
50
|
+
expect( firstRadio ).toHaveAccessibleDescription(
|
|
51
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
52
|
+
);
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
expect(
|
|
56
|
+
screen.getByRole( 'group', { name: /^Size/ } )
|
|
57
|
+
).toHaveAccessibleDescription(
|
|
58
|
+
expect.stringContaining( 'Choose a size.' )
|
|
59
|
+
);
|
|
60
|
+
} );
|
|
61
|
+
} );
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { useState, useRef } from '@wordpress/element';
|
|
4
|
+
import { ValidatedRangeControl } from '../components';
|
|
5
|
+
|
|
6
|
+
describe( 'ValidatedRangeControl', () => {
|
|
7
|
+
it( 'should preserve the help description', () => {
|
|
8
|
+
render(
|
|
9
|
+
<ValidatedRangeControl label="Opacity" help="Set the opacity." />
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
expect(
|
|
13
|
+
screen.getByRole( 'slider', { name: 'Opacity' } )
|
|
14
|
+
).toHaveAccessibleDescription( 'Set the opacity.' );
|
|
15
|
+
} );
|
|
16
|
+
|
|
17
|
+
// Range inputs always have a value, so `required` never fails constraint
|
|
18
|
+
// validation. Use `customValidity` to trigger the validation error.
|
|
19
|
+
it( 'should append the validation error alongside the help description', async () => {
|
|
20
|
+
const user = userEvent.setup();
|
|
21
|
+
|
|
22
|
+
function TestComponent() {
|
|
23
|
+
const [ customValidity, setCustomValidity ] =
|
|
24
|
+
useState<
|
|
25
|
+
React.ComponentProps<
|
|
26
|
+
typeof ValidatedRangeControl
|
|
27
|
+
>[ 'customValidity' ]
|
|
28
|
+
>( undefined );
|
|
29
|
+
const ref = useRef< HTMLInputElement >( null );
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<ValidatedRangeControl
|
|
34
|
+
ref={ ref }
|
|
35
|
+
label="Opacity"
|
|
36
|
+
help="Set the opacity."
|
|
37
|
+
customValidity={ customValidity }
|
|
38
|
+
/>
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
onClick={ () => {
|
|
42
|
+
setCustomValidity( {
|
|
43
|
+
type: 'invalid',
|
|
44
|
+
message: 'Value out of range.',
|
|
45
|
+
} );
|
|
46
|
+
requestAnimationFrame(
|
|
47
|
+
() => ref.current?.reportValidity()
|
|
48
|
+
);
|
|
49
|
+
} }
|
|
50
|
+
>
|
|
51
|
+
Validate
|
|
52
|
+
</button>
|
|
53
|
+
</>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
render( <TestComponent /> );
|
|
58
|
+
|
|
59
|
+
const slider = screen.getByRole( 'slider', { name: 'Opacity' } );
|
|
60
|
+
expect( slider ).toHaveAccessibleDescription( 'Set the opacity.' );
|
|
61
|
+
|
|
62
|
+
await user.click( screen.getByRole( 'button', { name: 'Validate' } ) );
|
|
63
|
+
|
|
64
|
+
await waitFor( () => {
|
|
65
|
+
expect( slider ).toHaveAccessibleDescription(
|
|
66
|
+
expect.stringContaining( 'Value out of range.' )
|
|
67
|
+
);
|
|
68
|
+
} );
|
|
69
|
+
expect( slider ).toHaveAccessibleDescription(
|
|
70
|
+
expect.stringContaining( 'Set the opacity.' )
|
|
71
|
+
);
|
|
72
|
+
} );
|
|
73
|
+
} );
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedSelectControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedSelectControl', () => {
|
|
6
|
+
const options = [
|
|
7
|
+
{ label: 'Select a color...', value: '' },
|
|
8
|
+
{ label: 'Red', value: 'red' },
|
|
9
|
+
{ label: 'Blue', value: 'blue' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
it( 'should preserve the help description', () => {
|
|
13
|
+
render(
|
|
14
|
+
<ValidatedSelectControl
|
|
15
|
+
label="Color"
|
|
16
|
+
help="Pick a color."
|
|
17
|
+
options={ options }
|
|
18
|
+
onChange={ () => {} }
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByRole( 'combobox', { name: 'Color' } )
|
|
24
|
+
).toHaveAccessibleDescription( 'Pick a color.' );
|
|
25
|
+
} );
|
|
26
|
+
|
|
27
|
+
it( 'should append the validation error alongside the help description', async () => {
|
|
28
|
+
const user = userEvent.setup();
|
|
29
|
+
render(
|
|
30
|
+
<form>
|
|
31
|
+
<ValidatedSelectControl
|
|
32
|
+
label="Color"
|
|
33
|
+
help="Pick a color."
|
|
34
|
+
options={ options }
|
|
35
|
+
onChange={ () => {} }
|
|
36
|
+
required
|
|
37
|
+
/>
|
|
38
|
+
<button type="submit">Submit</button>
|
|
39
|
+
</form>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const select = screen.getByRole( 'combobox', {
|
|
43
|
+
name: /^Color/,
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
47
|
+
|
|
48
|
+
await waitFor( () => {
|
|
49
|
+
expect( select ).toHaveAccessibleDescription(
|
|
50
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
51
|
+
);
|
|
52
|
+
} );
|
|
53
|
+
expect( select ).toHaveAccessibleDescription(
|
|
54
|
+
expect.stringContaining( 'Pick a color.' )
|
|
55
|
+
);
|
|
56
|
+
} );
|
|
57
|
+
} );
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { ValidatedTextControl } from '../components';
|
|
4
|
+
|
|
5
|
+
describe( 'ValidatedTextControl', () => {
|
|
6
|
+
it( 'should preserve the help description', () => {
|
|
7
|
+
render(
|
|
8
|
+
<ValidatedTextControl
|
|
9
|
+
label="Name"
|
|
10
|
+
help="Enter your full name."
|
|
11
|
+
onChange={ () => {} }
|
|
12
|
+
value=""
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(
|
|
17
|
+
screen.getByRole( 'textbox', { name: 'Name' } )
|
|
18
|
+
).toHaveAccessibleDescription( 'Enter your full name.' );
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
it( 'should append the validation error alongside the help description', async () => {
|
|
22
|
+
const user = userEvent.setup();
|
|
23
|
+
render(
|
|
24
|
+
<form>
|
|
25
|
+
<ValidatedTextControl
|
|
26
|
+
label="Name"
|
|
27
|
+
help="Enter your full name."
|
|
28
|
+
onChange={ () => {} }
|
|
29
|
+
value=""
|
|
30
|
+
required
|
|
31
|
+
/>
|
|
32
|
+
<button type="submit">Submit</button>
|
|
33
|
+
</form>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const input = screen.getByRole( 'textbox', { name: /^Name/ } );
|
|
37
|
+
|
|
38
|
+
await user.click( screen.getByRole( 'button', { name: 'Submit' } ) );
|
|
39
|
+
|
|
40
|
+
await waitFor( () => {
|
|
41
|
+
expect( input ).toHaveAccessibleDescription(
|
|
42
|
+
expect.stringContaining( 'Constraints not satisfied' )
|
|
43
|
+
);
|
|
44
|
+
} );
|
|
45
|
+
expect( input ).toHaveAccessibleDescription(
|
|
46
|
+
expect.stringContaining( 'Enter your full name.' )
|
|
47
|
+
);
|
|
48
|
+
} );
|
|
49
|
+
} );
|