Skip to content

Commit

Permalink
fix: scroll to just below title bar consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
shuuji3 committed Apr 7, 2024
1 parent 9ca6c9b commit 08f847f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions plugins/magic-keys.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineNuxtPlugin(({ $scrollToTop }) => {
const keys = useMagicKeys()
const router = useRouter()
const i18n = useNuxtApp().$i18n
const { y } = useWindowScroll({ behavior: 'smooth' })

// disable shortcuts when focused on inputs (https://vueuse.org/core/usemagickeys/#conditionally-disable)
const activeElement = useActiveElement()
Expand Down Expand Up @@ -96,8 +97,12 @@ export default defineNuxtPlugin(({ $scrollToTop }) => {
const activeStatusId = activeElement.value ? getActiveStatueId(activeElement.value) : undefined
const nextOrPreviousStatusId = getNextOrPreviousStatusId(activeStatusId, direction)
if (nextOrPreviousStatusId) {
document.getElementById(nextOrPreviousStatusId)?.scrollIntoView({ behavior: 'smooth', block: 'center' })
document.getElementById(nextOrPreviousStatusId)?.focus()
const status = document.getElementById(nextOrPreviousStatusId)
if (status) {
status.focus({ preventScroll: true })
const topBarHeight = 58
y.value += status.getBoundingClientRect().top - topBarHeight
}
}
}

Expand Down

0 comments on commit 08f847f

Please sign in to comment.