parent
488e87bda1
commit
ce33c80b6d
|
@ -65,7 +65,7 @@ export function leftRightFocusObservers (store) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
function focusNextOrPrevious (e, key) {
|
function focusNextOrPrevious (event, key) {
|
||||||
const { activeElement } = document
|
const { activeElement } = document
|
||||||
if (shouldIgnoreEvent(activeElement, key)) {
|
if (shouldIgnoreEvent(activeElement, key)) {
|
||||||
return
|
return
|
||||||
|
@ -81,26 +81,35 @@ export function leftRightFocusObservers (store) {
|
||||||
element = focusable[index + 1] || focusable[focusable.length - 1]
|
element = focusable[index + 1] || focusable[focusable.length - 1]
|
||||||
}
|
}
|
||||||
element.focus()
|
element.focus()
|
||||||
e.preventDefault()
|
event.preventDefault()
|
||||||
e.stopPropagation()
|
event.stopPropagation()
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEnter (e) {
|
function handleEnter (event) {
|
||||||
const { activeElement } = document
|
const { activeElement } = document
|
||||||
if (activeElement.tagName === 'INPUT' && ['checkbox', 'radio'].includes(activeElement.getAttribute('type'))) {
|
if (activeElement.tagName === 'INPUT' && ['checkbox', 'radio'].includes(activeElement.getAttribute('type'))) {
|
||||||
// Explicitly override "enter" on an input and make it fire the checkbox/radio
|
// Explicitly override "enter" on an input and make it fire the checkbox/radio
|
||||||
activeElement.click()
|
activeElement.click()
|
||||||
e.preventDefault()
|
event.preventDefault()
|
||||||
e.stopPropagation()
|
event.stopPropagation()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function keyListener (e) {
|
function keyListener (event) {
|
||||||
const { key } = e
|
if (event.altKey || event.metaKey || event.ctrlKey) {
|
||||||
if (key === 'ArrowRight' || key === 'ArrowLeft') {
|
return // ignore e.g. Alt-Left and Ctrl-Right, which are used to switch browser tabs or navigate back/forward
|
||||||
focusNextOrPrevious(e, key)
|
}
|
||||||
} else if (key === 'Enter') {
|
const { key } = event
|
||||||
handleEnter(e)
|
switch (key) {
|
||||||
|
case 'ArrowLeft':
|
||||||
|
case 'ArrowRight': {
|
||||||
|
focusNextOrPrevious(event, key)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case 'Enter': {
|
||||||
|
handleEnter(event)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue