mirror of
https://github.com/NoCrypt/migu.git
synced 2026-08-19 13:45:48 +00:00
fix: improve controller navigation
This commit is contained in:
parent
bcbb01fcf2
commit
2862b0235c
1 changed files with 3 additions and 4 deletions
|
|
@ -112,14 +112,12 @@ function getKeyboardFocusableElements (element = document.body) {
|
|||
function getElementPosition (element) {
|
||||
const { x, y, width, height, top, left, bottom, right } = element.getBoundingClientRect()
|
||||
const inViewport = isInViewport({ top, left, bottom, right })
|
||||
if (width || height) {
|
||||
return { element, x: x + width * 0.5, y: y + height * 0.5, inViewport }
|
||||
}
|
||||
return { element, x: x + width * 0.5, y: y + height * 0.5, inViewport }
|
||||
}
|
||||
|
||||
function getFocusableElementPositions () {
|
||||
const elements = []
|
||||
for (const element of getKeyboardFocusableElements()) {
|
||||
for (const element of getKeyboardFocusableElements(document.querySelector('.modal.show') ?? document.body)) {
|
||||
const position = getElementPosition(element)
|
||||
if (position) elements.push(position)
|
||||
}
|
||||
|
|
@ -165,6 +163,7 @@ function navigateDPad (direction = 'up') {
|
|||
}, { distance: Infinity, element: null })
|
||||
|
||||
closestElement.element.focus()
|
||||
closestElement.element.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' })
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue