@wordpress/components 32.5.0 → 32.6.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 (282) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +40 -0
  3. package/README.md +18 -4
  4. package/build/alignment-matrix-control/cell.cjs +3 -3
  5. package/build/alignment-matrix-control/cell.cjs.map +2 -2
  6. package/build/alignment-matrix-control/index.cjs +3 -3
  7. package/build/alignment-matrix-control/index.cjs.map +2 -2
  8. package/build/autocomplete/autocompleter-ui.cjs +75 -79
  9. package/build/autocomplete/autocompleter-ui.cjs.map +2 -2
  10. package/build/autocomplete/get-autocomplete-match.cjs +91 -0
  11. package/build/autocomplete/get-autocomplete-match.cjs.map +7 -0
  12. package/build/autocomplete/index.cjs +104 -107
  13. package/build/autocomplete/index.cjs.map +3 -3
  14. package/build/box-control/index.cjs +0 -8
  15. package/build/box-control/index.cjs.map +2 -2
  16. package/build/box-control/utils.cjs +1 -10
  17. package/build/box-control/utils.cjs.map +2 -2
  18. package/build/calendar/utils/use-localization-props.cjs +3 -2
  19. package/build/calendar/utils/use-localization-props.cjs.map +2 -2
  20. package/build/custom-gradient-picker/index.cjs.map +2 -2
  21. package/build/custom-select-control/index.cjs.map +3 -3
  22. package/build/custom-select-control-v2/custom-select.cjs +2 -2
  23. package/build/custom-select-control-v2/custom-select.cjs.map +2 -2
  24. package/build/custom-select-control-v2/index.cjs.map +3 -3
  25. package/build/date-time/{date → date-picker}/index.cjs +6 -6
  26. package/build/date-time/{date → date-picker}/index.cjs.map +2 -2
  27. package/build/date-time/{date → date-picker}/styles.cjs +17 -17
  28. package/build/date-time/{date → date-picker}/styles.cjs.map +2 -2
  29. package/build/date-time/{date → date-picker}/use-lilius/index.cjs +1 -1
  30. package/build/date-time/{date → date-picker}/use-lilius/index.cjs.map +1 -1
  31. package/build/date-time/date-time/index.cjs +6 -6
  32. package/build/date-time/date-time/index.cjs.map +2 -2
  33. package/build/date-time/index.cjs +4 -4
  34. package/build/date-time/index.cjs.map +2 -2
  35. package/build/date-time/{time → time-picker}/index.cjs +6 -6
  36. package/build/date-time/time-picker/index.cjs.map +7 -0
  37. package/build/date-time/{time → time-picker}/styles.cjs +21 -21
  38. package/build/date-time/{time → time-picker}/styles.cjs.map +2 -2
  39. package/build/date-time/{time → time-picker}/time-input/index.cjs +1 -1
  40. package/build/date-time/{time → time-picker}/time-input/index.cjs.map +1 -1
  41. package/build/date-time/{time → time-picker}/timezone.cjs +1 -1
  42. package/build/date-time/{time → time-picker}/timezone.cjs.map +1 -1
  43. package/build/modal/index.cjs.map +2 -2
  44. package/build/palette-edit/index.cjs.map +2 -2
  45. package/build/radio-control/index.cjs +2 -0
  46. package/build/radio-control/index.cjs.map +2 -2
  47. package/build/sandbox/index.cjs +127 -3
  48. package/build/sandbox/index.cjs.map +2 -2
  49. package/build/textarea-control/styles/textarea-control-styles.cjs +3 -3
  50. package/build/textarea-control/styles/textarea-control-styles.cjs.map +2 -2
  51. package/build/validated-form-controls/control-with-error.cjs +12 -8
  52. package/build/validated-form-controls/control-with-error.cjs.map +2 -2
  53. package/build-module/alignment-matrix-control/cell.mjs +3 -3
  54. package/build-module/alignment-matrix-control/cell.mjs.map +2 -2
  55. package/build-module/alignment-matrix-control/index.mjs +3 -3
  56. package/build-module/alignment-matrix-control/index.mjs.map +2 -2
  57. package/build-module/autocomplete/autocompleter-ui.mjs +74 -78
  58. package/build-module/autocomplete/autocompleter-ui.mjs.map +2 -2
  59. package/build-module/autocomplete/get-autocomplete-match.mjs +56 -0
  60. package/build-module/autocomplete/get-autocomplete-match.mjs.map +7 -0
  61. package/build-module/autocomplete/index.mjs +103 -107
  62. package/build-module/autocomplete/index.mjs.map +3 -3
  63. package/build-module/box-control/index.mjs +1 -9
  64. package/build-module/box-control/index.mjs.map +2 -2
  65. package/build-module/box-control/utils.mjs +1 -9
  66. package/build-module/box-control/utils.mjs.map +2 -2
  67. package/build-module/calendar/utils/use-localization-props.mjs +3 -2
  68. package/build-module/calendar/utils/use-localization-props.mjs.map +2 -2
  69. package/build-module/custom-gradient-picker/index.mjs.map +2 -2
  70. package/build-module/custom-select-control/index.mjs +2 -2
  71. package/build-module/custom-select-control/index.mjs.map +2 -2
  72. package/build-module/custom-select-control-v2/custom-select.mjs +2 -2
  73. package/build-module/custom-select-control-v2/custom-select.mjs.map +2 -2
  74. package/build-module/custom-select-control-v2/index.mjs +2 -2
  75. package/build-module/custom-select-control-v2/index.mjs.map +2 -2
  76. package/build-module/date-time/{date → date-picker}/index.mjs +3 -3
  77. package/build-module/date-time/{date → date-picker}/index.mjs.map +2 -2
  78. package/build-module/date-time/{date → date-picker}/styles.mjs +17 -17
  79. package/build-module/date-time/{date → date-picker}/styles.mjs.map +2 -2
  80. package/build-module/date-time/{date → date-picker}/use-lilius/index.mjs +1 -1
  81. package/build-module/date-time/{date → date-picker}/use-lilius/index.mjs.map +1 -1
  82. package/build-module/date-time/date-time/index.mjs +2 -2
  83. package/build-module/date-time/date-time/index.mjs.map +1 -1
  84. package/build-module/date-time/index.mjs +2 -2
  85. package/build-module/date-time/index.mjs.map +1 -1
  86. package/build-module/date-time/{time → time-picker}/index.mjs +3 -3
  87. package/build-module/date-time/time-picker/index.mjs.map +7 -0
  88. package/build-module/date-time/{time → time-picker}/styles.mjs +21 -21
  89. package/build-module/date-time/{time → time-picker}/styles.mjs.map +2 -2
  90. package/build-module/date-time/{time → time-picker}/time-input/index.mjs +1 -1
  91. package/build-module/date-time/{time → time-picker}/time-input/index.mjs.map +1 -1
  92. package/build-module/date-time/{time → time-picker}/timezone.mjs +1 -1
  93. package/build-module/date-time/{time → time-picker}/timezone.mjs.map +1 -1
  94. package/build-module/modal/index.mjs.map +2 -2
  95. package/build-module/palette-edit/index.mjs.map +2 -2
  96. package/build-module/radio-control/index.mjs +2 -0
  97. package/build-module/radio-control/index.mjs.map +2 -2
  98. package/build-module/sandbox/index.mjs +128 -4
  99. package/build-module/sandbox/index.mjs.map +2 -2
  100. package/build-module/textarea-control/styles/textarea-control-styles.mjs +3 -3
  101. package/build-module/textarea-control/styles/textarea-control-styles.mjs.map +2 -2
  102. package/build-module/validated-form-controls/control-with-error.mjs +12 -8
  103. package/build-module/validated-form-controls/control-with-error.mjs.map +2 -2
  104. package/build-style/style-rtl.css +83 -26
  105. package/build-style/style.css +83 -26
  106. package/build-types/autocomplete/autocompleter-ui.d.ts +2 -2
  107. package/build-types/autocomplete/autocompleter-ui.d.ts.map +1 -1
  108. package/build-types/autocomplete/get-autocomplete-match.d.ts +11 -0
  109. package/build-types/autocomplete/get-autocomplete-match.d.ts.map +1 -0
  110. package/build-types/autocomplete/index.d.ts +8 -0
  111. package/build-types/autocomplete/index.d.ts.map +1 -1
  112. package/build-types/autocomplete/test/get-autocomplete-match.d.ts +2 -0
  113. package/build-types/autocomplete/test/get-autocomplete-match.d.ts.map +1 -0
  114. package/build-types/autocomplete/types.d.ts +23 -9
  115. package/build-types/autocomplete/types.d.ts.map +1 -1
  116. package/build-types/box-control/index.d.ts.map +1 -1
  117. package/build-types/box-control/utils.d.ts +7 -16
  118. package/build-types/box-control/utils.d.ts.map +1 -1
  119. package/build-types/button/stories/index.story.d.ts +0 -1
  120. package/build-types/button/stories/index.story.d.ts.map +1 -1
  121. package/build-types/calendar/utils/use-localization-props.d.ts +3 -3
  122. package/build-types/calendar/utils/use-localization-props.d.ts.map +1 -1
  123. package/build-types/checkbox-control/types.d.ts +4 -0
  124. package/build-types/checkbox-control/types.d.ts.map +1 -1
  125. package/build-types/custom-gradient-picker/constants.d.ts +2 -2
  126. package/build-types/custom-gradient-picker/index.d.ts.map +1 -1
  127. package/build-types/custom-select-control-v2/custom-select.d.ts +3 -3
  128. package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -1
  129. package/build-types/custom-select-control-v2/types.d.ts +1 -1
  130. package/build-types/custom-select-control-v2/types.d.ts.map +1 -1
  131. package/build-types/date-time/date-picker/index.d.ts.map +1 -0
  132. package/build-types/date-time/date-picker/styles.d.ts.map +1 -0
  133. package/build-types/date-time/date-picker/test/index.d.ts.map +1 -0
  134. package/build-types/date-time/date-picker/test/use-lilius.d.ts.map +1 -0
  135. package/build-types/date-time/date-picker/use-lilius/index.d.ts.map +1 -0
  136. package/build-types/date-time/date-time/index.d.ts +2 -2
  137. package/build-types/date-time/date-time/index.d.ts.map +1 -1
  138. package/build-types/date-time/index.d.ts +2 -2
  139. package/build-types/date-time/index.d.ts.map +1 -1
  140. package/build-types/date-time/stories/date.story.d.ts +1 -1
  141. package/build-types/date-time/stories/date.story.d.ts.map +1 -1
  142. package/build-types/date-time/stories/time.story.d.ts +1 -1
  143. package/build-types/date-time/stories/time.story.d.ts.map +1 -1
  144. package/build-types/date-time/{time → time-picker}/index.d.ts +1 -1
  145. package/build-types/date-time/time-picker/index.d.ts.map +1 -0
  146. package/build-types/date-time/time-picker/styles.d.ts.map +1 -0
  147. package/build-types/date-time/time-picker/test/index.d.ts.map +1 -0
  148. package/build-types/date-time/time-picker/time-input/index.d.ts.map +1 -0
  149. package/build-types/date-time/time-picker/time-input/test/index.d.ts.map +1 -0
  150. package/build-types/date-time/time-picker/timezone.d.ts.map +1 -0
  151. package/build-types/date-time/types.d.ts +1 -1
  152. package/build-types/date-time/types.d.ts.map +1 -1
  153. package/build-types/font-size-picker/constants.d.ts +2 -2
  154. package/build-types/font-size-picker/constants.d.ts.map +1 -1
  155. package/build-types/modal/index.d.ts.map +1 -1
  156. package/build-types/palette-edit/index.d.ts +1 -1
  157. package/build-types/palette-edit/index.d.ts.map +1 -1
  158. package/build-types/radio-control/index.d.ts.map +1 -1
  159. package/build-types/radio-control/types.d.ts +6 -0
  160. package/build-types/radio-control/types.d.ts.map +1 -1
  161. package/build-types/sandbox/index.d.ts +1 -1
  162. package/build-types/sandbox/index.d.ts.map +1 -1
  163. package/build-types/sandbox/types.d.ts +11 -0
  164. package/build-types/sandbox/types.d.ts.map +1 -1
  165. package/build-types/textarea-control/stories/index.story.d.ts.map +1 -1
  166. package/build-types/textarea-control/styles/textarea-control-styles.d.ts.map +1 -1
  167. package/build-types/validated-form-controls/components/checkbox-control.d.ts +2 -1
  168. package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -1
  169. package/build-types/validated-form-controls/components/radio-control.d.ts +2 -1
  170. package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -1
  171. package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -1
  172. package/package.json +21 -21
  173. package/src/alignment-matrix-control/README.md +1 -1
  174. package/src/alignment-matrix-control/style.module.scss +1 -1
  175. package/src/angle-picker-control/style.module.scss +1 -0
  176. package/src/autocomplete/README.md +2 -2
  177. package/src/autocomplete/autocompleter-ui.native.js +166 -173
  178. package/src/autocomplete/autocompleter-ui.tsx +114 -116
  179. package/src/autocomplete/get-autocomplete-match.ts +115 -0
  180. package/src/autocomplete/index.tsx +129 -208
  181. package/src/autocomplete/test/get-autocomplete-match.ts +338 -0
  182. package/src/autocomplete/test/index.tsx +112 -4
  183. package/src/autocomplete/types.ts +17 -10
  184. package/src/box-control/index.tsx +1 -19
  185. package/src/box-control/utils.ts +1 -19
  186. package/src/button/README.md +1 -1
  187. package/src/button/stories/index.story.tsx +0 -1
  188. package/src/button/style.scss +1 -7
  189. package/src/calendar/style.scss +3 -3
  190. package/src/calendar/utils/use-localization-props.ts +3 -4
  191. package/src/checkbox-control/style.scss +17 -5
  192. package/src/checkbox-control/types.ts +4 -0
  193. package/src/circular-option-picker/style.scss +1 -1
  194. package/src/color-palette/style.scss +1 -1
  195. package/src/css.d.ts +1 -0
  196. package/src/custom-gradient-picker/index.tsx +1 -0
  197. package/src/custom-select-control/index.tsx +3 -3
  198. package/src/custom-select-control-v2/custom-select.tsx +4 -4
  199. package/src/custom-select-control-v2/index.tsx +2 -2
  200. package/src/custom-select-control-v2/types.ts +1 -1
  201. package/src/date-time/README.md +3 -3
  202. package/src/date-time/date-picker/README.md +65 -0
  203. package/src/date-time/date-time/index.tsx +2 -2
  204. package/src/date-time/index.ts +2 -2
  205. package/src/date-time/stories/date.story.tsx +1 -1
  206. package/src/date-time/stories/time.story.tsx +1 -1
  207. package/src/date-time/time-picker/README.md +119 -0
  208. package/src/date-time/{time → time-picker}/index.tsx +1 -1
  209. package/src/date-time/types.ts +1 -1
  210. package/src/divider/README.md +5 -6
  211. package/src/dropdown-menu/style.scss +1 -1
  212. package/src/flex/stories/index.story.tsx +1 -1
  213. package/src/form-file-upload/README.md +3 -3
  214. package/src/form-toggle/style.scss +35 -2
  215. package/src/form-token-field/style.scss +12 -3
  216. package/src/gradient-picker/README.md +2 -2
  217. package/src/h-stack/README.md +10 -15
  218. package/src/h-stack/stories/index.story.tsx +2 -2
  219. package/src/heading/stories/index.story.tsx +1 -1
  220. package/src/higher-order/with-focus-outside/index.native.js +21 -20
  221. package/src/icon/README.md +1 -1
  222. package/src/menu/README.md +2 -2
  223. package/src/mobile/utils/get-px-from-css-unit.native.js +1 -1
  224. package/src/modal/index.tsx +1 -0
  225. package/src/palette-edit/index.tsx +1 -0
  226. package/src/radio-control/index.tsx +2 -0
  227. package/src/radio-control/style.scss +21 -2
  228. package/src/radio-control/test/index.tsx +10 -0
  229. package/src/radio-control/types.ts +6 -0
  230. package/src/sandbox/index.native.js +2 -2
  231. package/src/sandbox/index.tsx +191 -11
  232. package/src/sandbox/test/index.tsx +65 -24
  233. package/src/sandbox/types.ts +11 -0
  234. package/src/snackbar/style.scss +2 -2
  235. package/src/tab-panel/style.scss +1 -1
  236. package/src/tabs/README.md +6 -6
  237. package/src/text/stories/index.story.tsx +1 -1
  238. package/src/textarea-control/stories/index.story.tsx +3 -0
  239. package/src/textarea-control/styles/textarea-control-styles.ts +6 -0
  240. package/src/toggle-control/style.scss +1 -1
  241. package/src/toggle-control/test/index.tsx +8 -2
  242. package/src/toolbar/toolbar-button/toolbar-button-container.native.js +3 -1
  243. package/src/tree-select/README.md +1 -1
  244. package/src/v-stack/README.md +10 -15
  245. package/src/v-stack/stories/index.story.tsx +2 -2
  246. package/src/validated-form-controls/control-with-error.tsx +17 -12
  247. package/src/validated-form-controls/test/control-with-error.tsx +28 -1
  248. package/src/view/README.md +2 -5
  249. package/build/date-time/time/index.cjs.map +0 -7
  250. package/build-module/date-time/time/index.mjs.map +0 -7
  251. package/build-types/date-time/date/index.d.ts.map +0 -1
  252. package/build-types/date-time/date/styles.d.ts.map +0 -1
  253. package/build-types/date-time/date/test/index.d.ts.map +0 -1
  254. package/build-types/date-time/date/test/use-lilius.d.ts.map +0 -1
  255. package/build-types/date-time/date/use-lilius/index.d.ts.map +0 -1
  256. package/build-types/date-time/time/index.d.ts.map +0 -1
  257. package/build-types/date-time/time/styles.d.ts.map +0 -1
  258. package/build-types/date-time/time/test/index.d.ts.map +0 -1
  259. package/build-types/date-time/time/time-input/index.d.ts.map +0 -1
  260. package/build-types/date-time/time/time-input/test/index.d.ts.map +0 -1
  261. package/build-types/date-time/time/timezone.d.ts.map +0 -1
  262. package/src/button/stories/style.css +0 -8
  263. /package/build-types/date-time/{date → date-picker}/index.d.ts +0 -0
  264. /package/build-types/date-time/{date → date-picker}/styles.d.ts +0 -0
  265. /package/build-types/date-time/{date → date-picker}/test/index.d.ts +0 -0
  266. /package/build-types/date-time/{date → date-picker}/test/use-lilius.d.ts +0 -0
  267. /package/build-types/date-time/{date → date-picker}/use-lilius/index.d.ts +0 -0
  268. /package/build-types/date-time/{time → time-picker}/styles.d.ts +0 -0
  269. /package/build-types/date-time/{time → time-picker}/test/index.d.ts +0 -0
  270. /package/build-types/date-time/{time → time-picker}/time-input/index.d.ts +0 -0
  271. /package/build-types/date-time/{time → time-picker}/time-input/test/index.d.ts +0 -0
  272. /package/build-types/date-time/{time → time-picker}/timezone.d.ts +0 -0
  273. /package/src/date-time/{date → date-picker}/index.tsx +0 -0
  274. /package/src/date-time/{date → date-picker}/styles.ts +0 -0
  275. /package/src/date-time/{date → date-picker}/test/index.tsx +0 -0
  276. /package/src/date-time/{date → date-picker}/test/use-lilius.ts +0 -0
  277. /package/src/date-time/{date → date-picker}/use-lilius/index.ts +0 -0
  278. /package/src/date-time/{time → time-picker}/styles.ts +0 -0
  279. /package/src/date-time/{time → time-picker}/test/index.tsx +0 -0
  280. /package/src/date-time/{time → time-picker}/time-input/index.tsx +0 -0
  281. /package/src/date-time/{time → time-picker}/time-input/test/index.tsx +0 -0
  282. /package/src/date-time/{time → time-picker}/timezone.tsx +0 -0
