Skip to content

Commit a725c7f

Browse files
authored
fix: ensure row cell parts are in place after setting rowDetailsRenderer (#10443)
1 parent 5550c66 commit a725c7f

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

packages/grid/src/vaadin-grid-a11y-mixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export const A11yMixin = (superClass) =>
8080
* @param {number} index
8181
* @private
8282
*/
83-
__a11yUpdateRowRowindex(row, index) {
84-
row.setAttribute('aria-rowindex', index + this.__a11yGetHeaderRowCount(this._columnTree) + 1);
83+
__a11yUpdateRowRowindex(row) {
84+
row.setAttribute('aria-rowindex', row.index + this.__a11yGetHeaderRowCount(this._columnTree) + 1);
8585
}
8686

8787
/**

packages/grid/src/vaadin-grid-mixin.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,6 @@ export const GridMixin = (superClass) =>
661661
}
662662

663663
row.index = index;
664-
665-
this._updateRowOrderParts(row, index);
666-
667-
this.__a11yUpdateRowRowindex(row, index);
668-
669664
this.__ensureRowItem(row);
670665
this.__ensureRowHierarchy(row);
671666
this.__updateRow(row);
@@ -678,17 +673,17 @@ export const GridMixin = (superClass) =>
678673
}
679674

680675
/** @private */
681-
_updateRowOrderParts(row, index = row.index) {
676+
__updateRowOrderParts(row) {
682677
updateBooleanRowStates(row, {
683-
first: index === 0,
684-
last: index === this._flatSize - 1,
685-
odd: index % 2 !== 0,
686-
even: index % 2 === 0,
678+
first: row.index === 0,
679+
last: row.index === this._flatSize - 1,
680+
odd: row.index % 2 !== 0,
681+
even: row.index % 2 === 0,
687682
});
688683
}
689684

690685
/** @private */
691-
_updateRowStateParts(row, { item, expanded, selected, detailsOpened }) {
686+
__updateRowStateParts(row, { item, expanded, selected, detailsOpened }) {
692687
updateBooleanRowStates(row, {
693688
expanded,
694689
collapsed: this.__isRowExpandable(row),
@@ -710,11 +705,7 @@ export const GridMixin = (superClass) =>
710705
_renderColumnTree(columnTree) {
711706
iterateChildren(this.$.items, (row) => {
712707
this.__initRow(row, columnTree[columnTree.length - 1], 'body', false, true);
713-
714-
const model = this.__getRowModel(row);
715-
this._updateRowOrderParts(row);
716-
this._updateRowStateParts(row, model);
717-
this._filterDragAndDrop(row, model);
708+
this.__updateRow(row);
718709
});
719710

720711
while (this.$.header.children.length < columnTree.length) {
@@ -791,6 +782,9 @@ export const GridMixin = (superClass) =>
791782
* @private
792783
*/
793784
__updateRow(row) {
785+
this.__a11yUpdateRowRowindex(row);
786+
this.__updateRowOrderParts(row);
787+
794788
const item = this.__getRowItem(row);
795789
if (item) {
796790
this.__updateRowLoading(row, false);
@@ -807,7 +801,7 @@ export const GridMixin = (superClass) =>
807801
this.__a11yUpdateRowLevel(row, model.level);
808802
this.__a11yUpdateRowSelected(row, model.selected);
809803

810-
this._updateRowStateParts(row, model);
804+
this.__updateRowStateParts(row, model);
811805

812806
this._generateCellClassNames(row, model);
813807
this._generateCellPartNames(row, model);

packages/grid/src/vaadin-grid-row-details-mixin.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export const RowDetailsMixin = (superClass) =>
8282
iterateChildren(this.$.items, (row) => {
8383
if (!row.querySelector('[part~=details-cell]')) {
8484
this.__initRow(row, this._columnTree[this._columnTree.length - 1]);
85-
const isDetailsOpened = this._isDetailsOpened(row._item);
86-
this._toggleDetailsCell(row, isDetailsOpened);
85+
this.__updateRow(row);
8786
}
8887
});
8988
}

packages/grid/test/row-details.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe('row details', () => {
329329
<vaadin-grid-column path="name"></vaadin-grid-column>
330330
</vaadin-grid>
331331
`);
332-
grid.items = [{ name: 'foo' }];
332+
grid.items = [{ name: 'foo' }, { name: 'bar' }];
333333
await nextFrame();
334334
bodyRows = getRows(grid.$.items);
335335
});
@@ -357,6 +357,14 @@ describe('row details', () => {
357357
const detailsCell = bodyRows[0].querySelector('[part~="details-cell"]');
358358
expect(detailsCell.hidden).to.be.false;
359359
});
360+
361+
it('should have order state parts on cells', async () => {
362+
grid.detailsOpenedItems = [...grid.items];
363+
grid.rowDetailsRenderer = () => {};
364+
await nextFrame();
365+
expect(bodyRows[0].children[0].getAttribute('part')).to.include('first-row-cell');
366+
expect(bodyRows[1].children[0].getAttribute('part')).to.include('last-row-cell');
367+
});
360368
});
361369

362370
describe('details cell height change', () => {

0 commit comments

Comments
 (0)