@wordpress/components 21.0.2 → 21.0.4

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 (43) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/build/combobox-control/index.js +0 -1
  3. package/build/combobox-control/index.js.map +1 -1
  4. package/build/form-token-field/token-input.js +20 -1
  5. package/build/form-token-field/token-input.js.map +1 -1
  6. package/build/popover/index.js +29 -32
  7. package/build/popover/index.js.map +1 -1
  8. package/build/popover/limit-shift.js +145 -0
  9. package/build/popover/limit-shift.js.map +1 -0
  10. package/build/toggle-group-control/toggle-group-control-option-base/styles.js +8 -8
  11. package/build/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  12. package/build/tree-grid/index.js +13 -8
  13. package/build/tree-grid/index.js.map +1 -1
  14. package/build-module/combobox-control/index.js +0 -1
  15. package/build-module/combobox-control/index.js.map +1 -1
  16. package/build-module/form-token-field/token-input.js +21 -2
  17. package/build-module/form-token-field/token-input.js.map +1 -1
  18. package/build-module/popover/index.js +31 -35
  19. package/build-module/popover/index.js.map +1 -1
  20. package/build-module/popover/limit-shift.js +136 -0
  21. package/build-module/popover/limit-shift.js.map +1 -0
  22. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js +7 -7
  23. package/build-module/toggle-group-control/toggle-group-control-option-base/styles.js.map +1 -1
  24. package/build-module/tree-grid/index.js +13 -8
  25. package/build-module/tree-grid/index.js.map +1 -1
  26. package/build-types/form-token-field/token-input.d.ts.map +1 -1
  27. package/build-types/popover/index.d.ts.map +1 -1
  28. package/build-types/popover/limit-shift.d.ts +87 -0
  29. package/build-types/popover/limit-shift.d.ts.map +1 -0
  30. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts +1 -1
  31. package/build-types/toggle-group-control/toggle-group-control-option-base/styles.d.ts.map +1 -1
  32. package/package.json +3 -3
  33. package/src/combobox-control/index.js +0 -5
  34. package/src/form-token-field/test/index.tsx +22 -1
  35. package/src/form-token-field/token-input.tsx +25 -3
  36. package/src/popover/index.tsx +26 -42
  37. package/src/popover/limit-shift.ts +205 -0
  38. package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +1 -0
  39. package/src/toggle-group-control/toggle-group-control-option-base/styles.ts +9 -7
  40. package/src/tree-grid/index.js +23 -14
  41. package/src/tree-grid/test/__snapshots__/cell.js.snap +21 -17
  42. package/src/tree-grid/test/__snapshots__/index.js.snap +1 -1
  43. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,205 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type {
5
+ Axis,
6
+ Coords,
7
+ Placement,
8
+ Side,
9
+ MiddlewareArguments,
10
+ } from '@floating-ui/react-dom';
11
+
12
+ /**
13
+ * Parts of this source were derived and modified from `floating-ui`,
14
+ * released under the MIT license.
15
+ *
16
+ * https://github.com/floating-ui/floating-ui
17
+ *
18
+ * Copyright (c) 2021 Floating UI contributors
19
+ *
20
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
21
+ * of this software and associated documentation files (the "Software"), to deal
22
+ * in the Software without restriction, including without limitation the rights
23
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ * copies of the Software, and to permit persons to whom the Software is
25
+ * furnished to do so, subject to the following conditions:
26
+ *
27
+ * The above copyright notice and this permission notice shall be included in all
28
+ * copies or substantial portions of the Software.
29
+ *
30
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36
+ * SOFTWARE.
37
+ */
38
+
39
+ /**
40
+ * Custom limiter function for the `shift` middleware.
41
+ * This function is mostly identical default `limitShift` from ``@floating-ui`;
42
+ * the only difference is that, when computing the min/max shift limits, it
43
+ * also takes into account the iframe offset that is added by the
44
+ * custom "frameOffset" middleware.
45
+ *
46
+ * All unexported types and functions are also from the `@floating-ui` library,
47
+ * and have been copied to this file for convenience.
48
+ */
49
+
50
+ type LimitShiftOffset =
51
+ | ( ( args: MiddlewareArguments ) =>
52
+ | number
53
+ | {
54
+ /**
55
+ * Offset the limiting of the axis that runs along the alignment of the
56
+ * floating element.
57
+ */
58
+ mainAxis?: number;
59
+ /**
60
+ * Offset the limiting of the axis that runs along the side of the
61
+ * floating element.
62
+ */
63
+ crossAxis?: number;
64
+ } )
65
+ | number
66
+ | {
67
+ /**
68
+ * Offset the limiting of the axis that runs along the alignment of the
69
+ * floating element.
70
+ */
71
+ mainAxis?: number;
72
+ /**
73
+ * Offset the limiting of the axis that runs along the side of the
74
+ * floating element.
75
+ */
76
+ crossAxis?: number;
77
+ };
78
+
79
+ type LimitShiftOptions = {
80
+ /**
81
+ * Offset when limiting starts. `0` will limit when the opposite edges of the
82
+ * reference and floating elements are aligned.
83
+ * - positive = start limiting earlier
84
+ * - negative = start limiting later
85
+ */
86
+ offset: LimitShiftOffset;
87
+ /**
88
+ * Whether to limit the axis that runs along the alignment of the floating
89
+ * element.
90
+ */
91
+ mainAxis: boolean;
92
+ /**
93
+ * Whether to limit the axis that runs along the side of the floating element.
94
+ */
95
+ crossAxis: boolean;
96
+ };
97
+
98
+ function getSide( placement: Placement ): Side {
99
+ return placement.split( '-' )[ 0 ] as Side;
100
+ }
101
+
102
+ function getMainAxisFromPlacement( placement: Placement ): Axis {
103
+ return [ 'top', 'bottom' ].includes( getSide( placement ) ) ? 'x' : 'y';
104
+ }
105
+
106
+ function getCrossAxis( axis: Axis ): Axis {
107
+ return axis === 'x' ? 'y' : 'x';
108
+ }
109
+
110
+ export const limitShift = (
111
+ options: Partial< LimitShiftOptions > = {}
112
+ ): {
113
+ options: Partial< LimitShiftOffset >;
114
+ fn: ( middlewareArguments: MiddlewareArguments ) => Coords;
115
+ } => ( {
116
+ options,
117
+ fn( middlewareArguments ) {
118
+ const { x, y, placement, rects, middlewareData } = middlewareArguments;
119
+ const {
120
+ offset = 0,
121
+ mainAxis: checkMainAxis = true,
122
+ crossAxis: checkCrossAxis = true,
123
+ } = options;
124
+
125
+ const coords = { x, y };
126
+ const mainAxis = getMainAxisFromPlacement( placement );
127
+ const crossAxis = getCrossAxis( mainAxis );
128
+
129
+ let mainAxisCoord = coords[ mainAxis ];
130
+ let crossAxisCoord = coords[ crossAxis ];
131
+
132
+ const rawOffset =
133
+ typeof offset === 'function'
134
+ ? offset( middlewareArguments )
135
+ : offset;
136
+ const computedOffset =
137
+ typeof rawOffset === 'number'
138
+ ? { mainAxis: rawOffset, crossAxis: 0 }
139
+ : { mainAxis: 0, crossAxis: 0, ...rawOffset };
140
+
141
+ // At the moment of writing, this is the only difference
142
+ // with the `limitShift` function from `@floating-ui`.
143
+ // This offset needs to be added to all min/max limits
144
+ // in order to make the shift-limiting work as expected.
145
+ const additionalFrameOffset = {
146
+ x: 0,
147
+ y: 0,
148
+ ...middlewareData.frameOffset?.amount,
149
+ };
150
+
151
+ if ( checkMainAxis ) {
152
+ const len = mainAxis === 'y' ? 'height' : 'width';
153
+ const limitMin =
154
+ rects.reference[ mainAxis ] -
155
+ rects.floating[ len ] +
156
+ computedOffset.mainAxis +
157
+ additionalFrameOffset[ mainAxis ];
158
+ const limitMax =
159
+ rects.reference[ mainAxis ] +
160
+ rects.reference[ len ] -
161
+ computedOffset.mainAxis +
162
+ additionalFrameOffset[ mainAxis ];
163
+
164
+ if ( mainAxisCoord < limitMin ) {
165
+ mainAxisCoord = limitMin;
166
+ } else if ( mainAxisCoord > limitMax ) {
167
+ mainAxisCoord = limitMax;
168
+ }
169
+ }
170
+
171
+ if ( checkCrossAxis ) {
172
+ const len = mainAxis === 'y' ? 'width' : 'height';
173
+ const isOriginSide = [ 'top', 'left' ].includes(
174
+ getSide( placement )
175
+ );
176
+ const limitMin =
177
+ rects.reference[ crossAxis ] -
178
+ rects.floating[ len ] +
179
+ ( isOriginSide
180
+ ? middlewareData.offset?.[ crossAxis ] ?? 0
181
+ : 0 ) +
182
+ ( isOriginSide ? 0 : computedOffset.crossAxis ) +
183
+ additionalFrameOffset[ crossAxis ];
184
+ const limitMax =
185
+ rects.reference[ crossAxis ] +
186
+ rects.reference[ len ] +
187
+ ( isOriginSide
188
+ ? 0
189
+ : middlewareData.offset?.[ crossAxis ] ?? 0 ) -
190
+ ( isOriginSide ? computedOffset.crossAxis : 0 ) +
191
+ additionalFrameOffset[ crossAxis ];
192
+
193
+ if ( crossAxisCoord < limitMin ) {
194
+ crossAxisCoord = limitMin;
195
+ } else if ( crossAxisCoord > limitMax ) {
196
+ crossAxisCoord = limitMax;
197
+ }
198
+ }
199
+
200
+ return {
201
+ [ mainAxis ]: mainAxisCoord,
202
+ [ crossAxis ]: crossAxisCoord,
203
+ } as Coords;
204
+ },
205
+ } );
@@ -159,6 +159,7 @@ exports[`ToggleGroupControl should render correctly with icons 1`] = `
159
159
  }
160
160
 
161
161
  .emotion-15 {
162
+ color: #1e1e1e;
162
163
  width: 30px;
163
164
  padding-left: 0;
164
165
  padding-right: 0;
@@ -55,13 +55,6 @@ export const buttonView = css`
55
55
  }
