Skip to content

Commit

Permalink
fix: prevent grid body from expanding on dragover (#2204)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Jan 20, 2022
1 parent 4ded1cc commit 9e1da36
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/vaadin-grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,15 @@
* `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 @@ -770,6 +771,7 @@
}

this._toggleAttribute('first', index === 0, row);
this._toggleAttribute('last', index === this._effectiveSize - 1, row);
this._toggleAttribute('odd', index % 2, row);
this._a11yUpdateRowRowindex(row, index);
this._getItem(index, row);
Expand Down
14 changes: 14 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@
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 lastRowCell = grid.shadowRoot.querySelector('[part~="row"][last] td');
const lastRowSlot = lastRowCell.firstElementChild;
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 lastRowCell = grid.shadowRoot.querySelector('[part~="row"][last] td');
const lastRowSlot = lastRowCell.firstElementChild;
expect(lastRowSlot.assignedNodes()[0].textContent).to.equal(String(grid.size - 1));
});

it('should keep row position after hiding/unhiding Grid', () => {
grid._scrollToIndex(100);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/visual/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ gemini.suite('vaadin-grid', (rootSuite) => {
grid.$.items.children[1].removeAttribute('dragover');
grid.$.items.children[1].setAttribute('dragstart', '123');
});
})
.capture('dragstart-below-last-row-all-rows-visible', {}, (actions) => {
actions.executeJS(function(window) {
var grid = window.document.querySelector('vaadin-grid');
grid.allRowsVisible = true;
grid.items = grid.items.slice(0, 2);
grid.$.items.children[1].removeAttribute('dragstart');
grid.$.items.children[1].setAttribute('dragover', 'below');
});
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions theme/lumo/vaadin-grid-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
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 theme/material/vaadin-grid-styles.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
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

0 comments on commit 9e1da36

Please # to comment.