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

[DataGrid] Fix Space triggering edit mode #8180

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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