Skip to content
API 风格:

FloatingPanel ​

A fixed bottom floating panel: anchors (anchors) accept numeric px values and 'percentage' strings (converted against the viewport height). The header and content area (contentDraggable) drag with the finger (computeDragHeight + --dragging disables transitions), and on release the panel snaps to the nearest anchor (resolveSnapIndex). The anchor index supports a controlled modelValue; when unmanaged, an internal state is used as fallback.

Basic Usage ​

The default anchors are [60, '40%'] (40% is converted against the viewport height); the drag handle snaps between the lowest and highest anchors:

Basic floating panel
Panel content: drag up to expand to 40% of the viewport height
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhFloatingPanel } from '@lh-ui/vue3'

// Unmanaged: the anchor index is kept inside the component; the change callback receives the index
const anchorIndex = ref(0)
</script>

<template>
  <LhFloatingPanel @change="(i) => (anchorIndex = i)">
    <div>Panel content</div>
  </LhFloatingPanel>
</template>

Controlled anchors (v-model) ​

Passing modelValue makes it controlled: on release only update:modelValue / change are emitted, and the anchor is up to the consumer; if the consumer does not update, the panel springs back to the current anchor:

Controlled anchors
Currently at anchor 2 (40% of the viewport height)
vue
<LhFloatingPanel v-model="anchorIndex" :anchors="[60, '40%']" />

Custom anchors ​

Numbers and percentages can be mixed; they are converted, sorted ascending and deduplicated internally:

Custom anchors
Three anchors: 80px / 30% / 70% of the viewport height
vue
<LhFloatingPanel :anchors="[80, '30%', '70%']" />

Header slot and options ​

The header slot overrides the default handle (the drag gesture still binds to the header); with contentDraggable=false only the header is draggable while the content area scrolls normally; safeAreaInsetBottom=false removes the bottom safe-area padding; disabled disables dragging:

Custom header
Drag me to expand
Only the header is draggable (content-draggable=false)
vue
<LhFloatingPanel :content-draggable="false">
  <template #header>
    <div class="custom-handle">Drag me to expand</div>
  </template>
  <div>Content</div>
</LhFloatingPanel>

API ​

FloatingPanel Props ​

PropDescriptionTypeDefault
anchorsSnap height array (numeric px or 'percentage' strings; converted / sorted / deduplicated automatically)(number | string)[][60, '40%']
modelValueCurrent anchor index (controlled; falls back to internal state when not passed)number—
contentDraggableContent area draggable (when false, only the header is draggable)booleantrue
safeAreaInsetBottomBottom safe-area padding (adds the --safe-area modifier)booleantrue
disabledDisable draggingbooleanfalse
sxsx quick-layout propsLhSxProps—

FloatingPanel Events ​

EventDescriptionCallback
update:modelValueAnchor index change (v-model hook)(index: number)
changeAnchor index change after a release snap(anchorIndex: number)
heightChangePanel height change (both drag-follow and snap paths)(height: number)

FloatingPanel Slots ​

SlotDescriptionScoped props
headerDrag handle area (renders the __handle indicator bar by default; the drag gesture always binds to the header)—
defaultPanel content—

Accessibility ​

The root node's aria-label is generated by getFloatingPanelAria (custom first, otherwise "Floating panel, anchor i of N"); when disabled, the --disabled modifier cuts off pointer events.

Beauty of tradition, foundation of code