Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent grid body from expanding on dragover #3263

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/grid/src/vaadin-grid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,15 @@ export interface GridEventMap<TItem> extends HTMLElementEventMap, GridCustomEven
* `reorder-status` | Reflects the status of a cell while columns are being reordered | cell
* `frozen` | Frozen cell | cell
* `last-frozen` | Last frozen cell | cell
* * `first-column` | First visible cell on a row | cell
* `first-column` | First visible cell on a row | cell
* `last-column` | Last visible cell on a row | cell
* `selected` | Selected row | row
* `expanded` | Expanded row | row
* `details-opened` | Row with details open | row
* `loading` | Row that is waiting for data from data provider | row
* `odd` | Odd row | row
* `first` | The first body row | row
* `last` | The last body row | row
* `dragstart` | Set for one frame when drag of a row is starting. The value is a number when multiple rows are dragged | row
* `dragover` | Set when the row is dragged over | row
* `drag-disabled` | Set to a row that isn't available for dragging | row
Expand Down
5 changes: 4 additions & 1 deletion packages/grid/src/vaadin-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ import { StylingMixin } from './vaadin-grid-styling-mixin.js';
* `reorder-status` | Reflects the status of a cell while columns are being reordered | cell
* `frozen` | Frozen cell | cell
* `last-frozen` | Last frozen cell | cell
* * `first-column` | First visible cell on a row | cell
* `first-column` | First visible cell on a row | cell
* `last-column` | Last visible cell on a row | cell
* `selected` | Selected row | row
* `expanded` | Expanded row | row
* `details-opened` | Row with details open | row
* `loading` | Row that is waiting for data from data provider | row
* `odd` | Odd row | row
* `first` | The first body row | row
* `last` | The last body row | row
* `dragstart` | Set for one frame when drag of a row is starting. The value is a number when multiple rows are dragged | row
* `dragover` | Set when the row is dragged over | row
* `drag-disabled` | Set to a row that isn't available for dragging | row
Expand Down Expand Up @@ -489,6 +490,7 @@ class Grid extends ElementMixin(
const cellCoordinates = this.__getBodyCellCoordinates(cell);

virtualizer.size = effectiveSize;
virtualizer.update();
virtualizer.flush();

// If the focused cell's parent row got hidden by the size change, focus the corresponding new cell
Expand Down Expand Up @@ -821,6 +823,7 @@ class Grid extends ElementMixin(
}

row.toggleAttribute('first', index === 0);
row.toggleAttribute('last', index === this._effectiveSize - 1);
row.toggleAttribute('odd', index % 2);
this._a11yUpdateRowRowindex(row, index);
this._getItem(index, row);
Expand Down
12 changes: 12 additions & 0 deletions packages/grid/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ describe('basic features', () => {
expect(parseInt(window.getComputedStyle(grid).getPropertyValue('flex-grow'))).to.equal(1);
expect(window.getComputedStyle(grid).getPropertyValue('flex-basis')).to.equal('auto');
});

it('should have attribute last on the last body row', () => {
grid.scrollToIndex(grid.size - 1);
const lastRowSlot = grid.shadowRoot.querySelector('[part~="row"][last] slot');
expect(lastRowSlot.assignedNodes()[0].textContent).to.equal(String(grid.size - 1));
});

it('should have attribute last on the last body row after resize', () => {
grid.size = 2;
const lastRowSlot = grid.shadowRoot.querySelector('[part~="row"][last] slot');
expect(lastRowSlot.assignedNodes()[0].textContent).to.equal(String(grid.size - 1));
});
});

describe('flex child', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/grid/test/visual/lumo/grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,12 @@ describe('grid', () => {
element.$.items.children[1].setAttribute('dragstart', '123');
await visualDiff(element, 'row-dragstart');
});

it('dragover below last row when all rows visible', async () => {
element.allRowsVisible = true;
element.items = element.items.slice(0, 2);
element.$.items.children[1].setAttribute('dragover', 'below');
await visualDiff(element, 'dragover-below-last-row-all-rows-visible');
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions packages/grid/test/visual/material/grid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,12 @@ describe('grid', () => {
element.$.items.children[1].setAttribute('dragstart', '123');
await visualDiff(element, 'row-dragstart');
});

it('dragover below last row when all rows visible', async () => {
element.allRowsVisible = true;
element.items = element.items.slice(0, 2);
element.$.items.children[1].setAttribute('dragover', 'below');
await visualDiff(element, 'dragover-below-last-row-all-rows-visible');
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/grid/theme/lumo/vaadin-grid-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ registerStyles(
margin-top: -1px;
}

:host([all-rows-visible]) [part~='row'][last][dragover='below'] [part~='cell']::after {
height: 1px;
}

[part~='row'][dragover='above'] [part~='cell']::after {
top: auto;
bottom: 100%;
Expand Down
4 changes: 4 additions & 0 deletions packages/grid/theme/material/vaadin-grid-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ registerStyles(
margin-top: -1px;
}

:host([all-rows-visible]) [part~='row'][last][dragover='below'] [part~='cell']::after {
height: 1px;
}

[part~='row'][dragover='above'] [part~='cell']::after {
top: auto;
bottom: 100%;
Expand Down