Skip to content

Commit

Permalink
[core] Ignore meta, ctrl and alt in keyboard modality detection (#17924)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeelibr authored and oliviertassinari committed Oct 18, 2019
1 parent f005567 commit 3729893
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/material-ui/src/utils/focusVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ function focusTriggersKeyboardModality(node) {
return false;
}

function handleKeyDown() {
/**
* Keep track of our keyboard modality state with `hadKeyboardEvent`.
* If the most recent user interaction was via the keyboard;
* and the key press did not include a meta, alt/option, or control key;
* then the modality is keyboard. Otherwise, the modality is not keyboard.
* @param {KeyboardEvent} event
*/
function handleKeyDown(event) {
if (event.metaKey || event.altKey || event.ctrlKey) {
return;
}
hadKeyboardEvent = true;
}

Expand All @@ -57,7 +67,6 @@ function handleKeyDown() {
* This avoids the situation where a user presses a key on an already focused
* element, and then clicks on a different element, focusing it with a
* pointing device, while we still think we're in keyboard modality.
* @param {Event} e
*/
function handlePointerDown() {
hadKeyboardEvent = false;
Expand Down Expand Up @@ -119,7 +128,6 @@ function handleBlurVisible() {
window.clearTimeout(hadFocusVisibleRecentlyTimeout);
hadFocusVisibleRecentlyTimeout = window.setTimeout(() => {
hadFocusVisibleRecently = false;
window.clearTimeout(hadFocusVisibleRecentlyTimeout);
}, 100);
}

Expand Down

0 comments on commit 3729893

Please sign in to comment.