@vaadin/grid 25.4.0-alpha2 → 25.4.0-alpha4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/grid",
3
- "version": "25.4.0-alpha2",
3
+ "version": "25.4.0-alpha4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,20 +45,20 @@
45
45
  ],
46
46
  "dependencies": {
47
47
  "@open-wc/dedupe-mixin": "^1.3.0",
48
- "@vaadin/a11y-base": "25.4.0-alpha2",
49
- "@vaadin/checkbox": "25.4.0-alpha2",
50
- "@vaadin/component-base": "25.4.0-alpha2",
51
- "@vaadin/lit-renderer": "25.4.0-alpha2",
52
- "@vaadin/text-field": "25.4.0-alpha2",
53
- "@vaadin/vaadin-themable-mixin": "25.4.0-alpha2",
48
+ "@vaadin/a11y-base": "25.4.0-alpha4",
49
+ "@vaadin/checkbox": "25.4.0-alpha4",
50
+ "@vaadin/component-base": "25.4.0-alpha4",
51
+ "@vaadin/lit-renderer": "25.4.0-alpha4",
52
+ "@vaadin/text-field": "25.4.0-alpha4",
53
+ "@vaadin/vaadin-themable-mixin": "25.4.0-alpha4",
54
54
  "lit": "^3.0.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@vaadin/aura": "25.4.0-alpha2",
58
- "@vaadin/chai-plugins": "25.4.0-alpha2",
59
- "@vaadin/test-runner-commands": "25.4.0-alpha2",
57
+ "@vaadin/aura": "25.4.0-alpha4",
58
+ "@vaadin/chai-plugins": "25.4.0-alpha4",
59
+ "@vaadin/test-runner-commands": "25.4.0-alpha4",
60
60
  "@vaadin/testing-helpers": "^2.0.0",
61
- "@vaadin/vaadin-lumo-styles": "25.4.0-alpha2",
61
+ "@vaadin/vaadin-lumo-styles": "25.4.0-alpha4",
62
62
  "sinon": "^22.0.0"
63
63
  },
64
64
  "customElements": "custom-elements.json",
@@ -66,5 +66,5 @@
66
66
  "web-types.json",
67
67
  "web-types.lit.json"
68
68
  ],
69
- "gitHead": "213f8b55112558d2f976d8730fe44370ca868333"
69
+ "gitHead": "7809e4c099538333a6dbd11d8da18a0c6ec30dad"
70
70
  }
@@ -127,6 +127,11 @@ export const gridStyles = css`
127
127
  box-sizing: border-box;
128
128
  margin: 0;
129
129
  position: relative;
130
+ /* Browser default tr styles use vertical-align: inherit and border-color: inherit,
131
+ which force every row to restyle when #items, #header or #footer gets a new
132
+ transform on horizontal scroll. Resetting them makes horizontal scrolling faster. */
133
+ vertical-align: initial;
134
+ border-color: initial;
130
135
  }
131
136
 
132
137
  .row:not(:focus-within) {
@@ -226,7 +231,7 @@ export const gridStyles = css`
226
231
 
227
232
  /* Block borders / Last body row */
228
233
 
229
- .last-row::after {
234
+ #table[has-footer] .last-row::after {
230
235
  bottom: 0;
231
236
  }
232
237
 
@@ -237,16 +242,26 @@ export const gridStyles = css`
237
242
 
238
243
  /* Block borders / Last body row without footer */
239
244
 
245
+ #table:not([has-footer]) {
246
+ /* Push the bottom border out of the row box, so the row height does not include it */
247
+ .last-row .details-cell,
248
+ .last-row-cell {
249
+ margin-bottom: calc(var(--_row-border-width) * -1);
250
+ }
251
+
252
+ /* Treat the border outside the row box as ink overflow, so it does not extend the scroll range */
253
+ .last-row {
254
+ contain: layout;
255
+ }
256
+ }
257
+
240
258
  :host([all-rows-visible]),
241
259
  :host([overflow~='top']),
242
260
  :host([overflow~='bottom']) {
243
- #table:not([has-footer]) .last-row .details-cell,
244
- #table:not([has-footer]) .last-row-cell:not(.details-opened-row-cell) {
245
- border-bottom-style: none;
246
-
247
- &::after {
248
- bottom: 0;
249
- }
261
+ #table:not([has-footer]) .last-row::after,
262
+ #table:not([has-footer]) .last-row .details-cell::after,
263
+ #table:not([has-footer]) .last-row-cell:not(.details-opened-row-cell)::after {
264
+ bottom: 0;
250
265
  }
251
266
  }
252
267
 
@@ -312,10 +327,14 @@ export const gridStyles = css`
312
327
  var(--vaadin-grid-cell-background-color, transparent)