56
56
  `;
57
57
 
58
- export const buttonActive = css`
59
- color: ${ COLORS.white };
60
- &:active {
61
- background: transparent;
62
- }
63
- `;
64
-
65
58
  export const ButtonContentView = styled.div`
66
59
  font-size: ${ CONFIG.fontSize };
67
60
  line-height: 1;
@@ -82,8 +75,17 @@ export const isIcon = ( {
82
75
  };
83
76
 
84
77
  return css`
78
+ color: ${ COLORS.gray[ 900 ] };
85
79
  width: ${ iconButtonSizes[ size ] };
86
80
  padding-left: 0;
87
81
  padding-right: 0;
88
82
  `;
89
83
  };
84
+
85
+ export const buttonActive = css`
86
+ color: ${ COLORS.white };
87
+
88
+ &:active {
89
+ background: transparent;
90
+ }
91
+ `;
@@ -36,12 +36,13 @@ function getRowFocusables( rowElement ) {
36
36
  * Renders both a table and tbody element, used to create a tree hierarchy.
37
37
  *
38
38
  * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/components/src/tree-grid/README.md
39
- * @param {Object} props Component props.
40
- * @param {WPElement} props.children Children to be rendered.
41
- * @param {Function} props.onExpandRow Callback to fire when row is expanded.
42
- * @param {Function} props.onCollapseRow Callback to fire when row is collapsed.
43
- * @param {Function} props.onFocusRow Callback to fire when moving focus to a different row.
44
- * @param {Object} ref A ref to the underlying DOM table element.
39
+ * @param {Object} props Component props.
40
+ * @param {WPElement} props.children Children to be rendered.
41
+ * @param {Function} props.onExpandRow Callback to fire when row is expanded.
42
+ * @param {Function} props.onCollapseRow Callback to fire when row is collapsed.
43
+ * @param {Function} props.onFocusRow Callback to fire when moving focus to a different row.
44
+ * @param {string} props.applicationAriaLabel Label to use for the application role.
45
+ * @param {Object} ref A ref to the underlying DOM table element.
45
46
  */
46
47
  function TreeGrid(
47
48
  {
@@ -49,6 +50,7 @@ function TreeGrid(
49
50
  onExpandRow = () => {},
50
51
  onCollapseRow = () => {},
51
52
  onFocusRow = () => {},
53
+ applicationAriaLabel,
52
54
  ...props
53
55
  },
54
56
  ref
@@ -286,14 +288,21 @@ function TreeGrid(
286
288
  /* eslint-disable jsx-a11y/no-noninteractive-element-to-interactive-role */
287
289
  return (
288
290
  <RovingTabIndexContainer>
289
- <table
290
- { ...props }
291
- role="treegrid"
292
- onKeyDown={ onKeyDown }
293
- ref={ ref }
294
- >
295
- <tbody>{ children }</tbody>
296
- </table>
291
+ {
292
+ // Prevent browser mode from triggering in NVDA by wrapping List View
293
+ // in a role=application wrapper.
294
+ // see: https://github.com/WordPress/gutenberg/issues/43729
295
+ }
296
+ <div role="application" aria-label={ applicationAriaLabel }>
297
+ <table
298
+ { ...props }
299
+ role="treegrid"
300
+ onKeyDown={ onKeyDown }
301
+ ref={ ref }
302
+ >
303
+ <tbody>{ children }</tbody>
304
+ </table>
305
+ </div>
297
306
  </RovingTabIndexContainer>
298
307
  );
299
308
  /* eslint-enable jsx-a11y/no-noninteractive-element-to-interactive-role */
@@ -1,23 +1,27 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`TreeGridCell uses a child render function to render children 1`] = `
4
- <table
5
- onKeyDown={[Function]}
6
- role="treegrid"
4
+ <div
5
+ role="application"
7
6
  >
8
- <tbody>
9
- <tr>
10
- <td
11
- role="gridcell"
12
- >
13
- <button
14
- className="my-button"
15
- onFocus={[Function]}
7
+ <table
8
+ onKeyDown={[Function]}
9
+ role="treegrid"
10
+ >
11
+ <tbody>
12
+ <tr>
13
+ <td
14
+ role="gridcell"
16
15
  >
17
- Click Me!
18
- </button>
19
- </td>
20
- </tr>
21
- </tbody>
22
- </table>
16
+ <button
17
+ className="my-button"
18
+ onFocus={[Function]}
19
+ >
20
+ Click Me!
21
+ </button>
22
+ </td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+ </div>
23
27
  `;
@@ -1,3 +1,3 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`TreeGrid simple rendering renders a table, tbody and any child elements 1`] = `"<table role=\\"treegrid\\"><tbody><tr role=\\"row\\" aria-level=\\"1\\" aria-posinset=\\"1\\" aria-setsize=\\"1\\"><td role=\\"gridcell\\">Test</td></tr></tbody></table>"`;
3
+ exports[`TreeGrid simple rendering renders a table, tbody and any child elements 1`] = `"<div role=\\"application\\"><table role=\\"treegrid\\"><tbody><tr role=\\"row\\" aria-level=\\"1\\" aria-posinset=\\"1\\" aria-setsize=\\"1\\"><td role=\\"gridcell\\">Test</td></tr></tbody></table></div>"`;