@@ -11,17 +11,14 @@ This feature is still experimental. “Experimental” means this is an early im
11
11
  `HStack` can render anything inside.
12
12
 
13
13
  ```jsx
14
- import {
15
- __experimentalHStack as HStack,
16
- __experimentalText as Text,
17
- } from '@wordpress/components';
14
+ import { __experimentalHStack as HStack } from '@wordpress/components';
18
15
 
19
16
  function Example() {
20
17
  return (
21
18
  <HStack>
22
- <Text>Code</Text>
23
- <Text>is</Text>
24
- <Text>Poetry</Text>
19
+ <span>Code</span>
20
+ <span>is</span>
21
+ <span>Poetry</span>
25
22
  </HStack>
26
23
  );
27
24
  }
@@ -87,17 +84,16 @@ When a `Spacer` is used within an `HStack`, the `Spacer` adaptively expands to t
87
84
  import {
88
85
  __experimentalHStack as HStack,
89
86
  __experimentalSpacer as Spacer,
90
- __experimentalText as Text,
91
87
  } from '@wordpress/components';
92
88
 
93
89
  function Example() {
94
90
  return (
95
91
  <HStack>
96
- <Text>Code</Text>
92
+ <span>Code</span>
97
93
  <Spacer>
98
- <Text>is</Text>
94
+ <span>is</span>
99
95
  </Spacer>
100
- <Text>Poetry</Text>
96
+ <span>Poetry</span>
101
97
  </HStack>
102
98
  );
103
99
  }
@@ -109,16 +105,15 @@ function Example() {
109
105
  import {
110
106
  __experimentalHStack as HStack,
111
107
  __experimentalSpacer as Spacer,
112
- __experimentalText as Text,
113
108
  } from '@wordpress/components';
114
109
 
115
110
  function Example() {
116
111
  return (
117
112
  <HStack>
118
- <Text>Code</Text>
113
+ <span>Code</span>
119
114
  <Spacer />
120
- <Text>is</Text>
121
- <Text>Poetry</Text>
115
+ <span>is</span>
116
+ <span>Poetry</span>
122
117
  </HStack>
123
118
  );
124
119
  }
@@ -75,9 +75,9 @@ const meta: Meta< typeof HStack > = {
75
75
  controls: { expanded: true },
76
76
  docs: { canvas: { sourceState: 'shown' } },
77
77
  componentStatus: {
78
- status: 'stable',
78
+ status: 'not-recommended',
79
79
  whereUsed: 'global',
80
- notes: 'Will be superseded by `Stack` in `@wordpress/ui`, but continue using for now.',
80
+ notes: 'Use `Stack` from `@wordpress/ui` instead.',
81
81
  },
82
82
  },
83
83
  };
@@ -32,7 +32,7 @@ const meta: Meta< typeof Heading > = {
32
32
  componentStatus: {
33
33
  status: 'not-recommended',
34
34
  whereUsed: 'global',
35
- notes: 'Values are not aligned with the current design system. Use [typography tokens](?path=/docs/tokens-typography--page) from `@wordpress/base-styles` instead.',
35
+ notes: 'Use `Text` from `@wordpress/ui` instead, with the `render` prop set to the heading level element and the variant set to the visual heading size (e.g. `<Text render={ <h1 /> } variant="heading-2xl">`).',
36
36
  },
37
37
  },
38
38
  };
@@ -12,26 +12,27 @@ import {
12
12
  } from '@wordpress/compose';
13
13
 
14
14
  export default createHigherOrderComponent(
15
- ( WrappedComponent ) => ( props ) => {
16
- const [ handleFocusOutside, setHandleFocusOutside ] = useState();
17
- const bindFocusOutsideHandler = useCallback(
18
- ( node ) =>
19
- setHandleFocusOutside( () =>
20
- node?.handleFocusOutside
21
- ? node.handleFocusOutside.bind( node )
22
- : undefined
23
- ),
24
- []
25
- );
15
+ ( WrappedComponent ) =>
16
+ function WithFocusOutside( props ) {
17
+ const [ handleFocusOutside, setHandleFocusOutside ] = useState();
18
+ const bindFocusOutsideHandler = useCallback(
19
+ ( node ) =>
20
+ setHandleFocusOutside( () =>
21
+ node?.handleFocusOutside
22
+ ? node.handleFocusOutside.bind( node )
23
+ : undefined
24
+ ),
25
+ []
26
+ );
26
27
 
27
- return (
28
- <View { ...useFocusOutside( handleFocusOutside ) }>
29
- <WrappedComponent
30
- ref={ bindFocusOutsideHandler }
31
- { ...props }
32
- />
33
- </View>
34
- );
35
- },
28
+ return (
29
+ <View { ...useFocusOutside( handleFocusOutside ) }>
30
+ <WrappedComponent
31
+ ref={ bindFocusOutsideHandler }
32
+ { ...props }
33
+ />
34
+ </View>
35
+ );
36
+ },
36
37
  'withFocusOutside'
37
38
  );
@@ -16,7 +16,7 @@ import { wordpress } from '@wordpress/icons';
16
16
 
17
17
  ### `icon`
18
18
 
19
- - Type: `IconType`
19
+ - Type: `IconType | null`
20
20
  - Required: No
21
21
  - Default: `null`
22
22
 
@@ -19,7 +19,7 @@ component, and the `Menu.Popover` component.
19
19
 
20
20
  ### `as`
21
21
 
22
- - Type: `"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | ... 516 more ... | ("view" & FunctionComponent<...>)`
22
+ - Type: `"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | ... 517 more ...`
23
23
  - Required: No
