Skip to content

Commit

Permalink
feat(VAppBar): add support for fully-hide scroll-behavior (#19557)
Browse files Browse the repository at this point in the history
resolves #18020
  • Loading branch information
johnleider authored Apr 10, 2024
1 parent 45199a4 commit c6f6587
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions packages/vuetify/src/components/VAppBar/VAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const VAppBar = genericComponent<VToolbarSlots>()({
const behavior = new Set(props.scrollBehavior?.split(' ') ?? [])
return {
hide: behavior.has('hide'),
// fullyHide: behavior.has('fully-hide'),
fullyHide: behavior.has('fully-hide'),
inverted: behavior.has('inverted'),
collapse: behavior.has('collapse'),
elevate: behavior.has('elevate'),
Expand All @@ -69,7 +69,7 @@ export const VAppBar = genericComponent<VToolbarSlots>()({
const behavior = scrollBehavior.value
return (
behavior.hide ||
// behavior.fullyHide ||
behavior.fullyHide ||
behavior.inverted ||
behavior.collapse ||
behavior.elevate ||
Expand All @@ -85,11 +85,18 @@ export const VAppBar = genericComponent<VToolbarSlots>()({
scrollRatio,
} = useScroll(props, { canScroll })

const canHide = computed(() => (
scrollBehavior.value.hide ||
scrollBehavior.value.fullyHide
))
const isCollapsed = computed(() => props.collapse || (
scrollBehavior.value.collapse &&
(scrollBehavior.value.inverted ? scrollRatio.value > 0 : scrollRatio.value === 0)
))
const isFlat = computed(() => props.flat || (
scrollBehavior.value.fullyHide &&
!isActive.value
) || (
scrollBehavior.value.elevate &&
(scrollBehavior.value.inverted ? currentScroll.value > 0 : currentScroll.value === 0)
))
Expand All @@ -102,12 +109,16 @@ export const VAppBar = genericComponent<VToolbarSlots>()({
const height = Number(vToolbarRef.value?.contentHeight ?? props.height)
const extensionHeight = Number(vToolbarRef.value?.extensionHeight ?? 0)

return (height + extensionHeight)
if (!canHide.value) return (height + extensionHeight)

return currentScroll.value < scrollThreshold.value || scrollBehavior.value.fullyHide
? (height + extensionHeight)
: height
})

useToggleScope(computed(() => !!props.scrollBehavior), () => {
watchEffect(() => {
if (scrollBehavior.value.hide) {
if (canHide.value) {
if (scrollBehavior.value.inverted) {
isActive.value = currentScroll.value > scrollThreshold.value
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/vuetify/src/composables/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function createLayout (props: { overlaps?: string[], fullHeight?: boolean
const styles = {
[position.value]: 0,
zIndex: zIndex.value,
transform: `translate${isHorizontal ? 'X' : 'Y'}(${(active.value ? 0 : -110) * (isOppositeHorizontal || isOppositeVertical ? -1 : 1)}%)`,
transform: `translate${isHorizontal ? 'X' : 'Y'}(${(active.value ? 0 : -layoutSize.value) * (isOppositeHorizontal || isOppositeVertical ? -1 : 1)}px)`,
position: absolute.value || rootZIndex.value !== ROOT_ZINDEX ? 'absolute' : 'fixed',
...(transitionsEnabled.value ? undefined : { transition: 'none' }),
} as const
Expand Down

0 comments on commit c6f6587

Please sign in to comment.