Skip to content

useAutoFillHeight ​

Sizes an element so it fills the page from its own top edge down to the bottom of the viewport, or to the top of a Vuetify bottom bar. It powers the fill prop of WeDatatable and works at any nesting depth, without a flex chain in the parents.

Usage ​

vue
<script setup>
const panel = useTemplateRef('panel')
const { height } = useAutoFillHeight(panel)
</script>

<template>
  <v-card ref="panel" :style="{ height }" class="overflow-auto">
    …
  </v-card>
</template>

Type Signature ​

ts
function useAutoFillHeight(
  target: MaybeRefOrGetter<HTMLElement | { $el?: HTMLElement } | null | undefined>,
  enabled?: MaybeRefOrGetter<boolean | number | string>, // default true
): {
  height: Ref<string | undefined>
  recompute: () => void
}

Parameters ​

ParameterTypeDefaultDescription
targetMaybeRefOrGetter<HTMLElement | component>—Element to size, or a component instance (its $el is used)
enabledMaybeRefOrGetter<boolean | number | string>truefalse disables; true fills with no bottom gap; a number (or numeric string, e.g. fill="16") leaves that gap in px

Return Value ​

PropertyTypeDescription
heightRef<string | undefined>calc(100dvh - <top>px - var(--v-layout-bottom, 0px) - <gap>px), or undefined while disabled. Bind it to the element's height
recompute() => voidMeasures again — for layout changes the observers can't see

When it recomputes ​

  • After mount (next tick).
  • On window resize.
  • When the height of any ancestor changes (via ResizeObserver); width-only changes are ignored.
  • When enabled changes.

Only the element's top offset is measured; the rest is left to CSS (100dvh and Vuetify's --v-layout-bottom).

TIP

Keep the containers below the element free of bottom padding (e.g. pb-0 on the v-container), otherwise the page gets a second scrollbar.

Source Code ​