Skip to content

Commit

Permalink
[DataGrid] Fix Space triggering edit mode (#8180)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw authored Mar 13, 2023
1 parent a3e43d2 commit bdbe836
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ describe('<DataGridPro /> - Cell Editing', () => {
fireEvent.keyDown(cell, { key: '$' });
expect(listener.lastCall.args[0].reason).to.equal('printableKeyDown');
});

it(`should not publish 'cellEditStart' if space is pressed`, () => {
render(<TestCase autoHeight />);
const listener = spy();
apiRef.current.subscribeEvent('cellEditStart', listener);
const cell = getCell(0, 1);
userEvent.mousePress(cell);
fireEvent.keyDown(cell, { key: ' ' });
expect(listener.callCount).to.equal(0);
});
});

describe('by pressing a number', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,16 @@ describe('<DataGridPro /> - Row Editing', () => {
expect(listener.callCount).to.equal(1);
});

it('should not call startRowEditMode if space is pressed', () => {
render(<TestCase autoHeight />);
const listener = spy();
apiRef.current.subscribeEvent('rowEditStart', listener);
const cell = getCell(0, 1);
userEvent.mousePress(cell);
fireEvent.keyDown(cell, { key: ' ' });
expect(listener.callCount).to.equal(0);
});

it(`should call startRowEditMode if ctrl+V is pressed`, () => {
render(<TestCase />);
const listener = spy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export const useGridCellEditing = (
} else if (params.isEditable) {
let reason: GridCellEditStartReasons | undefined;

if (event.key === ' ' && event.shiftKey) {
return; // Shift + Space is used to select the row
if (event.key === ' ') {
return; // Space scrolls to the last row
}

if (isPrintableKey(event)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export const useGridRowEditing = (
} else if (params.isEditable) {
let reason: GridRowEditStartReasons | undefined;

if (event.key === ' ' && event.shiftKey) {
return; // Shift + Space is used to select the row
if (event.key === ' ') {
return; // Space scrolls to the last row
}

if (isPrintableKey(event)) {
Expand Down

0 comments on commit bdbe836

Please sign in to comment.