Skip to content

Commit

Permalink
fix(VAppBar): inability to scroll to the bottom (#19921)
Browse files Browse the repository at this point in the history
fixes #19090
  • Loading branch information
lzl0304 authored Jun 11, 2024
1 parent 193301c commit 7ccff92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,28 @@ describe('VAppBar', () => {
.get('.v-app-bar').should('not.be.visible')
})

it('should hide correctly when scroll to the bottom', () => {
cy.mount(({ scrollBehavior }: any) => (
<VLayout>
<VAppBar scrollBehavior={ scrollBehavior } />

<VMain style="min-height: 300px">
{
Array.from({ length: 7 }, () => (
<div class="pa-16 ma-2 w-50 bg-green text-center">
box
</div>
))
}
</VMain>
</VLayout>
))
.setProps({ scrollBehavior: 'hide' })
.get('.v-app-bar').should('be.visible')
.window().scrollTo('bottom')
.get('.v-app-bar').should('not.be.visible')
})

it('collapses', () => {
cy.mount(({ scrollBehavior }: any) => (
<VLayout>
Expand Down
7 changes: 7 additions & 0 deletions packages/vuetify/src/composables/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function useScroll (
) {
const { canScroll } = args
let previousScroll = 0
let previousScrollHeight = 0
const target = ref<Element | Window | null>(null)
const currentScroll = shallowRef(0)
const savedScroll = shallowRef(0)
Expand Down Expand Up @@ -71,6 +72,12 @@ export function useScroll (
previousScroll = currentScroll.value
currentScroll.value = ('window' in targetEl) ? targetEl.pageYOffset : targetEl.scrollTop

const currentScrollHeight = targetEl instanceof Window ? document.documentElement.scrollHeight : targetEl.scrollHeight
if (previousScrollHeight !== currentScrollHeight) {
previousScrollHeight = currentScrollHeight
return
}

isScrollingUp.value = currentScroll.value < previousScroll
currentThreshold.value = Math.abs(currentScroll.value - scrollThreshold.value)
}
Expand Down

0 comments on commit 7ccff92

Please sign in to comment.