Skip to content

Commit

Permalink
fix: handle focus button mode columns for reordering (#7273)
Browse files Browse the repository at this point in the history
* fix: handle focus button mode columns for reordering

* Update packages/grid/src/vaadin-grid-column-reordering-mixin.js

Co-authored-by: Sergey Vinogradov <[email protected]>

* chore: fix format

* test: revert skipped tests that pass with the fix

* test: add test for focus button mode column reordering

* test: add test for reordering by dropping column on body cells

* test: add test for focus button mode column reordering

* test: remove duplicate test

* Update packages/grid/src/vaadin-grid-column-reordering-mixin.js

Co-authored-by: Sergey Vinogradov <[email protected]>

* Update packages/grid/test/column-reordering.common.js

Co-authored-by: Sergey Vinogradov <[email protected]>

---------

Co-authored-by: Sergey Vinogradov <[email protected]>
  • Loading branch information
ugur-vaadin and vursen authored Mar 28, 2024
1 parent 19e1f16 commit 27a5d55
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/grid-pro/test/keyboard-navigation.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('keyboard navigation', () => {
expect(getCellEditor(firstCell)).to.be.not.ok;
});

it.skip('should focus correct editable cell after column reordering', () => {
it('should focus correct editable cell after column reordering', () => {
grid.columnReorderingAllowed = true;
const headerContent = [
getContainerCell(grid.$.header, 0, 0)._content,
Expand Down
21 changes: 17 additions & 4 deletions packages/grid/src/vaadin-grid-column-reordering-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,26 @@ export const ColumnReorderingMixin = (superClass) =>
if (!this._draggedColumn) {
this.$.scroller.toggleAttribute('no-content-pointer-events', true);
}
const cell = this.shadowRoot.elementFromPoint(x, y);
const elementFromPoint = this.shadowRoot.elementFromPoint(x, y);
this.$.scroller.toggleAttribute('no-content-pointer-events', false);

// Make sure the element is actually a cell
if (cell && cell._column) {
return cell;
return this._getCellFromElement(elementFromPoint);
}

/** @private */
_getCellFromElement(element) {
if (element) {
// Check if element is a cell
if (element._column) {
return element;
}
// Check if element is the cell of a focus button mode column
const { parentElement } = element;
if (parentElement && parentElement._focusButton === element) {
return parentElement;
}
}
return null;
}

/**
Expand Down
35 changes: 35 additions & 0 deletions packages/grid/test/column-reordering.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,41 @@ describe('reordering simple grid', () => {
const e = spy.firstCall.args[0];
expect(e.detail.columns.map((column) => column.getAttribute('index'))).to.eql(['2', '1', '3', '4']);
});

describe('focus button mode', () => {
beforeEach(() => {
grid = fixtureSync(`
<vaadin-grid column-reordering-allowed>
<vaadin-grid-column path="name"></vaadin-grid-column>
<vaadin-grid-column path="age"></vaadin-grid-column>
</vaadin-grid>
`);
grid.querySelectorAll('vaadin-grid-column').forEach((col) => {
col._focusButtonMode = true;
});
grid.items = [
{ name: 'John', age: 30 },
{ name: 'Ringo', age: 40 },
];
flushGrid(grid);
headerContent = [
getContainerCell(grid.$.header, 0, 0)._content,
getContainerCell(grid.$.header, 0, 1)._content,
];
});

it('should allow dropping over header cell of another column', () => {
dragAndDropOver(headerContent[0], headerContent[1]);
expect(getVisualHeaderCellContent(grid, 0, 0).innerText).to.be.equal('Age');
expect(getVisualHeaderCellContent(grid, 0, 1).innerText).to.be.equal('Name');
});

it('should allow dropping over body cell of another column', () => {
dragAndDropOver(headerContent[0], getVisualCellContent(grid.$.items, 0, 1));
expect(getVisualHeaderCellContent(grid, 0, 0).innerText).to.be.equal('Age');
expect(getVisualHeaderCellContent(grid, 0, 1).innerText).to.be.equal('Name');
});
});
});

describe('frozen columns', () => {
Expand Down

0 comments on commit 27a5d55

Please sign in to comment.