@wordpress/grid 0.5.0 → 0.7.1-next.v.202608281122.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 (91) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +44 -1
  3. package/build/dashboard-grid/grid-item.cjs +21 -7
  4. package/build/dashboard-grid/grid-item.cjs.map +2 -2
  5. package/build/dashboard-grid/index.cjs +110 -48
  6. package/build/dashboard-grid/index.cjs.map +2 -2
  7. package/build/dashboard-grid/resolve-fill-widths.cjs +68 -50
  8. package/build/dashboard-grid/resolve-fill-widths.cjs.map +2 -2
  9. package/build/dashboard-grid/types.cjs.map +1 -1
  10. package/build/dashboard-lanes/index.cjs +62 -20
  11. package/build/dashboard-lanes/index.cjs.map +2 -2
  12. package/build/dashboard-lanes/lanes-item.cjs +14 -6
  13. package/build/dashboard-lanes/lanes-item.cjs.map +2 -2
  14. package/build/dashboard-lanes/types.cjs.map +1 -1
  15. package/build/index.cjs.map +1 -1
  16. package/build/shared/array-move-with-pinned.cjs +49 -0
  17. package/build/shared/array-move-with-pinned.cjs.map +7 -0
  18. package/build/shared/resize-snap.cjs +91 -5
  19. package/build/shared/resize-snap.cjs.map +2 -2
  20. package/build/shared/types.cjs.map +1 -1
  21. package/build/shared/use-span-bounds.cjs +85 -0
  22. package/build/shared/use-span-bounds.cjs.map +7 -0
  23. package/build-module/dashboard-grid/grid-item.mjs +21 -7
  24. package/build-module/dashboard-grid/grid-item.mjs.map +2 -2
  25. package/build-module/dashboard-grid/index.mjs +111 -50
  26. package/build-module/dashboard-grid/index.mjs.map +2 -2
  27. package/build-module/dashboard-grid/resolve-fill-widths.mjs +68 -50
  28. package/build-module/dashboard-grid/resolve-fill-widths.mjs.map +2 -2
  29. package/build-module/dashboard-lanes/index.mjs +63 -22
  30. package/build-module/dashboard-lanes/index.mjs.map +2 -2
  31. package/build-module/dashboard-lanes/lanes-item.mjs +14 -6
  32. package/build-module/dashboard-lanes/lanes-item.mjs.map +2 -2
  33. package/build-module/index.mjs.map +1 -1
  34. package/build-module/shared/array-move-with-pinned.mjs +24 -0
  35. package/build-module/shared/array-move-with-pinned.mjs.map +7 -0
  36. package/build-module/shared/resize-snap.mjs +87 -4
  37. package/build-module/shared/resize-snap.mjs.map +2 -2
  38. package/build-module/shared/use-span-bounds.mjs +62 -0
  39. package/build-module/shared/use-span-bounds.mjs.map +7 -0
  40. package/build-types/dashboard-grid/grid-item.d.ts +1 -1
  41. package/build-types/dashboard-grid/grid-item.d.ts.map +1 -1
  42. package/build-types/dashboard-grid/index.d.ts.map +1 -1
  43. package/build-types/dashboard-grid/resolve-fill-widths.d.ts +12 -1
  44. package/build-types/dashboard-grid/resolve-fill-widths.d.ts.map +1 -1
  45. package/build-types/dashboard-grid/types.d.ts +43 -1
  46. package/build-types/dashboard-grid/types.d.ts.map +1 -1
  47. package/build-types/dashboard-lanes/index.d.ts.map +1 -1
  48. package/build-types/dashboard-lanes/lanes-item.d.ts +18 -1
  49. package/build-types/dashboard-lanes/lanes-item.d.ts.map +1 -1
  50. package/build-types/dashboard-lanes/types.d.ts +20 -1
  51. package/build-types/dashboard-lanes/types.d.ts.map +1 -1
  52. package/build-types/index.d.ts +1 -1
  53. package/build-types/index.d.ts.map +1 -1
  54. package/build-types/shared/array-move-with-pinned.d.ts +13 -0
  55. package/build-types/shared/array-move-with-pinned.d.ts.map +1 -0
  56. package/build-types/shared/resize-snap.d.ts +65 -2
  57. package/build-types/shared/resize-snap.d.ts.map +1 -1
  58. package/build-types/shared/types.d.ts +31 -0
  59. package/build-types/shared/types.d.ts.map +1 -1
  60. package/build-types/shared/use-span-bounds.d.ts +29 -0
  61. package/build-types/shared/use-span-bounds.d.ts.map +1 -0
  62. package/package.json +10 -10
  63. package/src/dashboard-grid/grid-item.tsx +21 -7
  64. package/src/dashboard-grid/grid.module.css +6 -6
  65. package/src/dashboard-grid/index.tsx +155 -58
  66. package/src/dashboard-grid/resolve-fill-widths.ts +85 -62
  67. package/src/dashboard-grid/stories/index.story.tsx +169 -0
  68. package/src/dashboard-grid/test/item-interactions.test.tsx +63 -0
  69. package/src/dashboard-grid/test/item-limits.test.tsx +147 -0
  70. package/src/dashboard-grid/test/resolve-fill-widths.test.ts +158 -0
  71. package/src/dashboard-grid/types.ts +50 -0
  72. package/src/dashboard-lanes/index.tsx +87 -25
  73. package/src/dashboard-lanes/lanes-item.tsx +34 -6
  74. package/src/dashboard-lanes/lanes.module.css +6 -6
  75. package/src/dashboard-lanes/stories/index.story.tsx +144 -0
  76. package/src/dashboard-lanes/test/item-interactions.test.tsx +63 -0
  77. package/src/dashboard-lanes/test/item-limits.test.tsx +140 -0
  78. package/src/dashboard-lanes/test/use-lane-placement.test.tsx +10 -3
  79. package/src/dashboard-lanes/types.ts +23 -0
  80. package/src/index.ts +2 -0
  81. package/src/shared/array-move-with-pinned.ts +36 -0
  82. package/src/shared/resize-snap.ts +161 -5
  83. package/src/shared/test/array-move-with-pinned.test.ts +39 -0
  84. package/src/shared/test/resize-snap.test.ts +170 -2
  85. package/src/shared/test/use-span-bounds.test.ts +104 -0
  86. package/src/shared/types.ts +35 -0
  87. package/src/shared/use-span-bounds.ts +99 -0
  88. package/build-types/dashboard-grid/stories/index.story.d.ts +0 -92
  89. package/build-types/dashboard-grid/stories/index.story.d.ts.map +0 -1
  90. package/build-types/dashboard-lanes/stories/index.story.d.ts +0 -58
  91. package/build-types/dashboard-lanes/stories/index.story.d.ts.map +0 -1
