-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 Alt+c being ignored on some systems #3660
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3f520b2
[test] cover alt+c copy
cherniavskii a784117
[DataGrid] Fix Alt+c being ignored on some systems
cherniavskii a0fc376
[test] Do not skip clipboard tests in real browser
cherniavskii 6490f5e
[docs] Update MacOS key assignment
cherniavskii b35b309
use keyCode instead of code
cherniavskii a957848
fix failing tests
cherniavskii 8b8355c
Merge branch 'master' into fix-copy-to-clipboard
cherniavskii 735192b
fix failing test
cherniavskii f589472
fix failing test
cherniavskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,13 +48,6 @@ describe('<DataGridPro /> - Clipboard', () => { | |
describe('copySelectedRowsToClipboard', () => { | ||
let writeText; | ||
|
||
before(function beforeHook() { | ||
if (!isJSDOM) { | ||
cherniavskii marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Needs permission to read the clipboard | ||
this.skip(); | ||
} | ||
}); | ||
|
||
beforeEach(function beforeEachHook() { | ||
writeText = stub().resolves(); | ||
|
||
|
@@ -94,5 +87,31 @@ describe('<DataGridPro /> - Clipboard', () => { | |
expect(writeText.firstCall.args[0]).to.equal(['0\tNike', '1\tAdidas'].join('\r\n')); | ||
}); | ||
}); | ||
|
||
it(`should copy the selected rows and headers to the clipboard when Alt + C is pressed`, () => { | ||
render(<Test />); | ||
apiRef.current.selectRows([0, 1]); | ||
const cell = getCell(0, 0); | ||
cell.focus(); | ||
fireEvent.keyDown(cell, { key: 'c', altKey: true }); | ||
expect(writeText.callCount).to.equal(1, "writeText wasn't called"); | ||
expect(writeText.firstCall.args[0]).to.equal( | ||
['id\tBrand', '0\tNike', '1\tAdidas'].join('\r\n'), | ||
); | ||
}); | ||
|
||
it(`should copy the selected rows and headers to the clipboard when Alt + C is pressed with modified key`, () => { | ||
render(<Test />); | ||
apiRef.current.selectRows([0, 1]); | ||
const cell = getCell(0, 0); | ||
cell.focus(); | ||
// On some systems (e.g. MacOS) Alt+C might add accents to letters (like Alt+c gives ç) | ||
// depending on keyboard layout and language | ||
fireEvent.keyDown(cell, { key: 'ç', altKey: true, code: 'KeyC' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not ideal, but that's the best I could do to cover this test case. |
||
expect(writeText.callCount).to.equal(1, "writeText wasn't called"); | ||
expect(writeText.firstCall.args[0]).to.equal( | ||
['id\tBrand', '0\tNike', '1\tAdidas'].join('\r\n'), | ||
); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be enough to check the physical keyboard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'm just being cautious here.
There are different layouts, and for example
KeyC
will be returned forC
key on QWERTY andJ
key on Dvorak.If we remove
event.key
,Alt+C
on Dvorak layout won't work, which is a bad UX.So I think it's better to keep both.
Here's some context on this https://ux.stackexchange.com/questions/30666/keyboard-shortcuts-on-non-qwerty-keyboard-layouts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Dvorak keyboard case is interesting, I didn't know that it would have an influence here. It's the time I see it relevant in a discussion on MUI 😁. But for a macOS user with a Dvorak keyboard, would it mean that a user would need to press Option + J?
In this case maybe?
Anyway, it's a detail. I might not have the time to check your answer, feel free to move forward with what you think of best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that's the only solution that would work consistently on every layout (
Alt
/Option
+C
, whereC
is the key that is marked asC
on system keyboard layout)The problem with
keyCode
is that it's deprecated in favor ofkey
andcode
.keyCode
is still supported by browsers, since a lot of apps use it.This made me think if
Alt
/Option
+C
is a good idea for keyboard shortcut. Because it has direct impact on another feature ofDataGrid
- Editing.The problem
When user presses any printable key, grid cell enters edit mode (as per https://mui.com/components/data-grid/editing/#start-editing)
As we have seen here, on MacOS
Option
is a modifier key, andOption
+C
on most layouts results in printable key (e.g.ç
on British/U.S. layout) that IMHO should start edit mode. Currently, it doesn't and it's something we should fix.Proposal
Since
Alt+C
is the only shortcut that usesAlt
(see https://mui.com/components/data-grid/accessibility/#keyboard-navigation) and it's not a widespread shortcut (as opposed toCtrl+C/Ctrl+V
), I propose to change it to something that doesn't involveAlt
key:Ctrl+Shift+C
I think it makes more sense.
We need to add
event.preventDefault()
though, since this shortcut opens DevTools on MacOS 🙃Doubts
Technically it's a breaking change, but the functionality doesn't work on MacOS.
We can leave current implementation for backward compatibility though.
What do you think?
Action points
Alt+C
shortcut toCtrl+Shift+C
Alt
/Option
- this might be a tricky one, since I'm not sure yet how we define "printable key". This can be explored in a separate issue.Would love some input from @mui-org/x members
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to:
event.keyCode
)