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: handle focus button mode columns for reordering #7273

Merged
merged 10 commits into from
Mar 28, 2024
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
Loading