@@ -7,7 +7,6 @@ import {
7
7
  useSensors,
8
8
  } from '@dnd-kit/core';
9
9
  import {
10
- arrayMove,
11
10
  SortableContext,
12
11
  sortableKeyboardCoordinates,
13
12
  } from '@dnd-kit/sortable';
@@ -26,8 +25,10 @@ import {
26
25
  } from '@wordpress/element';
27
26
  import { LanesItem } from './lanes-item';
28
27
  import { useLanePlacement } from './use-lane-placement';
28
+ import { arrayMoveWithPinned } from '../shared/array-move-with-pinned';
29
29
  import { GridOverlay } from '../shared/grid-overlay';
30
- import { gridSpanToPixelSize } from '../shared/resize-snap';
30
+ import { clampSpan, gridSpanToPixelSize } from '../shared/resize-snap';
31
+ import { useResizePixelLimits, useSpanBounds } from '../shared/use-span-bounds';
31
32
  import layoutAnimationStyles from '../shared/layout-shift-animation.module.css';
32
33
  import { ItemExitOverlay } from '../shared/item-exit-overlay';
33
34
  import {
@@ -44,7 +45,7 @@ import styles from './lanes.module.css';
44
45
 
45
46
  const dashboardDragDropAnimation = createDashboardDragDropAnimation(
46
47
  styles[ 'drag-preview-frame' ],
47
- styles.dragPreviewFrameExiting
48
+ styles[ 'is-exiting' ]
48
49
  );
49
50
 
50
51
  // Fallback gap in pixels for math that runs before the computed gap
@@ -109,6 +110,7 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
109
110
  flowTolerance = 16,
110
111
  rowUnit = 4,
111
112
  minColumnWidth,
113
+ itemLimits,
112
114
  editMode = false,
113
115
  onChangeLayout,
114
116
  onPreviewLayout,
@@ -197,6 +199,21 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
197
199
  null
198
200
  ).widthPx;
