Skip to content

Commit

Permalink
fix: improve controller navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaUnknown committed May 17, 2024
1 parent bcbb01f commit 2862b02
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions common/modules/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2862b02

Please sign in to comment.