@wordpress/components 30.9.0 → 31.0.1-next.6deb34194.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.
Files changed (214) hide show
  1. package/CHANGELOG.md +25 -4
  2. package/build/alignment-matrix-control/cell.js +131 -3
  3. package/build/alignment-matrix-control/cell.js.map +4 -4
  4. package/build/alignment-matrix-control/index.js +134 -6
  5. package/build/alignment-matrix-control/index.js.map +3 -3
  6. package/build/angle-picker-control/angle-circle.js +119 -15
  7. package/build/angle-picker-control/angle-circle.js.map +4 -4
  8. package/build/angle-picker-control/index.js +12 -7
  9. package/build/angle-picker-control/index.js.map +3 -3
  10. package/build/dropdown-menu/index.js +1 -1
  11. package/build/dropdown-menu/index.js.map +2 -2
  12. package/build/menu/styles.js +17 -17
  13. package/build/menu/styles.js.map +2 -2
  14. package/build/menu-item/index.js +1 -1
  15. package/build/menu-item/index.js.map +2 -2
  16. package/build/notice/index.js +1 -1
  17. package/build/notice/index.js.map +2 -2
  18. package/build/snackbar/index.js +1 -1
  19. package/build/snackbar/index.js.map +1 -1
  20. package/build/validated-form-controls/components/checkbox-control.js +0 -10
  21. package/build/validated-form-controls/components/checkbox-control.js.map +2 -2
  22. package/build/validated-form-controls/components/combobox-control.js +1 -11
  23. package/build/validated-form-controls/components/combobox-control.js.map +2 -2
  24. package/build/validated-form-controls/components/custom-select-control.js +0 -10
  25. package/build/validated-form-controls/components/custom-select-control.js.map +2 -2
  26. package/build/validated-form-controls/components/form-token-field.js +2 -12
  27. package/build/validated-form-controls/components/form-token-field.js.map +2 -2
  28. package/build/validated-form-controls/components/input-control.js +0 -10
  29. package/build/validated-form-controls/components/input-control.js.map +2 -2
  30. package/build/validated-form-controls/components/number-control.js +0 -10
  31. package/build/validated-form-controls/components/number-control.js.map +2 -2
  32. package/build/validated-form-controls/components/radio-control.js +0 -10
  33. package/build/validated-form-controls/components/radio-control.js.map +2 -2
  34. package/build/validated-form-controls/components/range-control.js +0 -10
  35. package/build/validated-form-controls/components/range-control.js.map +2 -2
  36. package/build/validated-form-controls/components/select-control.js +0 -10
  37. package/build/validated-form-controls/components/select-control.js.map +2 -2
  38. package/build/validated-form-controls/components/text-control.js +0 -10
  39. package/build/validated-form-controls/components/text-control.js.map +2 -2
  40. package/build/validated-form-controls/components/textarea-control.js +0 -10
  41. package/build/validated-form-controls/components/textarea-control.js.map +2 -2
  42. package/build/validated-form-controls/components/toggle-control.js +0 -10
  43. package/build/validated-form-controls/components/toggle-control.js.map +2 -2
  44. package/build/validated-form-controls/components/toggle-group-control.js +0 -10
  45. package/build/validated-form-controls/components/toggle-group-control.js.map +2 -2
  46. package/build/validated-form-controls/control-with-error.js +53 -58
  47. package/build/validated-form-controls/control-with-error.js.map +2 -2
  48. package/build-module/alignment-matrix-control/cell.js +131 -3
  49. package/build-module/alignment-matrix-control/cell.js.map +3 -3
  50. package/build-module/alignment-matrix-control/index.js +134 -6
  51. package/build-module/alignment-matrix-control/index.js.map +3 -3
  52. package/build-module/angle-picker-control/angle-circle.js +109 -15
  53. package/build-module/angle-picker-control/angle-circle.js.map +3 -3
  54. package/build-module/angle-picker-control/index.js +12 -7
  55. package/build-module/angle-picker-control/index.js.map +2 -2
  56. package/build-module/dropdown-menu/index.js +1 -1
  57. package/build-module/dropdown-menu/index.js.map +2 -2
  58. package/build-module/menu/styles.js +17 -17
  59. package/build-module/menu/styles.js.map +2 -2
  60. package/build-module/menu-item/index.js +1 -1
  61. package/build-module/menu-item/index.js.map +2 -2
  62. package/build-module/notice/index.js +1 -1
  63. package/build-module/notice/index.js.map +2 -2
  64. package/build-module/snackbar/index.js +1 -1
  65. package/build-module/snackbar/index.js.map +1 -1
  66. package/build-module/validated-form-controls/components/checkbox-control.js +0 -10
  67. package/build-module/validated-form-controls/components/checkbox-control.js.map +2 -2
  68. package/build-module/validated-form-controls/components/combobox-control.js +1 -11
  69. package/build-module/validated-form-controls/components/combobox-control.js.map +2 -2
  70. package/build-module/validated-form-controls/components/custom-select-control.js +0 -10
  71. package/build-module/validated-form-controls/components/custom-select-control.js.map +2 -2
  72. package/build-module/validated-form-controls/components/form-token-field.js +2 -12
  73. package/build-module/validated-form-controls/components/form-token-field.js.map +2 -2
  74. package/build-module/validated-form-controls/components/input-control.js +0 -10
  75. package/build-module/validated-form-controls/components/input-control.js.map +2 -2
  76. package/build-module/validated-form-controls/components/number-control.js +0 -10
  77. package/build-module/validated-form-controls/components/number-control.js.map +2 -2
  78. package/build-module/validated-form-controls/components/radio-control.js +0 -10
  79. package/build-module/validated-form-controls/components/radio-control.js.map +2 -2
  80. package/build-module/validated-form-controls/components/range-control.js +0 -10
  81. package/build-module/validated-form-controls/components/range-control.js.map +2 -2
  82. package/build-module/validated-form-controls/components/select-control.js +0 -10
  83. package/build-module/validated-form-controls/components/select-control.js.map +2 -2
  84. package/build-module/validated-form-controls/components/text-control.js +0 -10
  85. package/build-module/validated-form-controls/components/text-control.js.map +2 -2
  86. package/build-module/validated-form-controls/components/textarea-control.js +0 -10
  87. package/build-module/validated-form-controls/components/textarea-control.js.map +2 -2
  88. package/build-module/validated-form-controls/components/toggle-control.js +0 -10
  89. package/build-module/validated-form-controls/components/toggle-control.js.map +2 -2
  90. package/build-module/validated-form-controls/components/toggle-group-control.js +0 -10
  91. package/build-module/validated-form-controls/components/toggle-group-control.js.map +2 -2
  92. package/build-module/validated-form-controls/control-with-error.js +53 -58
  93. package/build-module/validated-form-controls/control-with-error.js.map +2 -2
  94. package/build-style/style-rtl.css +21 -33
  95. package/build-style/style.css +21 -33
  96. package/build-types/alignment-matrix-control/cell.d.ts.map +1 -1
  97. package/build-types/alignment-matrix-control/index.d.ts.map +1 -1
  98. package/build-types/angle-picker-control/angle-circle.d.ts +1 -1
  99. package/build-types/angle-picker-control/angle-circle.d.ts.map +1 -1
  100. package/build-types/angle-picker-control/index.d.ts.map +1 -1
  101. package/build-types/notice/index.d.ts.map +1 -1
  102. package/build-types/notice/stories/index.story.d.ts.map +1 -1
  103. package/build-types/validated-form-controls/components/checkbox-control.d.ts +1 -1
  104. package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -1
  105. package/build-types/validated-form-controls/components/combobox-control.d.ts +2 -3
  106. package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -1
  107. package/build-types/validated-form-controls/components/custom-select-control.d.ts +1 -2
  108. package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -1
  109. package/build-types/validated-form-controls/components/form-token-field.d.ts +1 -2
  110. package/build-types/validated-form-controls/components/form-token-field.d.ts.map +1 -1
  111. package/build-types/validated-form-controls/components/input-control.d.ts +1 -2
  112. package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -1
  113. package/build-types/validated-form-controls/components/number-control.d.ts +1 -1
  114. package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -1
  115. package/build-types/validated-form-controls/components/radio-control.d.ts +1 -1
  116. package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -1
  117. package/build-types/validated-form-controls/components/range-control.d.ts +1 -1
  118. package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -1
  119. package/build-types/validated-form-controls/components/select-control.d.ts +2 -3
  120. package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -1
  121. package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -1
  122. package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -1
  123. package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -1
  124. package/build-types/validated-form-controls/components/stories/form-token-field.story.d.ts.map +1 -1
  125. package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -1
  126. package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -1
  127. package/build-types/validated-form-controls/components/stories/overview.story.d.ts +7 -0
  128. package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -1
  129. package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -1
  130. package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -1
  131. package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -1
  132. package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -1
  133. package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -1
  134. package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -1
  135. package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -1
  136. package/build-types/validated-form-controls/components/text-control.d.ts +1 -1
  137. package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -1
  138. package/build-types/validated-form-controls/components/textarea-control.d.ts +1 -1
  139. package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -1
  140. package/build-types/validated-form-controls/components/toggle-control.d.ts +1 -1
  141. package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -1
  142. package/build-types/validated-form-controls/components/toggle-group-control.d.ts +1 -1
  143. package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -1
  144. package/build-types/validated-form-controls/components/types.d.ts +1 -9
  145. package/build-types/validated-form-controls/components/types.d.ts.map +1 -1
  146. package/build-types/validated-form-controls/control-with-error.d.ts +4 -5
  147. package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
  148. package/package.json +20 -20
  149. package/src/alignment-matrix-control/cell.tsx +14 -3
  150. package/src/alignment-matrix-control/index.tsx +15 -6
  151. package/src/alignment-matrix-control/style.module.scss +84 -0
  152. package/src/angle-picker-control/angle-circle.tsx +27 -12
  153. package/src/angle-picker-control/index.tsx +8 -7
  154. package/src/angle-picker-control/style.module.scss +40 -0
  155. package/src/button/style.scss +1 -1
  156. package/src/dropdown-menu/index.tsx +1 -1
  157. package/src/dropdown-menu/style.scss +1 -1
  158. package/src/guide/style.scss +3 -3
  159. package/src/menu/styles.ts +2 -2
  160. package/src/menu-item/index.tsx +1 -1
  161. package/src/menu-item/test/__snapshots__/index.js.snap +4 -4
  162. package/src/modal/style.scss +5 -5
  163. package/src/notice/index.tsx +53 -46
  164. package/src/notice/stories/index.story.tsx +17 -1
  165. package/src/notice/style.scss +3 -20
  166. package/src/snackbar/index.tsx +1 -1
  167. package/src/validated-form-controls/components/checkbox-control.tsx +1 -14
  168. package/src/validated-form-controls/components/combobox-control.tsx +1 -14
  169. package/src/validated-form-controls/components/custom-select-control.tsx +1 -19
  170. package/src/validated-form-controls/components/form-token-field.tsx +2 -15
  171. package/src/validated-form-controls/components/input-control.tsx +1 -14
  172. package/src/validated-form-controls/components/number-control.tsx +1 -16
  173. package/src/validated-form-controls/components/radio-control.tsx +2 -18
  174. package/src/validated-form-controls/components/range-control.tsx +1 -14
  175. package/src/validated-form-controls/components/select-control.tsx +1 -23
  176. package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +11 -20
  177. package/src/validated-form-controls/components/stories/combobox-control.story.tsx +8 -17
  178. package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +8 -17
  179. package/src/validated-form-controls/components/stories/form-token-field.story.tsx +14 -26
  180. package/src/validated-form-controls/components/stories/input-control.story.tsx +25 -50
  181. package/src/validated-form-controls/components/stories/number-control.story.tsx +10 -19
  182. package/src/validated-form-controls/components/stories/overview.mdx +3 -3
  183. package/src/validated-form-controls/components/stories/overview.story.tsx +94 -79
  184. package/src/validated-form-controls/components/stories/radio-control.story.tsx +11 -20
  185. package/src/validated-form-controls/components/stories/range-control.story.tsx +8 -17
  186. package/src/validated-form-controls/components/stories/select-control.story.tsx +9 -18
  187. package/src/validated-form-controls/components/stories/text-control.story.tsx +11 -17
  188. package/src/validated-form-controls/components/stories/textarea-control.story.tsx +12 -16
  189. package/src/validated-form-controls/components/stories/toggle-control.story.tsx +11 -20
  190. package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +8 -17
  191. package/src/validated-form-controls/components/text-control.tsx +1 -14
  192. package/src/validated-form-controls/components/textarea-control.tsx +1 -14
  193. package/src/validated-form-controls/components/toggle-control.tsx +1 -14
  194. package/src/validated-form-controls/components/toggle-group-control.tsx +1 -14
  195. package/src/validated-form-controls/components/types.ts +1 -9
  196. package/src/validated-form-controls/control-with-error.tsx +57 -84
  197. package/src/validated-form-controls/style.scss +7 -7
  198. package/src/validated-form-controls/test/control-with-error.tsx +66 -5
  199. package/tsconfig.json +1 -0
  200. package/tsconfig.tsbuildinfo +1 -1
  201. package/build/alignment-matrix-control/styles.js +0 -105
  202. package/build/alignment-matrix-control/styles.js.map +0 -7
  203. package/build/angle-picker-control/styles/angle-picker-control-styles.js +0 -88
  204. package/build/angle-picker-control/styles/angle-picker-control-styles.js.map +0 -7
  205. package/build-module/alignment-matrix-control/styles.js +0 -67
  206. package/build-module/alignment-matrix-control/styles.js.map +0 -7
  207. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js +0 -50
  208. package/build-module/angle-picker-control/styles/angle-picker-control-styles.js.map +0 -7
  209. package/build-types/alignment-matrix-control/styles.d.ts +0 -21
  210. package/build-types/alignment-matrix-control/styles.d.ts.map +0 -1
  211. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts +0 -18
  212. package/build-types/angle-picker-control/styles/angle-picker-control-styles.d.ts.map +0 -1
  213. package/src/alignment-matrix-control/styles.ts +0 -113
  214. package/src/angle-picker-control/styles/angle-picker-control-styles.tsx +0 -58