199
201
 
202
+ // Height limits do not apply: lane heights are content-driven.
203
+ const widthBoundsByKey = useSpanBounds(
204
+ itemLimits,
205
+ columnWidth,
206
+ gapPx,
207
+ null,
208
+ effectiveColumns
209
+ );
210
+ const resizeLimitsByKey = useResizePixelLimits(
211
+ widthBoundsByKey,
212
+ columnWidth,
213
+ gapPx,
214
+ null
215
+ );
216
+
200
217
  const layoutMap = useMemo( () => {
201
218
  const map = new Map< string, DashboardLanesLayoutItem >();
202
219
  activeLayout.forEach( ( item ) => map.set( item.key, item ) );
@@ -225,21 +242,42 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
225
242
  );
226
243
  const items = sortedItems;
227
244
 
228
- // Placement input for the hook: each item with its clamped span
245
+ // Span each item renders at: the stored width clamped to the lane
246
+ // count and to the item's width bounds. Placement, the resize
247
+ // baseline, and the commit check all read it, so a gesture starts
248
+ // from the span on screen and commits nothing until it leaves it.
249
+ const renderedSpanByKey = useMemo( () => {
250
+ const map = new Map< string, number >();
251
+ for ( const [ key, item ] of layoutMap ) {
252
+ const span =
253
+ typeof item.width === 'number'
254
+ ? Math.max(
255
+ 1,
256
+ Math.min( item.width, effectiveColumns )
257
+ )
258
+ : 1;
259
+ const bounds = widthBoundsByKey.get( key );
260
+ map.set(
261
+ key,
262
+ bounds
263
+ ? clampSpan( span, bounds.minWidth, bounds.maxWidth )
264
+ : span
265
+ );
266
+ }
267
+ return map;
268
+ }, [ layoutMap, effectiveColumns, widthBoundsByKey ] );
269
+
270
+ // Placement input for the hook: each item with its rendered span
229
271
  // in source (sorted) order. `lane` forwards the optional explicit
230
272
  // pin from the layout item; the algorithm clamps out-of-range
231
273
  // values, so no surface-level guard is needed.
232
274
  const placementItems = useMemo( () => {
233
- return items.map( ( key ) => {
234
- const item = layoutMap.get( key );
235
- const width = item?.width;
236
- const span =
237
- typeof width === 'number'
238
- ? Math.max( 1, Math.min( width, effectiveColumns ) )
239
- : 1;
240
- return { key, span, lane: item?.lane };
241
- } );
242
- }, [ items, layoutMap, effectiveColumns ] );
275
+ return items.map( ( key ) => ( {
276
+ key,
277
+ span: renderedSpanByKey.get( key ) ?? 1,
278
+ lane: layoutMap.get( key )?.lane,
279
+ } ) );
280
+ }, [ items, layoutMap, renderedSpanByKey ] );
243
281
 
244
282
  const { itemStyles } = useLanePlacement( container, {
245
283
  items: placementItems,
@@ -366,7 +404,19 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
366
404
  return;
367
405
  }
368
406
 
369
- const updatedItems = arrayMove( items, currentIndex, newIndex );
407
+ // Non-draggable items are pinned: they hold their index while
408
+ // the others reorder around them.
409
+ const updatedItems = arrayMoveWithPinned(
410
+ items,
411
+ currentIndex,
412
+ newIndex,
413
+ ( key ) => layoutMap.get( key )?.draggable === false
414
+ );
415
+ if (
416
+ updatedItems.every( ( key, index ) => key === items[ index ] )
417
+ ) {
418
+ return;
419
+ }
370
420
  // Build a key→index lookup so the .map below is O(n)
371
421
  // instead of O(n²) from per-item `indexOf` calls.
372
422
  const orderByKey = new Map< string, number >();
@@ -416,15 +466,14 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
416
466
  );
417
467
 
418
468
  if ( resizeBaselineRef.current === null ) {
419
- const baseItem = layoutMap.get( id );
420
- const baseWidth =
421
- typeof baseItem?.width === 'number' ? baseItem.width : 1;
422
- resizeBaselineRef.current = baseWidth;
469
+ resizeBaselineRef.current = renderedSpanByKey.get( id ) ?? 1;
423
470
  }