24
24
 
25
25
  The HTML element or React component to render the component as.
@@ -57,7 +57,7 @@ override the `defaultOpen` prop.
57
57
 
58
58
  ### `onOpenChange`
59
59
 
60
- - Type: `(open: boolean) => void`
60
+ - Type: `((open: boolean) => void)`
61
61
  - Required: No
62
62
 
63
63
  A callback that gets called when the `open` state changes.
@@ -26,7 +26,7 @@ function parseUnit( cssUnit ) {
26
26
  function calculate( expression ) {
27
27
  try {
28
28
  return Function( `'use strict'; return (${ expression })` )();
29
- } catch ( err ) {
29
+ } catch {
30
30
  return null;
31
31
  }
32
32
  }
@@ -121,6 +121,7 @@ function UnforwardedModal(
121
121
  const onRequestCloseRef =
122
122
  useRef< ModalProps[ 'onRequestClose' ] >( undefined );
123
123
  useEffect( () => {
124
+ // eslint-disable-next-line react-compiler/react-compiler -- false positive, see https://github.com/facebook/react/issues/29196
124
125
  onRequestCloseRef.current = onRequestClose;
125
126
  }, [ onRequestClose ] );
126
127
 
@@ -299,6 +299,7 @@ function PaletteEditListView< T extends PaletteElement >( {
299
299
  // When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.
300
300
  const elementsReferenceRef = useRef< T[] >( undefined );
301
301
  useEffect( () => {
302
+ // eslint-disable-next-line react-compiler/react-compiler -- false positive, see https://github.com/facebook/react/issues/29196
302
303
  elementsReferenceRef.current = elements;
303
304
  }, [ elements ] );
304
305
 
@@ -67,6 +67,7 @@ export function RadioControl(
67
67
  onChange,
68
68
  onClick,
69
69
  hideLabelFromVision,
70
+ disabled,
70
71
  options = [],
71
72
  id: preferredId,
72
73
  ...additionalProps
@@ -89,6 +90,7 @@ export function RadioControl(
89
90
  id={ id }
90
91
  role="radiogroup"
91
92
  className={ clsx( className, 'components-radio-control' ) }
93
+ disabled={ disabled }
92
94
  aria-describedby={ !! help ? generateHelpId( id ) : undefined }
93
95
  >
94
96
  { hideLabelFromVision ? (
@@ -10,6 +10,7 @@
10
10
 
11
11
  font-family: $default-font;
12
12
  font-size: $default-font-size;
13
+
13
14
  }
14
15
 
15
16
  .components-radio-control__group-wrapper.has-help {
@@ -34,7 +35,10 @@
34
35
  margin: 0;
35
36
  padding: 0;
36
37
  appearance: none;
37
- cursor: pointer;
38
+
39
+ &:not(:disabled) {
40
+ cursor: var(--wpds-cursor-control);
41
+ }
38
42
 
39
43
  &:focus {
40
44
  @include button-style-outset__focus(var(--wp-admin-theme-color));
@@ -49,13 +53,28 @@
49
53
  border-radius: $radius-round;
50
54
  }
51
55
  }
56
+
57
+ &:disabled {
58
+ background: $components-color-gray-100;
59
+ border: 1px solid $components-color-gray-300;
60
+ opacity: 1; // Override style from wp-admin forms.css.
61
+
62
+ &:checked::before {
63
+ border-color: $components-color-gray-400;
64
+ opacity: 1; // Override style from wp-admin forms.css.
65
+
66
+ }
67
+ }
52
68
  }
53
69
 
54
70
  .components-radio-control__label {
55
71
  grid-column: 2;
56
72
  grid-row: 1;
57
73
 
58
- cursor: pointer;
74
+ .components-radio-control:not(:disabled) & {
75
+ cursor: var(--wpds-cursor-control);
76
+ }
77
+
59
78
  line-height: $radio-input-size-sm;
60
79
 
61
80
  @include break-small() {
@@ -82,6 +82,16 @@ describe.each( [
82
82
  ).toBeVisible();
83
83
  } );
84
84
 
85
+ it( 'should disable the radio group when `disabled` is true', () => {
86
+ render(
87
+ <Component { ...defaultProps } disabled onChange={ () => {} } />
88
+ );
89
+
90
+ expect(
91
+ screen.getByRole( 'radiogroup', { name: defaultProps.label } )
92
+ ).toBeDisabled();
93
+ } );
94
+
85
95
  it( 'should describe the radio group with the help text', () => {
86
96
  const onChangeSpy = jest.fn();
87
97
  render(
@@ -7,6 +7,12 @@ export type RadioControlProps = Pick<
7
7
  BaseControlProps,
8
8
  'label' | 'help' | 'hideLabelFromVision'
9
9
  > & {
10
+ /**
11
+ * Whether the radio group should be disabled.
12
+ *
13
+ * @default false
14
+ */
15
+ disabled?: boolean;
10
16
  /**
11
17
  * A function that receives the value of the new option that is being
12
18
  * selected as input.
@@ -172,7 +172,7 @@ const style = `
172
172
 
173
173
  const EMPTY_ARRAY = [];
174
174
 
175
- const Sandbox = forwardRef( function Sandbox(
175
+ const Sandbox = forwardRef( function UnforwardedSandbox(
176
176
  {
177
177
  containerStyle,
178
178
  customJS,
@@ -297,7 +297,7 @@ const Sandbox = forwardRef( function Sandbox(
297
297
 
298
298
  try {
299
299
  data = JSON.parse( data );
300
- } catch ( e ) {
300
+ } catch {
301
301
  return;
302
302
  }
303
303
 
@@ -6,6 +6,7 @@ import {
6
6
  useRef,
7
7
  useState,
8
8
  useEffect,
9
+ useMemo,
9
10
  } from '@wordpress/element';
10
11
  import { useFocusableIframe, useMergeRefs } from '@wordpress/compose';
11
12
 
@@ -14,6 +15,8 @@ import { useFocusableIframe, useMergeRefs } from '@wordpress/compose';
14
15
  */
15
16
  import type { SandBoxProps } from './types';
16
17
 
18
+ type SandBoxContentProps = Omit< SandBoxProps, 'allowSameOrigin' >;
19
+
17
20
  const observeAndResizeJS = function () {
18
21
  const { MutationObserver } = window;
19
22
 
@@ -115,17 +118,176 @@ const style = `
115
118
  `;
116
119
 
117
120
  /**
118
- * This component provides an isolated environment for arbitrary HTML via iframes.
121
+ * Builds the full HTML document string for the sandbox iframe content.
122
+ */
123
+ function buildSandBoxDocument( {
124
+ html,
125
+ title,
126
+ type,
127
+ styles,
128
+ scripts,
129
+ }: {
130
+ html: string;
131
+ title: string;
132
+ type?: string;
133
+ styles: string[];
134
+ scripts: string[];
135
+ } ): string {
136
+ const htmlDoc = (
137
+ <html lang={ document.documentElement.lang } className={ type }>
138
+ <head>
139
+ <title>{ title }</title>
140
+ <style dangerouslySetInnerHTML={ { __html: style } } />
141
+ { styles.map( ( rules, i ) => (
142
+ <style
143
+ key={ i }
144
+ dangerouslySetInnerHTML={ { __html: rules } }
145
+ />
146
+ ) ) }
147
+ </head>
148
+ <body
149
+ data-resizable-iframe-connected="data-resizable-iframe-connected"
150
+ className={ type }
151
+ >
152
+ <div dangerouslySetInnerHTML={ { __html: html } } />
153
+ <script
154
+ type="text/javascript"
155
+ dangerouslySetInnerHTML={ {
156
+ __html: `(${ observeAndResizeJS.toString() })();`,
157
+ } }
158
+ />
159
+ { scripts.map( ( src ) => (
160
+ <script key={ src } src={ src } />
161
+ ) ) }
162
+ </body>
163
+ </html>
164
+ );
165
+
166
+ return '<!DOCTYPE html>' + renderToString( htmlDoc );
167
+ }
168
+
169
+ /**
170
+ * Isolated sandbox that uses the `srcdoc` attribute to render content
171
+ * without `allow-same-origin`. This is the default for user-controlled
172
+ * content (e.g., the HTML block) where same-origin access would be a
173
+ * security risk.
119
174
  *
120
- * ```jsx
121
- * import { SandBox } from '@wordpress/components';
175
+ * Because `srcdoc` is a declarative attribute, the browser automatically
176
+ * re-renders the content when the iframe is moved in the DOM (e.g.,
177
+ * block reordering), so no `load` event listener is needed.
178
+ * The `message` listener is re-synced on every `load` so
179
+ * it follows the iframe if it's reparented into a different document.
180
+ */
181
+ function IsolatedSandBox( {
182
+ html = '',
183
+ title = '',
184
+ type,
185
+ styles = [],
186
+ scripts = [],
187
+ onFocus,
188
+ tabIndex,
189
+ }: SandBoxContentProps ) {
190
+ const ref = useRef< HTMLIFrameElement >( null );
191
+ const [ width, setWidth ] = useState( 0 );
192
+ const [ height, setHeight ] = useState( 0 );
193
+
194
+ const srcDoc = useMemo(
195
+ () => buildSandBoxDocument( { html, title, type, styles, scripts } ),
196
+ [ html, title, type, styles, scripts ]
197
+ );
198
+
199
+ useEffect( () => {
200
+ const iframe = ref.current;
201
+ if ( ! iframe ) {
202
+ return;
203
+ }
204
+
205
+ function checkMessageForResize( event: MessageEvent ) {
206
+ // Verify that the mounted element is the source of the message.
207
+ // iframe.contentWindow is accessible cross-origin as a
208
+ // WindowProxy reference, so this check still works without
209
+ // allow-same-origin.
210
+ if ( ! iframe || iframe.contentWindow !== event.source ) {
211
+ return;
212
+ }
213
+
214
+ // Attempt to parse the message data as JSON if passed as string.
215
+ let data = event.data || {};
216
+
217
+ if ( 'string' === typeof data ) {
218
+ try {
219
+ data = JSON.parse( data );
220
+ } catch {}
221
+ }
222
+
223
+ // Update the state only if the message is formatted as we expect,
224
+ // i.e. as an object with a 'resize' action.
225
+ if ( 'resize' !== data.action ) {
226
+ return;
227
+ }
228
+
229
+ setWidth( data.width );
230
+ setHeight( data.height );
231
+ }
232
+
233
+ let currentView: Window | null = null;
234
+ function syncListener() {
235
+ const view = iframe?.ownerDocument?.defaultView ?? null;
236
+ if ( view === currentView ) {
237
+ return;
238
+ }
239
+
240
+ currentView?.removeEventListener(
241
+ 'message',
242
+ checkMessageForResize
243
+ );
244
+
245
+ currentView = view;
246
+ currentView?.addEventListener( 'message', checkMessageForResize );
247
+ }
248
+
249
+ syncListener();
250
+ iframe.addEventListener( 'load', syncListener );
251
+
252
+ return () => {
253
+ iframe.removeEventListener( 'load', syncListener );
254
+ currentView?.removeEventListener(
255
+ 'message',
256
+ checkMessageForResize
257
+ );
258
+ };
259
+ }, [] );
260
+
261
+ return (
262
+ <iframe
263
+ ref={ useMergeRefs( [ ref, useFocusableIframe() ] ) }
264
+ title={ title }
265
+ tabIndex={ tabIndex }
266
+ className="components-sandbox"
267
+ sandbox="allow-scripts allow-presentation"
268
+ srcDoc={ srcDoc }
269
+ onFocus={ onFocus }
270
+ width={ Math.ceil( width ) }
271
+ height={ Math.ceil( height ) }
272
+ />
273
+ );
274
+ }
275
+
276
+ /**
277
+ * Same-origin sandbox that writes to `contentDocument` directly. This
278
+ * preserves the parent page's URL as the iframe's document URL, which
279
+ * provides a valid Referer header for nested iframes (required by
280
+ * providers like YouTube).
122
281
  *
123
- * const MySandBox = () => (
124
- * <SandBox html="<p>Content</p>" title="SandBox" type="embed" />
125
- * );
126
- * ```
282
+ * Only used when `allowSameOrigin` is true — i.e., for server-fetched
283
+ * oEmbed previews that are not directly user-controlled.
284
+ *
285
+ * This implementation is intentionally kept close to the original
286
+ * pre-refactor code to preserve past bugfixes:
287
+ * - load listener for iframe re-initialization after DOM moves (#21916)
288
+ * - forceRerender guard to avoid unnecessary full rewrites (#20176)
127
289
  */
128
- function SandBox( {
290
+ function SameOriginSandBox( {
129
291
  html = '',
130
292
  title = '',
131
293
  type,
@@ -133,7 +295,7 @@ function SandBox( {
133
295
  scripts = [],
134
296
  onFocus,
135
297
  tabIndex,
136
- }: SandBoxProps ) {
298
+ }: SandBoxContentProps ) {
137
299
  const ref = useRef< HTMLIFrameElement >( null );
138
300
  const [ width, setWidth ] = useState( 0 );
139
301
  const [ height, setHeight ] = useState( 0 );
@@ -141,7 +303,7 @@ function SandBox( {
141
303
  function isFrameAccessible() {
142
304
  try {
143
305
  return !! ref.current?.contentDocument?.body;
144
- } catch ( e ) {
306
+ } catch {
145
307
  return false;
146
308
  }
147
309
  }
@@ -232,7 +394,7 @@ function SandBox( {
232
394
  if ( 'string' === typeof data ) {
233
395
  try {
234
396
  data = JSON.parse( data );
235
- } catch ( e ) {}
397
+ } catch {}
236
398
  }
237
399
 
238
400
  // Update the state only if the message is formatted as we expect,
@@ -292,4 +454,22 @@ function SandBox( {
292
454
  );
293
455
  }
294
456
 
457
+ /**
458
+ * This component provides an isolated environment for arbitrary HTML via iframes.
459
+ *
460
+ * ```jsx
461
+ * import { SandBox } from '@wordpress/components';
462
+ *
463
+ * const MySandBox = () => (
464
+ * <SandBox html="<p>Content</p>" title="SandBox" type="embed" />
465
+ * );
466
+ * ```
467
+ */
468
+ function SandBox( { allowSameOrigin = false, ...contentProps }: SandBoxProps ) {
469
+ if ( allowSameOrigin ) {
470
+ return <SameOriginSandBox { ...contentProps } />;
471
+ }
472
+ return <IsolatedSandBox { ...contentProps } />;
473
+ }
474
+
295
475
  export default SandBox;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { fireEvent, render, screen, within } from '@testing-library/react';
4
+ import { fireEvent, render, screen } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -16,10 +16,7 @@ import SandBox from '..';
16
16
  describe( 'SandBox', () => {
17
17
  const TestWrapper = () => {
18
18
  const [ html, setHtml ] = useState(
19
- // MutationObserver implementation from JSDom does not work as intended
20
- // with iframes so we need to ignore it for the time being.
21
- '<script type="text/javascript">window.MutationObserver = null;</script>' +
22
- '<iframe title="Mock Iframe" src="https://super.embed"></iframe>'
19
+ '<iframe title="Mock Iframe" src="https://super.embed"></iframe>'
23
20
  );
24
21
 
25
22
  const updateHtml = () => {
@@ -38,34 +35,78 @@ describe( 'SandBox', () => {
38
35
  );
39
36
  };
40
37
 
41
- it( 'should rerender with new emdeded content if html prop changes', () => {
38
+ it( 'should not include allow-same-origin by default', () => {
39
+ render( <SandBox html="<p>Hello</p>" title="Test" /> );
40
+
41
+ const iframe = screen.getByTitle< HTMLIFrameElement >( 'Test' );
42
+
43
+ expect( iframe ).toHaveAttribute(
44
+ 'sandbox',
45
+ 'allow-scripts allow-presentation'
46
+ );
47
+ expect( iframe.getAttribute( 'sandbox' ) ).not.toContain(
48
+ 'allow-same-origin'
49
+ );
50
+ } );
51
+
52
+ it( 'should set srcdoc with the provided html content', () => {
53
+ render( <SandBox html="<p>Hello</p>" title="Test Title" /> );
54
+
55
+ const iframe = screen.getByTitle< HTMLIFrameElement >( 'Test Title' );
56
+ const srcDoc = iframe.getAttribute( 'srcdoc' ) ?? '';
57
+
58
+ expect( srcDoc ).toContain( '<p>Hello</p>' );
59
+ expect( srcDoc ).toContain( '<title>Test Title</title>' );
60
+ } );
61
+
62
+ it( 'should include custom styles in srcdoc', () => {
63
+ render(
64
+ <SandBox
65
+ html="<p>Styled</p>"
66
+ title="Styled Test"
67
+ styles={ [ '.custom { color: red; }' ] }
68
+ />
69
+ );
70
+
71
+ const iframe = screen.getByTitle< HTMLIFrameElement >( 'Styled Test' );
72
+ const srcDoc = iframe.getAttribute( 'srcdoc' ) ?? '';
73
+
74
+ expect( srcDoc ).toContain( '.custom { color: red; }' );
75
+ } );
76
+
77
+ it( 'should include script tags in srcdoc', () => {
78
+ render(
79
+ <SandBox
80
+ html="<p>Script</p>"
81
+ title="Script Test"
82
+ scripts={ [ 'https://example.com/embed.js' ] }
83
+ />
84
+ );
85
+
86
+ const iframe = screen.getByTitle< HTMLIFrameElement >( 'Script Test' );
87
+ const srcDoc = iframe.getAttribute( 'srcdoc' ) ?? '';
88
+
89
+ expect( srcDoc ).toContain(
90
+ '<script src="https://example.com/embed.js">'
91
+ );
92
+ } );
93
+
94
+ it( 'should update srcdoc when html prop changes', () => {
42
95
  render( <TestWrapper /> );
43
96
 
44
97
  const iframe =
45
98
  screen.getByTitle< HTMLIFrameElement >( 'SandBox Title' );
46
99
 
47
- if ( ! iframe.contentWindow ) {
48
- throw new Error();
49
- }
50
-
51
- let sandboxedIframe = within(
52
- iframe.contentWindow.document.body
53
- ).getByTitle( 'Mock Iframe' );
54
-
55
- expect( sandboxedIframe ).toHaveAttribute(
56
- 'src',
57
- 'https://super.embed'
100
+ expect( iframe ).toHaveAttribute(
101
+ 'srcdoc',
102
+ expect.stringContaining( 'https://super.embed' )
58
103
  );
59
104
 
60
105
  fireEvent.click( screen.getByRole( 'button' ) );
61
106
 
62
- sandboxedIframe = within(
63
- iframe.contentWindow.document.body
64
- ).getByTitle( 'Mock Iframe' );
65
-
66
- expect( sandboxedIframe ).toHaveAttribute(
67
- 'src',
68
- 'https://another.super.embed'
107
+ expect( iframe ).toHaveAttribute(
108
+ 'srcdoc',
109
+ expect.stringContaining( 'https://another.super.embed' )
69
110
  );
70
111
  } );
71
112
  } );