313
328
  );
314
329
 
315
- background-color: inherit;
330
+ background-color: var(--vaadin-grid-row-background-color, var(--vaadin-background-color));
316
331
  background-repeat: no-repeat;
317
332
  background-origin: padding-box;
318
333
  background-image: var(--_cell-background-image);
334
+
335
+ /* Browser default td styles use vertical-align: inherit, which forces every
336
+ cell in a row to restyle when the row's style changes. */
337
+ vertical-align: initial;
319
338
  }
320
339
 
321
340
  .body-cell {
@@ -121,6 +121,7 @@ export declare class GridColumnMixinClass<
121
121
  > extends ColumnBaseMixinClass<TItem, Column> {
122
122
  /**
123
123
  * Width of the cells for this column.
124
+ * Setting the property to `null` or `undefined` restores the default width.
124
125
  *
125
126
  * Please note that using the `em` length unit is discouraged as
126
127
  * it might lead to misalignment issues if the header, body, and footer
@@ -12,6 +12,9 @@ import { updateCellState } from './vaadin-grid-helpers.js';
12
12
 
13
13
  export const ColumnBaseMixin = (superClass) =>
14
14
  class ColumnBaseMixin extends superClass {
15
+ /** @type {Grid | undefined} */
16
+ #cachedGrid;
17
+
15
18
  static get properties() {
16
19
  return {
17
20
  /**
@@ -273,10 +276,8 @@ export const ColumnBaseMixin = (superClass) =>
273
276
  * @protected
274
277
  */
275
278
  get _grid() {
276
- if (!this._gridValue) {
277
- this._gridValue = this._findHostGrid();
278
- }
279
- return this._gridValue;
279
+ this.#cachedGrid ??= this._findHostGrid();
280
+ return this.#cachedGrid;
280
281
  }
281
282
 
282
283
  /**
@@ -340,7 +341,7 @@ export const ColumnBaseMixin = (superClass) =>
340
341
  });
341
342
  });
342
343
 
343
- this._gridValue = undefined;
344
+ this.#cachedGrid = undefined;
344
345
  }
345
346
 
346
347
  /**
@@ -374,7 +375,7 @@ export const ColumnBaseMixin = (superClass) =>
374
375
  });
375
376
  }
376
377
 
377
- /** @private */
378
+ /** @protected */
378
379
  _widthChanged(width) {
379
380
  this.parentElement?._columnPropChanged?.('width');
380
381
 
@@ -757,6 +758,7 @@ export const GridColumnMixin = (superClass) =>
757
758
  return {
758
759
  /**
759
760
  * Width of the cells for this column.
761
+ * Setting the property to `null` or `undefined` restores the default width.
760
762
  *
761
763
  * Please note that using the `em` length unit is discouraged as
762
764
  * it might lead to misalignment issues if the header, body, and footer
@@ -867,4 +869,22 @@ export const GridColumnMixin = (superClass) =>
867
869
  },
868
870
  };
869
871
  }
872
+
873
+ /**
874
+ * Override method from `ColumnBaseMixin` to restore the default width
875
+ * when the property is set to `null` or `undefined`.
876
+ *
877
+ * @param {string | null | undefined} width
878
+ * @protected
879
+ * @override
880
+ */
881
+ _widthChanged(width) {
882
+ if (width == null) {
883
+ // Read the default from the property options, as e.g. the selection column overrides it
884
+ this.width = this.constructor.elementProperties.get('width').value;
885
+ return;
886
+ }
887
+
888
+ super._widthChanged(width);
889
+ }
870
890
  };
@@ -36,7 +36,7 @@ export const ColumnReorderingMixin = (superClass) =>
36
36
  ready() {
37
37
  super.ready();
38
38
  addListener(this, 'track', this._onTrackEvent);
39
- this._reorderGhost = this.shadowRoot.querySelector('[part="reorder-ghost"]');
39
+ this._reorderGhost = this.shadowRoot.querySelector('.reorder-ghost');
40
40
 
41
41
  this.addEventListener('touchstart', this._onTouchStart.bind(this));
42
42
  this.addEventListener('touchmove', this._onTouchMove.bind(this));
@@ -422,7 +422,7 @@ export const ColumnReorderingMixin = (superClass) =>
422
422
  * @protected
423
423
  */
424
424
  _isSwappableByPosition(targetColumn, clientX) {
425
- const targetCell = Array.from(this.$.header.querySelectorAll('tr:not([hidden]) [part~="cell"]')).find((cell) =>
425
+ const targetCell = Array.from(this.$.header.querySelectorAll('tr:not([hidden]) .header-cell')).find((cell) =>
426
426
  targetColumn.contains(cell._column),
427
427
  );
428
428
  const sourceCellRect = this.$.header
@@ -63,8 +63,8 @@ export const ColumnResizingMixin = (superClass) =>
63
63
 
64
64
  const isRTL = this.__isRTL;
65
65
  const eventX = e.detail.x;
66
- const columnRowCells = Array.from(this.$.header.querySelectorAll('[part~="row"]:last-child [part~="cell"]'));
67
- const targetCell = columnRowCells.find((cell) => cell._column === column);
66
+ const targetCell = column._headerCell;
67
+ const columnRowCells = [...targetCell.parentElement.children];
68
68
  // Resize the target column
69
69
  if (targetCell.offsetWidth) {
70
70
  const style = getComputedStyle(targetCell._content);
@@ -123,8 +123,7 @@ export const ColumnResizingMixin = (superClass) =>
123
123
  );
124
124
  }
125
125
 
126
- // Notify resize
127
- this._resizeHandler();
126
+ this.__updateHorizontalScrollPosition();
128
127
  }
129
128
  }
130
129
  };
@@ -7,6 +7,7 @@ import { isChrome, isSafari } from '@vaadin/component-base/src/browser-utils.js'
7
7
  import { setOrRemoveAttribute } from '@vaadin/component-base/src/dom-utils.js';
8
8
  import {
9
9
  getBodyRowCells,
10
+ getClosestCell,
10
11
  iterateChildren,
11
12
  iterateRowCells,
12
13
  updateBooleanRowStates,
@@ -149,10 +150,10 @@ export const DragAndDropMixin = (superClass) =>
149
150
  if (this.rowsDraggable) {
150
151
  let row = e.target;
151
152
  if (row.localName === 'vaadin-grid-cell-content') {
152
- // The draggable node is the cell content element on browsers that support native shadow
153
- row = row.assignedSlot.parentNode.parentNode;
153
+ // The draggable node is the cell content element
154
+ row = getClosestCell(row)?.__parentRow;
154
155
  }
155
- if (row.parentNode !== this.$.items) {
156
+ if (!row || row.parentNode !== this.$.items) {
156
157
  return;
157
158
  }
158
159
 
@@ -8,15 +8,14 @@ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
8
  import { getClosestElement } from '@vaadin/component-base/src/dom-utils.js';
9
9
 
10
10
  /**
11
- * Returns the grid cell that contains the given node, or `undefined` if the
12
- * node is not inside a cell's content.
11
+ * Returns the grid cell that contains the given node, if any.
13
12
  *
14
13
  * @param {Node} node
15
- * @return {HTMLElement | undefined}
14
+ * @return {HTMLElement | null | undefined}
16
15
  */
17
16
  export function getClosestCell(node) {
18
17
  const content = getClosestElement('vaadin-grid-cell-content', node);
19
- return content?.assignedSlot?.parentElement;
18
+ return content?.assignedSlot?.closest('.cell');
20
19
  }
21
20
 
22
21
  /**
@@ -27,7 +26,7 @@ export function getClosestCell(node) {
27
26
  */
28
27
  export function getBodyRowCells(row) {
29
28
  // If available, return the cached cells. Otherwise, query the cells directly from the row.
30
- return row.__cells || Array.from(row.querySelectorAll('[part~="cell"]:not([part~="details-cell"])'));
29
+ return row.__cells || Array.from(row.querySelectorAll('.body-cell'));
31
30
  }
32
31
 
33
32
  /**
@@ -48,8 +47,10 @@ export function iterateChildren(container, callback) {
48
47
  */
49
48
  export function iterateRowCells(row, callback) {
50
49
  getBodyRowCells(row).forEach(callback);
51
- if (row.__detailsCell) {
52
- callback(row.__detailsCell);
50
+
51
+ const detailsCell = row.querySelector('.details-cell');
52
+ if (detailsCell) {
53
+ callback(detailsCell);
53
54
  }
54
55
  }
55
56
 
@@ -17,7 +17,7 @@ function isCell(element) {
17
17
  }
18
18
 
19
19
  function isDetailsCell(element) {
20
- return element.matches('[part~="details-cell"]');
20
+ return element.classList.contains('details-cell');
21
21
  }
22
22
 
23
23
  export const KeyboardNavigationMixin = (superClass) =>
@@ -641,6 +641,8 @@ export const KeyboardNavigationMixin = (superClass) =>
641
641
 
642
642
  /** @private */
643
643
  _predictFocusStepTarget(srcElement, step) {
644
+ this._debounceColumnContentVisibility?.flush();
645
+
644
646
  const tabOrder = [
645
647
  this.$.table,
646
648
  this._headerFocusable,
@@ -676,8 +678,8 @@ export const KeyboardNavigationMixin = (superClass) =>
676
678
  if (focusStepTarget === this._headerFocusable) {
677
679
  focusStepTarget = firstVisibleColumn._headerCell;
678
680
  } else if (focusStepTarget === this._itemsFocusable) {
679
- const rowIndex = focusStepTarget._column._cells.indexOf(focusStepTarget);
680
- focusStepTarget = firstVisibleColumn._cells[rowIndex];
681
+ const row = focusStepTarget.parentElement;
682
+ focusStepTarget = [...row.children].find((cell) => cell._column === firstVisibleColumn);
681
683
  } else if (focusStepTarget === this._footerFocusable) {
682
684
  focusStepTarget = firstVisibleColumn._footerCell;
683
685
  }
@@ -434,14 +434,16 @@ export const GridMixin = (superClass) =>
434
434
  iterateRowCells(row, (cell) => {
435
435
  cell._vacant = true;
436
436
  });
437
+
438
+ const detailsCell = row.querySelector('.details-cell');
439
+ if (detailsCell) {
440
+ this.__teardownDetailsCell(detailsCell);
441
+ }
442
+
437
443
  row.innerHTML = '';
438
444
  if (section === 'body') {
439
445
  // Clear the cached cell references
440
446
  row.__cells = [];
441
- if (row.__detailsCell) {
442
- this.__teardownDetailsCell(row.__detailsCell);
443
- }
444
- row.__detailsCell = null;
445
447
  }
446
448
 
447
449
  columns
@@ -490,8 +492,6 @@ export const GridMixin = (superClass) =>
490
492
  this._configureDetailsCell(detailsCell);
491
493
  detailsCell.__parentRow = row;
492
494
  row.appendChild(detailsCell);
493
- // Cache the details cell reference
494
- row.__detailsCell = detailsCell;
495
495
  this.__a11ySetRowDetailsCell(row, detailsCell);
496
496
  detailsCell._vacant = false;
497
497
  }
@@ -565,6 +565,10 @@ export const GridMixin = (superClass) =>
565
565
  * @protected
566
566
  */
567
567
  _renderColumnTree(columnTree) {
568
+ // This render uses the current hidden state of all columns,
569
+ // so a pending render from a hidden change is not needed
570
+ this._debouncerHiddenChanged?.cancel();
571
+
568
572
  iterateChildren(this.$.items, (row) => {
569
573
  this.__initRow(row, columnTree[columnTree.length - 1], 'body', true);
570
574
  this.__updateRow(row);
@@ -575,7 +579,7 @@ export const GridMixin = (superClass) =>
575
579
  // Sizer rows
576
580
  this.__initRow(this.$.sizer, columnTree[columnTree.length - 1]);
577
581
 
578
- this._resizeHandler();
582
+ this.__updateHorizontalScrollPosition();
579
583
  this.__a11yUpdateHeaderRows();
580
584
  this.__a11yUpdateFooterRows();
581
585
  this.__updateHeaderAndFooter();
@@ -645,12 +649,6 @@ export const GridMixin = (superClass) =>
645
649
  this.__a11yUpdateRowExpanded(row, model.expanded);
646
650
  }
647
651
 
648
- /** @private */
649
- _resizeHandler() {
650
- this._updateDetailsCellHeights();
651
- this.__updateHorizontalScrollPosition();
652
- }
653
-
654
652
  /**
655
653
  * @param {!HTMLTableRowElement} row
656
654
  * @return {!GridItemModel}
@@ -86,7 +86,7 @@ export const RowDetailsMixin = (superClass) =>
86
86
  if (this._columnTree) {
87
87
  // Only update the rows if the column tree has already been initialized
88
88
  this._getRenderedRows().forEach((row) => {
89
- if (!row.querySelector('[part~=details-cell]')) {
89
+ if (!row.querySelector('.details-cell')) {
90
90
  this.__initRow(row, this._columnTree[this._columnTree.length - 1]);
91
91
  this.__updateRow(row);
92
92
  return;
@@ -133,7 +133,7 @@ export const RowDetailsMixin = (superClass) =>
133
133
  * @protected
134
134
  */
135
135
  _toggleDetailsCell(row, detailsOpened) {
136
- const cell = row.querySelector('[part~="details-cell"]');
136
+ const cell = row.querySelector('.details-cell');
137
137
  if (!cell) {
138
138
  return;
139
139
  }
@@ -153,7 +153,7 @@ export const RowDetailsMixin = (superClass) =>
153
153
 
154
154
  /** @protected */
155
155
  _updateDetailsCellHeight(row) {
156
- const cell = row.querySelector('[part~="details-cell"]');
156
+ const cell = row.querySelector('.details-cell');
157
157
  if (!cell) {
158
158
  return;
159
159
  }
@@ -172,13 +172,6 @@ export const RowDetailsMixin = (superClass) =>
172
172
  }
173
173
  }
174
174
 
175
- /** @protected */
176
- _updateDetailsCellHeights() {
177
- this._getRenderedRows().forEach((row) => {
178
- this._updateDetailsCellHeight(row);
179
- });
180
- }
181
-
182
175
  /**
183
176
  * @param {!GridItem} item
184
177
  * @return {boolean}
@@ -134,6 +134,24 @@ export const ScrollMixin = (superClass) =>
134
134
  this.addController(this.__overflowController);
135
135
  }
136
136
 
137
+ /** @protected */
138
+ updated(props) {
139
+ super.updated(props);
140
+
141
+ if (props.has('dir')) {
142
+ // Transforms calculated for the previous direction can push the
143
+ // containers and the frozen-to-end cells outside the table and increase
144
+ // its scroll width, so reset them before calculating the new position.
145
+ [this.$.header, this.$.items, this.$.footer, ...this._frozenToEndCells].forEach((element) => {
146
+ element.style.transform = '';
147
+ });
148
+ // The columns in the viewport and their offset with lazy column
149
+ // rendering depend on the direction as well
150
+ this.__updateColumnsBodyContentHidden();
151
+ this.__updateHorizontalScrollPosition();
152
+ }
153
+ }
154
+
137
155
  /**
138
156
  * Scroll to a specific row index in the virtual list. Note that the row index is
139
157
  * not always the same for any particular item. For example, sorting or filtering
@@ -406,7 +424,7 @@ export const ScrollMixin = (superClass) =>
406
424
  /** @protected */
407
425
  _frozenCellsChanged() {
408
426
  this._debouncerCacheElements = Debouncer.debounce(this._debouncerCacheElements, microTask, () => {
409
- Array.from(this.shadowRoot.querySelectorAll('[part~="cell"]')).forEach((cell) => {
427
+ Array.from(this.shadowRoot.querySelectorAll('.cell')).forEach((cell) => {
410
428
  cell.style.transform = '';
411
429
  });
412
430
  this._frozenCells = Array.prototype.slice.call(this.$.table.querySelectorAll('[frozen]'));
@@ -518,18 +536,18 @@ export const ScrollMixin = (superClass) =>
518
536
  }
519
537
  });
520
538
 
521
- const focusedRow = this.shadowRoot.querySelector("[part~='row']:focus");
539
+ const focusedRow = this.shadowRoot.querySelector('.row:focus');
522
540
  if (focusedRow) {
523
541
  // Update the horizontal scroll position property of the focused row
524
542
  this.__updateRowScrollPositionProperty(focusedRow);
525
543
  }
526
544
 
527
- const lastHeaderRow = this.$.header.querySelector("[part~='last-header-row']");
545
+ const lastHeaderRow = this.$.header.querySelector('.last-header-row');
528
546
  if (lastHeaderRow) {
529
547
  this.__updateRowScrollPositionProperty(lastHeaderRow);
530
548
  }
531
549
 
532
- const firstFooterRow = this.$.footer.querySelector("[part~='first-footer-row']");
550
+ const firstFooterRow = this.$.footer.querySelector('.first-footer-row');
533
551
  if (firstFooterRow) {
534
552
  this.__updateRowScrollPositionProperty(firstFooterRow);
535
553
  }
@@ -4,6 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { addListener, setTouchAction } from '@vaadin/component-base/src/gestures.js';
7
+ import { getClosestCell } from './vaadin-grid-helpers.js';
7
8
 
8
9
  /**
9
10
  * A mixin that provides basic functionality for the
@@ -225,7 +226,7 @@ export const GridSelectionColumnBaseMixin = (superClass) =>
225
226
  // the row have run in the current task, as the selection column may
226
227
  // render before the row header column.
227
228
  queueMicrotask(() => {
228
- const row = root.assignedSlot?.parentElement?.__parentRow;
229
+ const row = getClosestCell(root)?.__parentRow;
229
230
  if (!checkbox.isConnected || !row) {
230
231
  return;
231
232
  }