424
471
  const baseline = resizeBaselineRef.current;
425
- const newWidth = Math.max(
426
- 1,
427
- Math.min( baseline + relativeDelta, effectiveColumns )
472
+ const bounds = widthBoundsByKey.get( id );
473
+ const newWidth = clampSpan(
474
+ baseline + relativeDelta,
475
+ bounds?.minWidth ?? 1,
476
+ bounds?.maxWidth ?? effectiveColumns
428
477
  );
429
478
 
430
479
  setResizeSnapPreview( {
@@ -438,11 +487,14 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
438
487
  ),
439
488
  } );
440
489
 
490
+ // Bail when the snap target matches the span staged for commit,
491
+ // or the rendered span while nothing is staged.
441
492
  const pendingItem = latestLayoutRef.current?.find(
442
493
  ( item ) => item.key === id
443
494
  );
444
- const currentItem = pendingItem ?? layoutMap.get( id );
445
- if ( currentItem && currentItem.width === newWidth ) {
495
+ const currentWidth =
496
+ pendingItem?.width ?? renderedSpanByKey.get( id );
497
+ if ( currentWidth === newWidth ) {
446
498
  return;
447
499
  }
448
500
 
@@ -569,6 +621,7 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
569
621
  if ( ! child ) {
570
622
  return null;
571
623
  }
624
+ const limitsPx = resizeLimitsByKey.get( id );
572
625
  return (
573
626
  <LanesItem
574
627
  key={ id }
@@ -577,6 +630,12 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
577
630
  itemStyles.get( id ) ?? {}
578
631
  }
579
632
  disabled={ ! editMode }
633
+ draggable={
634
+ layoutMap.get( id )?.draggable !== false
635
+ }
636
+ resizable={
637
+ layoutMap.get( id )?.resizable !== false
638
+ }
580
639
  interacting={ interacting }
581
640
  dragging={ activeId !== null }
582
641
  onResize={ handleResize }
@@ -586,7 +645,10 @@ export const DashboardLanes = forwardRef< HTMLDivElement, DashboardLanesProps >(
586
645
  ? resizeSnapPreview.snap
587
646
  : null
588
647
  }
589
- minResizeWidthPx={ minResizeWidthPx }
648
+ minResizeWidthPx={
649
+ limitsPx?.minWidthPx ?? minResizeWidthPx
650
+ }
651
+ maxResizeWidthPx={ limitsPx?.maxWidthPx }
590
652
  actionableArea={ actionableAreaMap.get(
591
653
  id
592
654
  ) }
@@ -46,6 +46,20 @@ export type LanesItemProps = {
46
46
  */
47
47
  disabled?: boolean;
48
48
 
49
+ /**
50
+ * Whether the item can be dragged. Combined with `disabled`.
51
+ *
52
+ * @default true
53
+ */
54
+ draggable?: boolean;
55
+
56
+ /**
57
+ * Whether the item can be resized. Combined with `disabled`.
58
+ *
59
+ * @default true
60
+ */
61
+ resizable?: boolean;
62
+
49
63
  /**
50
64
  * Whether any tile in the surface is currently being dragged or
51
65
  * resized. Drives the drag activator cursor.
@@ -77,6 +91,12 @@ export type LanesItemProps = {
77
91
  */
78
92
  minResizeWidthPx: number;
79
93
 
94
+ /**
95
+ * Maximum tile width while resizing, in pixels. Omitted when the
96
+ * item declares no width limit.
97
+ */
98
+ maxResizeWidthPx?: number;
99
+
80
100
  onResizeEnd: () => void;
81
101
 
82
102
  renderResizeHandle?: React.ComponentType< ResizeHandleRenderProps >;
@@ -86,6 +106,8 @@ export function LanesItem( {
86
106
  itemKey,
87
107
  placementStyle,
88
108
  disabled = false,
109
+ draggable = true,
110
+ resizable = true,
89
111
  interacting = false,
90
112
  children,
91
113
  actionableArea = null,
@@ -93,6 +115,7 @@ export function LanesItem( {
93
115
  onResizeEnd,
94
116
  resizeSnapPreview = null,
95
117
  minResizeWidthPx,
118
+ maxResizeWidthPx,
96
119
  renderResizeHandle,
97
120
  dragging = false,
98
121
  }: LanesItemProps ) {
@@ -106,6 +129,8 @@ export function LanesItem( {
106
129
  const itemRef = useRef< HTMLDivElement >( null );
107
130
  const contentRef = useRef< HTMLDivElement >( null );
108
131
 
132
+ const dragDisabled = disabled || ! draggable;
133
+ const resizeDisabled = disabled || ! resizable;
109
134
  const {
110
135
  attributes,
111
136
  listeners,
@@ -114,7 +139,7 @@ export function LanesItem( {
114
139
  isDragging,
115
140
  } = useSortable( {
116
141
  id: itemKey,
117
- disabled,
142
+ disabled: dragDisabled,
118
143
  } );
119
144
  const mergedRef = useMergeRefs( [ itemRef, setNodeRef ] );
120
145
  const contentMergedRef = useMergeRefs( [ contentRef ] );
@@ -141,9 +166,12 @@ export function LanesItem( {
141
166
  }
142
167
  let clamped: ResizeDelta = { width: delta.width, height: 0 };
143
168
  if ( baselineSize ) {
144
- clamped = clampResizeDelta( clamped, baselineSize, {
145
- width: minResizeWidthPx,
146
- } );
169
+ clamped = clampResizeDelta(
170
+ clamped,
171
+ baselineSize,
172
+ { width: minResizeWidthPx },
173
+ { width: maxResizeWidthPx }
174
+ );
147
175
  }
148
176
  setResizeDelta( clamped );
149
177
  onResize( itemKey, clamped );
@@ -199,7 +227,7 @@ export function LanesItem( {
199
227
  { ...listeners }
200
228
  style={ {
201
229
  height: '100%',
202
- cursor: getItemCursor( disabled, interacting ),
230
+ cursor: getItemCursor( dragDisabled, interacting ),
203
231
  } }
204
232
  >
205
233
  <div
@@ -208,7 +236,7 @@ export function LanesItem( {
208
236
  style={ continuousContentStyle }
209
237
  >
210
238
  { children }
211
- { ! disabled && (
239
+ { ! resizeDisabled && (
212
240
  <ResizeHandle
213
241
  itemId={ itemKey }
214
242
  verticalResizable={ false }
@@ -100,14 +100,14 @@
100
100
  * is replaced.
101
101
  */
102
102
  @media not (prefers-reduced-motion: reduce) {
103
- .drag-preview-frame.dragPreviewFrameExiting {
103
+ .drag-preview-frame.is-exiting {
104
104
  animation:
105
105
  wp-grid-drag-preview-shadow-exit
106
106
  var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced)
107
107
  forwards;
108
108
  }
109
109
 
110
- .drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
110
+ .drag-preview-frame.is-exiting .drag-preview-frame__lift {
111
111
  animation:
112
112
  wp-grid-drag-preview-scale-exit
113
113
  var(--wpds-motion-duration-md) var(--wpds-motion-easing-balanced)
@@ -135,11 +135,11 @@
135
135
  }
136
136
  }
137
137
 
138
- .drag-preview-frame.dragPreviewFrameExiting {
138
+ .drag-preview-frame.is-exiting {
139
139
  box-shadow: var(--_wp-grid-elevation-xs);
140
140
  }
141
141
 
142
- .drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
142
+ .drag-preview-frame.is-exiting .drag-preview-frame__lift {
143
143
  transform: scale(1);
144
144
  }
145
145
 
@@ -152,12 +152,12 @@
152
152
  transform: none;
153
153
  }
154
154
 
155
- .drag-preview-frame.dragPreviewFrameExiting {
155
+ .drag-preview-frame.is-exiting {
156
156
  box-shadow: var(--_wp-grid-elevation-xs);
157
157
  transition: none;
158
158
  }
159
159
 
160
- .drag-preview-frame.dragPreviewFrameExiting .drag-preview-frame__lift {
160
+ .drag-preview-frame.is-exiting .drag-preview-frame__lift {
161
161
  transition: none;
162
162
  }
163
163
  }
@@ -187,6 +187,11 @@ export const Default: Story = {
187
187
  * frame to see the lane count adapt.
188
188
  */
189
189
  export const Responsive: Story = {
190
+ parameters: {
191
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
192
+ // See: https://github.com/WordPress/gutenberg/issues/81596
193
+ a11y: { test: 'todo' },
194
+ },
190
195
  args: {
191
196
  minColumnWidth: 200,
192
197
  layout: [
@@ -216,6 +221,11 @@ export const Responsive: Story = {
216
221
  * tiles below `minColumnWidth`.
217
222
  */
218
223
  export const Layered: Story = {
224
+ parameters: {
225
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
226
+ // See: https://github.com/WordPress/gutenberg/issues/81596
227
+ a11y: { test: 'todo' },
228
+ },
219
229
  args: {
220
230
  columns: 4,
221
231
  minColumnWidth: 200,
@@ -244,6 +254,11 @@ export const Layered: Story = {
244
254
  * lanes.
245
255
  */
246
256
  export const Spanning: Story = {
257
+ parameters: {
258
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
259
+ // See: https://github.com/WordPress/gutenberg/issues/81596
260
+ a11y: { test: 'todo' },
261
+ },
247
262
  args: {
248
263
  columns: 4,
249
264
  layout: [
@@ -287,6 +302,11 @@ export const Spanning: Story = {
287
302
  * story below for a full override example.
288
303
  */
289
304
  export const EditMode: Story = {
305
+ parameters: {
306
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
307
+ // See: https://github.com/WordPress/gutenberg/issues/81596
308
+ a11y: { test: 'todo' },
309
+ },
290
310
  args: {
291
311
  columns: 4,
292
312
  editMode: true,
@@ -359,6 +379,125 @@ export const EditMode: Story = {
359
379
  },
360
380
  };
361
381
 
382
+ /**
383
+ * Per-item width limits via `itemLimits`, in pixels. The wide tile
384
+ * stops shrinking at its minimum, the capped tile stops growing at its
385
+ * maximum, the ranged tile stays between both, and the free tiles keep
386
+ * the full range. Lanes take no height limits; lane heights are
387
+ * content-driven.
388
+ */
389
+ export const SizeLimits: Story = {
390
+ name: 'Per-Item Size Limits',
391
+ parameters: {
392
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
393
+ // See: https://github.com/WordPress/gutenberg/issues/81596
394
+ a11y: { test: 'todo' },
395
+ },
396
+ args: {
397
+ columns: 12,
398
+ editMode: true,
399
+ itemLimits: {
400
+ min: { minWidth: 360 },
401
+ max: { maxWidth: 500 },
402
+ ranged: { minWidth: 300, maxWidth: 500 },
403
+ },
404
+ },
405
+ render: function SizeLimitsStory( args ) {
406
+ const initial: ( DashboardLanesLayoutItem & {
407
+ tone: Tone;
408
+ height: number;
409
+ label: string;
410
+ } )[] = [
411
+ {
412
+ key: 'min',
413
+ width: 2,
414
+ tone: 'info',
415
+ height: 140,
416
+ label: 'min 360px wide',
417
+ },
418
+ {
419
+ key: 'max',
420
+ width: 3,
421
+ tone: 'warning',
422
+ height: 120,
423
+ label: 'max 500px wide',
424
+ },
425
+ {
426
+ key: 'ranged',
427
+ width: 2,
428
+ tone: 'brand',
429
+ height: 150,
430
+ label: 'min 300, max 500px wide',
431
+ },
432
+ {
433
+ key: 'free-a',
434
+ width: 3,
435
+ tone: 'neutral',
436
+ height: 180,
437
+ label: 'no limits',
438
+ },
439
+ {
440
+ key: 'free-b',
441
+ width: 2,
442
+ tone: 'neutral',
443
+ height: 100,
444
+ label: 'no limits',
445
+ },
446
+ {
447
+ key: 'free-c',
448
+ width: 3,
449
+ tone: 'neutral',
450
+ height: 160,
451
+ label: 'no limits',
452
+ },
453
+ ];
454
+
455
+ const [ tiles, setTiles ] = useState( initial );
456
+
457
+ const layout: DashboardLanesLayoutItem[] = tiles.map(
458
+ ( { tone: _tone, height: _height, label: _label, ...item } ) => item
459
+ );
460
+
461
+ const onChangeLayout = ( next: DashboardLanesLayoutItem[] ) => {
462
+ setTiles(
463
+ next.map( ( item ) => {
464
+ const existing = tiles.find( ( t ) => t.key === item.key );
465
+ return {
466
+ ...item,
467
+ tone: existing?.tone ?? 'neutral',
468
+ height: existing?.height ?? 100,
469
+ label: existing?.label ?? item.key,
470
+ };
471
+ } )
472
+ );
473
+ };
474
+
475
+ const tileElements = useMemo(
476
+ () =>
477
+ tiles.map( ( tile ) => (
478
+ <Tile
479
+ key={ tile.key }
480
+ tone={ tile.tone }
481
+ height={ tile.height }
482
+ >
483
+ { tile.label }
484
+ </Tile>
485
+ ) ),
486
+ [ tiles ]
487
+ );
488
+
489
+ return (
490
+ <DashboardLanes
491
+ { ...args }
492
+ layout={ layout }
493
+ onChangeLayout={ onChangeLayout }
494
+ >
495
+ { tileElements }
496
+ </DashboardLanes>
497
+ );
498
+ },
499
+ };
500
+
362
501
  /**
363
502
  * Example custom overlay supplied to `<DashboardLanes />` through the
364
503
  * `renderGridOverlay` prop. Receives `{ columns, isActive }` from the
@@ -433,6 +572,11 @@ function NumberedLanesOverlay( { columns, isActive }: GridOverlayRenderProps ) {
433
572
  * entirely while keeping `editMode` interactions on.
434
573
  */
435
574
  export const CustomGridOverlayStory: Story = {
575
+ parameters: {
576
+ // FIXME: Resize handles are nameless aria commands; edit mode nests interactive controls (aria-command-name, nested-interactive).
577
+ // See: https://github.com/WordPress/gutenberg/issues/81596
578
+ a11y: { test: 'todo' },
579
+ },
436
580
  name: 'Custom Grid Overlay',
437
581
  args: {
438
582
  columns: 4,
@@ -0,0 +1,63 @@
1
+ import { render } from '@testing-library/react';
2
+ import { DashboardLanes } from '..';
3
+
4
+ class MockResizeObserver {
5
+ observe() {}
6
+ unobserve() {}
7
+ disconnect() {}
8
+ }
9
+
10
+ let originalResizeObserver: typeof ResizeObserver;
11
+
12
+ beforeEach( () => {
13
+ originalResizeObserver = global.ResizeObserver;
14
+ ( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
15
+ MockResizeObserver;
16
+ } );
17
+
18
+ afterEach( () => {
19
+ ( global as unknown as { ResizeObserver: unknown } ).ResizeObserver =
20
+ originalResizeObserver;
21
+ } );
22
+
23
+ /* eslint-disable testing-library/no-container */
24
+ function renderItem( flags: { draggable?: boolean; resizable?: boolean } ) {
25
+ const { container } = render(
26
+ <DashboardLanes
27
+ layout={ [ { key: 'a', width: 1, ...flags } ] }
28
+ columns={ 2 }
29
+ editMode
30
+ >
31
+ <div key="a">A</div>
32
+ </DashboardLanes>
33
+ );
34
+ return {
35
+ activator: container.querySelector(
36
+ '[aria-roledescription="sortable"]'
37
+ ),
38
+ resizeHandle: container.querySelector(
39
+ '[aria-roledescription="draggable"]'
40
+ ),
41
+ };
42
+ }
43
+ /* eslint-enable testing-library/no-container */
44
+
45
+ describe( 'DashboardLanes item interactions', () => {
46
+ it( 'drags and resizes by default in edit mode', () => {
47
+ const { activator, resizeHandle } = renderItem( {} );
48
+ expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
49
+ expect( resizeHandle ).not.toBeNull();
50
+ } );
51
+
52
+ it( 'keeps an item in place when draggable is false', () => {
53
+ const { activator, resizeHandle } = renderItem( { draggable: false } );
54
+ expect( activator ).toHaveAttribute( 'aria-disabled', 'true' );
55
+ expect( resizeHandle ).not.toBeNull();
56
+ } );
57
+
58
+ it( 'keeps an item at its size when resizable is false', () => {
59
+ const { activator, resizeHandle } = renderItem( { resizable: false } );
60
+ expect( activator ).toHaveAttribute( 'aria-disabled', 'false' );
61
+ expect( resizeHandle ).toBeNull();
62
+ } );
63
+ } );