@@ -111,53 +111,60 @@ function Notice( {
111
111
  <VisuallyHidden>{ getStatusLabel( status ) }</VisuallyHidden>
112
112
  <div className="components-notice__content">
113
113
  { children }
114
- <div className="components-notice__actions">
115
- { actions.map(
116
- (
117
- {
118
- className: buttonCustomClasses,
119
- label,
120
- isPrimary,
121
- variant,
122
- noDefaultClasses = false,
123
- onClick,
124
- url,
125
- }: NoticeAction &
126
- // `isPrimary` is a legacy prop included for
127
- // backcompat, but `variant` should be used
128
- // instead.
129
- Pick< DeprecatedButtonProps, 'isPrimary' >,
130
- index
131
- ) => {
132
- let computedVariant = variant;
133
- if ( variant !== 'primary' && ! noDefaultClasses ) {
134
- computedVariant = ! url ? 'secondary' : 'link';
135
- }
136
- if (
137
- typeof computedVariant === 'undefined' &&
138
- isPrimary
139
- ) {
140
- computedVariant = 'primary';
141
- }
114
+ { actions.length > 0 && (
115
+ <div className="components-notice__actions">
116
+ { actions.map(
117
+ (
118
+ {
119
+ className: buttonCustomClasses,
120
+ label,
121
+ isPrimary,
122
+ variant,
123
+ noDefaultClasses = false,
124
+ onClick,
125
+ url,
126
+ }: NoticeAction &
127
+ // `isPrimary` is a legacy prop included for
128
+ // backcompat, but `variant` should be used
129
+ // instead.
130
+ Pick< DeprecatedButtonProps, 'isPrimary' >,
131
+ index
132
+ ) => {
133
+ let computedVariant = variant;
134
+ if (
135
+ variant !== 'primary' &&
136
+ ! noDefaultClasses
137
+ ) {
138
+ computedVariant = ! url
139
+ ? 'secondary'
140
+ : 'link';
141
+ }
142
+ if (
143
+ typeof computedVariant === 'undefined' &&
144
+ isPrimary
145
+ ) {
146
+ computedVariant = 'primary';
147
+ }
142
148
 
143
- return (
144
- <Button
145
- __next40pxDefaultSize
146
- key={ index }
147
- href={ url }
148
- variant={ computedVariant }
149
- onClick={ url ? undefined : onClick }
150
- className={ clsx(
151
- 'components-notice__action',
152
- buttonCustomClasses
153
- ) }
154
- >
155
- { label }
156
- </Button>
157
- );
158
- }
159
- ) }
160
- </div>
149
+ return (
150
+ <Button
151
+ __next40pxDefaultSize
152
+ key={ index }
153
+ href={ url }
154
+ variant={ computedVariant }
155
+ onClick={ url ? undefined : onClick }
156
+ className={ clsx(
157
+ 'components-notice__action',
158
+ buttonCustomClasses
159
+ ) }
160
+ >
161
+ { label }
162
+ </Button>
163
+ );
164
+ }
165
+ ) }
166
+ </div>
167
+ ) }
161
168
  </div>
162
169
  { isDismissible && (
163
170
  <Button
@@ -89,7 +89,7 @@ WithActions.args = {
89
89
  };
90
90
 
91
91
  export const NoticeListSubcomponent: StoryFn< typeof NoticeList > = () => {
92
- const exampleNotices = [
92
+ const exampleNotices: NoticeListProps[ 'notices' ] = [
93
93
  {
94
94
  id: 'second-notice',
95
95
  content: 'second notice content',
@@ -97,6 +97,22 @@ export const NoticeListSubcomponent: StoryFn< typeof NoticeList > = () => {
97
97
  {
98
98
  id: 'first-notice',
99
99
  content: 'first notice content',
100
+ actions: [
101
+ {
102
+ label: 'Click me!',
103
+ onClick: () => {},
104
+ variant: 'primary',
105
+ },
106
+ {
107
+ label: 'Or click me instead!',
108
+ onClick: () => {},
109
+ },
110
+ {
111
+ label: 'Or visit a link for more info',
112
+ url: 'https://wordpress.org',
113
+ variant: 'link',
114
+ },
115
+ ],
100
116
  },
101
117
  ];
102
118
  const [ notices, setNotices ] = useState( exampleNotices );
@@ -41,20 +41,9 @@
41
41
  .components-notice__actions {
42
42
  display: flex;
43
43
  flex-wrap: wrap;
44
- }
45
-
46
- .components-notice__action.components-button {
47
- &,
48
- &.is-link {
49
- margin-left: $grid-unit-15;
50
- }
51
- &.is-secondary {
52
- vertical-align: initial;
53
- }
54
-
55
- // When it has better support, this can be replaced
56
- // with column-gap since these are flex items.
57
- margin-right: $grid-unit-10;
44
+ align-items: center;
45
+ gap: $grid-unit-15;
46
+ margin-top: $grid-unit-15;
58
47
  }
59
48
 
60
49
  .components-notice__dismiss {
@@ -86,10 +75,4 @@
86
75
  margin-bottom: $grid-unit-15;
87
76
  line-height: 2;
88
77
  }
89
-
90
- .components-notice__action.components-button {
91
- display: block;
92
- margin-left: 0;
93
- margin-top: $grid-unit-10;
94
- }
95
78
  }
@@ -27,7 +27,7 @@ import type { SnackbarProps } from './types';
27
27
  import type { NoticeAction } from '../notice/types';
28
28
  import type { WordPressComponentProps } from '../context';
29
29
 
30
- const NOTICE_TIMEOUT = 10000;
30
+ const NOTICE_TIMEOUT = 6000;
31
31
 
32
32
  /**
33
33
  * Custom hook which announces the message with the given politeness, if a
@@ -10,37 +10,28 @@ import { forwardRef, useRef } from '@wordpress/element';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import type { ValidatedControlProps } from './types';
12
12
  import CheckboxControl from '../../checkbox-control';
13
- import type { CheckboxControlProps } from '../../checkbox-control/types';
14
-
15
- type Value = CheckboxControlProps[ 'checked' ];
16
13
 
17
14
  const UnforwardedValidatedCheckboxControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
20
  }: Omit<
26
21
  React.ComponentProps< typeof CheckboxControl >,
27
22
  '__nextHasNoMarginBottom'
28
23
  > &
29
- ValidatedControlProps< Value >,
24
+ ValidatedControlProps,
30
25
  forwardedRef: React.ForwardedRef< HTMLInputElement >
31
26
  ) => {
32
27
  const validityTargetRef = useRef< HTMLDivElement >( null );
33
28
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
34
- const valueRef = useRef< Value >( restProps.checked );
35
29
 
36
30
  return (
37
31
  <ControlWithError
38
32
  required={ required }
39
33
  markWhenOptional={ markWhenOptional }
40
34
  ref={ mergedRefs }
41
- onValidate={ () => {
42
- return onValidate?.( valueRef.current );
43
- } }
44
35
  customValidity={ customValidity }
45
36
  getValidityTarget={ () =>
46
37
  validityTargetRef.current?.querySelector< HTMLInputElement >(
@@ -50,10 +41,6 @@ const UnforwardedValidatedCheckboxControl = (
50
41
  >
51
42
  <CheckboxControl
52
43
  __nextHasNoMarginBottom
53
- onChange={ ( value ) => {
54
- valueRef.current = value;
55
- onChange?.( value );
56
- } }
57
44
  // TODO: Upstream limitation - CheckboxControl doesn't support uncontrolled mode, visually.
58
45
  { ...restProps }
59
46
  />
@@ -10,28 +10,22 @@ import { forwardRef, useEffect, useRef } from '@wordpress/element';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import type { ValidatedControlProps } from './types';
12
12
  import ComboboxControl from '../../combobox-control';
13
- import type { ComboboxControlProps } from '../../combobox-control/types';
14
-
15
- type Value = ComboboxControlProps[ 'value' ];
16
13
 
17
14
  const UnforwardedValidatedComboboxControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
20
  }: Omit<
26
21
  React.ComponentProps< typeof ComboboxControl >,
27
22
  '__next40pxDefaultSize' | '__nextHasNoMarginBottom'
28
23
  > &
29
- ValidatedControlProps< Value >,
24
+ ValidatedControlProps,
30
25
  forwardedRef: React.ForwardedRef< HTMLInputElement >
31
26
  ) => {
32
27
  const validityTargetRef = useRef< HTMLInputElement >( null );
33
28
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
34
- const valueRef = useRef< Value >( restProps.value );
35
29
 
36
30
  // TODO: Upstream limitation - The `required` attribute is not passed down to the input,
37
31
  // so we need to set it manually.
@@ -51,9 +45,6 @@ const UnforwardedValidatedComboboxControl = (
51
45
  required={ required }
52
46
  markWhenOptional={ markWhenOptional }
53
47
  ref={ mergedRefs }
54
- onValidate={ () => {
55
- return onValidate?.( valueRef.current );
56
- } }
57
48
  customValidity={ customValidity }
58
49
  getValidityTarget={ () =>
59
50
  validityTargetRef.current?.querySelector< HTMLInputElement >(
@@ -65,10 +56,6 @@ const UnforwardedValidatedComboboxControl = (
65
56
  __nextHasNoMarginBottom
66
57
  __next40pxDefaultSize
67
58
  { ...restProps }
68
- onChange={ ( value ) => {
69
- valueRef.current = value;
70
- onChange?.( value );
71
- } }
72
59
  />
73
60
  </ControlWithError>
74
61
  );
@@ -9,32 +9,21 @@ import { forwardRef, useRef } from '@wordpress/element';
9
9
  import { ControlWithError } from '../control-with-error';
10
10
  import type { ValidatedControlProps } from './types';
11
11
  import CustomSelectControl from '../../custom-select-control';
12
- import type {
13
- CustomSelectOption,
14
- CustomSelectProps,
15
- } from '../../custom-select-control/types';
16
-
17
- type CustomSelectControlProps = CustomSelectProps< CustomSelectOption >;
18
-
19
- type Value = CustomSelectControlProps[ 'value' ];
20
12
 
21
13
  const UnforwardedValidatedCustomSelectControl = (
22
14
  {
23
15
  required,
24
- onValidate,
25
16
  customValidity,
26
- onChange,
27
17
  markWhenOptional,
28
18
  ...restProps
29
19
  }: Omit<
30
20
  React.ComponentProps< typeof CustomSelectControl >,
31
21
  '__next40pxDefaultSize'
32
22
  > &
33
- ValidatedControlProps< Value >,
23
+ ValidatedControlProps,
34
24
  forwardedRef: React.ForwardedRef< HTMLDivElement >
35
25
  ) => {
36
26
  const validityTargetRef = useRef< HTMLSelectElement >( null );
37
- const valueRef = useRef< Value >( restProps.value );
38
27
 
39
28
  return (
40
29
  <div
@@ -44,9 +33,6 @@ const UnforwardedValidatedCustomSelectControl = (
44
33
  <ControlWithError
45
34
  required={ required }
46
35
  markWhenOptional={ markWhenOptional }
47
- onValidate={ () => {
48
- return onValidate?.( valueRef.current );
49
- } }
50
36
  customValidity={ customValidity }
51
37
  getValidityTarget={ () => validityTargetRef.current }
52
38
  >
@@ -54,10 +40,6 @@ const UnforwardedValidatedCustomSelectControl = (
54
40
  // TODO: Upstream limitation - Required isn't passed down correctly,
55
41
  // so it needs to be set on a delegate element.
56
42
  __next40pxDefaultSize
57
- onChange={ ( value ) => {
58
- valueRef.current = value.selectedItem;
59
- onChange?.( value );
60
- } }
61
43
  { ...restProps }
62
44
  />
63
45
  </ControlWithError>
@@ -9,27 +9,21 @@ import { forwardRef, useRef } from '@wordpress/element';
9
9
  import { ControlWithError } from '../control-with-error';
10
10
  import type { ValidatedControlProps } from './types';
11
11
  import { FormTokenField } from '../../form-token-field';
12
- import type { FormTokenFieldProps } from '../../form-token-field/types';
13
-
14
- type Value = FormTokenFieldProps[ 'value' ];
15
12
 
16
13
  const UnforwardedValidatedFormTokenField = (
17
14
  {
18
15
  required,
19
- onValidate,
20
16
  customValidity,
21
- onChange,
22
17
  markWhenOptional,
23
18
  ...restProps
24
19
  }: Omit<
25
20
  React.ComponentProps< typeof FormTokenField >,
26
21
  '__next40pxDefaultSize' | '__nextHasNoMarginBottom'
27
22
  > &
28
- ValidatedControlProps< FormTokenFieldProps[ 'value' ] >,
23
+ ValidatedControlProps,
29
24
  forwardedRef: React.ForwardedRef< HTMLDivElement >
30
25
  ) => {
31
26
  const validityTargetRef = useRef< HTMLInputElement >( null );
32
- const valueRef = useRef< Value >( restProps.value );
33
27
 
34
28
  return (
35
29
  <div
@@ -39,9 +33,6 @@ const UnforwardedValidatedFormTokenField = (
39
33
  <ControlWithError
40
34
  required={ required }
41
35
  markWhenOptional={ markWhenOptional }
42
- onValidate={ () => {
43
- return onValidate?.( valueRef.current );
44
- } }
45
36
  customValidity={ customValidity }
46
37
  getValidityTarget={ () => validityTargetRef.current }
47
38
  >
@@ -49,10 +40,6 @@ const UnforwardedValidatedFormTokenField = (
49
40
  __next40pxDefaultSize
50
41
  __nextHasNoMarginBottom
51
42
  { ...restProps }
52
- onChange={ ( value, ...args ) => {
53
- valueRef.current = value;
54
- onChange?.( value, ...args );
55
- } }
56
43
  />
57
44
  </ControlWithError>
58
45
  <input
@@ -61,7 +48,7 @@ const UnforwardedValidatedFormTokenField = (
61
48
  ref={ validityTargetRef }
62
49
  required={ required }
63
50
  value={
64
- valueRef.current && valueRef.current.length > 0
51
+ restProps.value && restProps.value.length > 0
65
52
  ? 'hasvalue'
66
53
  : ''
67
54
  }
@@ -10,46 +10,33 @@ import { useMergeRefs } from '@wordpress/compose';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import type { ValidatedControlProps } from './types';
12
12
  import InputControl from '../../input-control';
13
- import type { InputControlProps } from '../../input-control/types';
14
-
15
- type Value = InputControlProps[ 'value' ];
16
13
 
17
14
  const UnforwardedValidatedInputControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
20
  }: Omit<
26
21
  React.ComponentProps< typeof InputControl >,
27
22
  '__next40pxDefaultSize'
28
23
  > &
29
- ValidatedControlProps< InputControlProps[ 'value' ] >,
24
+ ValidatedControlProps,
30
25
  forwardedRef: React.ForwardedRef< HTMLInputElement >
31
26
  ) => {
32
27
  const validityTargetRef = useRef< HTMLInputElement >( null );
33
28
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
34
- const valueRef = useRef< Value >( restProps.value );
35
29
 
36
30
  return (
37
31
  <ControlWithError
38
32
  required={ required }
39
33
  markWhenOptional={ markWhenOptional }
40
- onValidate={ () => {
41
- return onValidate?.( valueRef.current );
42
- } }
43
34
  customValidity={ customValidity }
44
35
  getValidityTarget={ () => validityTargetRef.current }
45
36
  >
46
37
  <InputControl
47
38
  __next40pxDefaultSize
48
39
  ref={ mergedRefs }
49
- onChange={ ( value, ...args ) => {
50
- valueRef.current = value;
51
- onChange?.( value, ...args );
52
- } }
53
40
  { ...restProps }
54
41
  />
55
42
  </ControlWithError>
@@ -10,48 +10,33 @@ import { useMergeRefs } from '@wordpress/compose';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import NumberControl from '../../number-control';
12
12
  import type { ValidatedControlProps } from './types';
13
- import type { NumberControlProps } from '../../number-control/types';
14
-
15
- type Value = NumberControlProps[ 'value' ];
16
13
 
17
14
  const UnforwardedValidatedNumberControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
20
  }: Omit<
26
21
  React.ComponentProps< typeof NumberControl >,
27
22
  '__next40pxDefaultSize'
28
23
  > &
29
- ValidatedControlProps< Value >,
24
+ ValidatedControlProps,
30
25
  forwardedRef: React.ForwardedRef< HTMLInputElement >
31
26
  ) => {
32
27
  const validityTargetRef = useRef< HTMLInputElement >( null );
33
28
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
34
- const valueRef = useRef< Value >( restProps.value );
35
29
 
36
30
  return (
37
31
  <ControlWithError
38
32
  required={ required }
39
33
  markWhenOptional={ markWhenOptional }
40
- onValidate={ () => {
41
- return onValidate?.( valueRef.current );
42
- } }
43
34
  customValidity={ customValidity }
44
35
  getValidityTarget={ () => validityTargetRef.current }
45
36
  >
46
37
  <NumberControl
47
38
  __next40pxDefaultSize
48
39
  ref={ mergedRefs }
49
- // TODO: Upstream limitation - When form is submitted when value is undefined, it will
50
- // automatically set a clamped value (as defined by `min` attribute, so 0 by default).
51
- onChange={ ( value, ...args ) => {
52
- valueRef.current = value;
53
- onChange?.( value, ...args );
54
- } }
55
40
  { ...restProps }
56
41
  />
57
42
  </ControlWithError>
@@ -10,25 +10,18 @@ import { forwardRef, useRef } from '@wordpress/element';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import type { ValidatedControlProps } from './types';
12
12
  import RadioControl from '../../radio-control';
13
- import type { RadioControlProps } from '../../radio-control/types';
14
-
15
- type Value = RadioControlProps[ 'selected' ];
16
13
 
17
14
  const UnforwardedValidatedRadioControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
- }: React.ComponentProps< typeof RadioControl > &
26
- ValidatedControlProps< Value >,
20
+ }: React.ComponentProps< typeof RadioControl > & ValidatedControlProps,
27
21
  forwardedRef: React.ForwardedRef< HTMLDivElement >
28
22
  ) => {
29
23
  const validityTargetRef = useRef< HTMLDivElement >( null );
30
24
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
31
- const valueRef = useRef< Value >( restProps.selected );
32
25
 
33
26
  return (
34
27
  <ControlWithError
@@ -36,9 +29,6 @@ const UnforwardedValidatedRadioControl = (
36
29
  markWhenOptional={ markWhenOptional }
37
30
  // TODO: Upstream limitation - RadioControl does not accept a ref.
38
31
  ref={ mergedRefs }
39
- onValidate={ () => {
40
- return onValidate?.( valueRef.current );
41
- } }
42
32
  customValidity={ customValidity }
43
33
  getValidityTarget={ () =>
44
34
  validityTargetRef.current?.querySelector< HTMLInputElement >(
@@ -46,13 +36,7 @@ const UnforwardedValidatedRadioControl = (
46
36
  )
47
37
  }
48
38
  >
49
- <RadioControl
50
- onChange={ ( value ) => {
51
- valueRef.current = value;
52
- onChange?.( value );
53
- } }
54
- { ...restProps }
55
- />
39
+ <RadioControl { ...restProps } />
56
40
  </ControlWithError>
57
41
  );
58
42
  };
@@ -10,36 +10,27 @@ import { forwardRef, useRef } from '@wordpress/element';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import type { ValidatedControlProps } from './types';
12
12
  import RangeControl from '../../range-control';
13
- import type { RangeControlProps } from '../../range-control/types';
14
-
15
- type Value = RangeControlProps[ 'value' ];
16
13
 
17
14
  const UnforwardedValidatedRangeControl = (
18
15
  {
19
16
  required,
20
- onValidate,
21
17
  customValidity,
22
- onChange,
23
18
  markWhenOptional,
24
19
  ...restProps
25
20
  }: Omit<
26
21
  React.ComponentProps< typeof RangeControl >,
27
22
  '__next40pxDefaultSize' | '__nextHasNoMarginBottom'
28
23
  > &
29
- ValidatedControlProps< Value >,
24
+ ValidatedControlProps,
30
25
  forwardedRef: React.ForwardedRef< HTMLInputElement >
31
26
  ) => {
32
27
  const validityTargetRef = useRef< HTMLInputElement >( null );
33
28
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
34
- const valueRef = useRef< Value >( restProps.value );
35
29
 
36
30
  return (
37
31
  <ControlWithError
38
32
  required={ required }
39
33
  markWhenOptional={ markWhenOptional }
40
- onValidate={ () => {
41
- return onValidate?.( valueRef.current );
42
- } }
43
34
  customValidity={ customValidity }
44
35
  getValidityTarget={ () => validityTargetRef.current }
45
36
  >
@@ -47,10 +38,6 @@ const UnforwardedValidatedRangeControl = (
47
38
  __next40pxDefaultSize
48
39
  __nextHasNoMarginBottom
49
40
  ref={ mergedRefs }
50
- onChange={ ( value ) => {
51
- valueRef.current = value;
52
- onChange?.( value );
53
- } }
54
41
  { ...restProps }
55
42
  />
56
43
  </ControlWithError>
@@ -10,25 +10,11 @@ import { useMergeRefs } from '@wordpress/compose';
10
10
  import { ControlWithError } from '../control-with-error';
11
11
  import SelectControl from '../../select-control';
12
12
  import type { ValidatedControlProps } from './types';
13
- import type { SelectControlProps as _SelectControlProps } from '../../select-control/types';
14
-
15
- // Only support single value selection
16
- type SelectControlProps = Omit<
17
- _SelectControlProps,
18
- 'multiple' | 'onChange' | 'value'
19
- > & {
20
- onChange?: ( value: string ) => void;
21
- value?: string;
22
- };
23
-
24
- type Value = SelectControlProps[ 'value' ];
25
13
 
26
14
  const UnforwardedValidatedSelectControl = (
27
15
  {
28
16
  required,
29
- onValidate,
30
17
  customValidity,
31
- onChange,
32
18
  markWhenOptional,
33
19
  ...restProps
34
20
  }: Omit<
@@ -41,20 +27,16 @@ const UnforwardedValidatedSelectControl = (
41
27
  > & {
42
28
  value?: string;
43
29
  onChange: ( value: string ) => void;
44
- } & ValidatedControlProps< Value >,
30
+ } & ValidatedControlProps,
45
31
  forwardedRef: React.ForwardedRef< HTMLSelectElement >
46
32
  ) => {
47
33
  const validityTargetRef = useRef< HTMLSelectElement >( null );
48
34
  const mergedRefs = useMergeRefs( [ forwardedRef, validityTargetRef ] );
49
- const valueRef = useRef< Value >( restProps.value );
50
35
 
51
36
  return (
52
37
  <ControlWithError
53
38
  required={ required }
54
39
  markWhenOptional={ markWhenOptional }
55
- onValidate={ () => {
56
- return onValidate?.( valueRef.current );
57
- } }
58
40
  customValidity={ customValidity }
59
41
  getValidityTarget={ () => validityTargetRef.current }
60
42
  >
@@ -62,10 +44,6 @@ const UnforwardedValidatedSelectControl = (
62
44
  __nextHasNoMarginBottom
63
45
  __next40pxDefaultSize
64
46
  ref={ mergedRefs }
65
- onChange={ ( value ) => {
66
- valueRef.current = value;
67
- onChange?.( value );
68
- } }
69
47
  { ...restProps }
70
48
  />
71
49
  </ControlWithError>