# FloatingPanel
A floating panel pinned to the bottom that snaps to anchor steps (anchor geometry and snap computation live in @lh-ui/share/core/floating-panel); root class lh-floating-panel, styles come from share styles/floating-panel.
<template>
<div class="demo-col" style="gap: 18px; max-width: 480px">
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="anchorIndex = 0">Collapse to lowest step</LhButton>
<LhButton size="small" @click="anchorIndex = 1">Middle step</LhButton>
<LhButton size="small" @click="anchorIndex = 2">Expand to highest step</LhButton>
<LhButton size="small" @click="contentDraggable = !contentDraggable">Content draggable ({{ contentDraggable }})</LhButton>
</div>
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="safeArea = !safeArea">Safe-area padding ({{ safeArea }})</LhButton>
<LhButton size="small" @click="disabled = !disabled">Disabled ({{ disabled }})</LhButton>
</div>
<span class="demo-note">
Step: {{ anchorIndex }} / live height: {{ height }}px (anchors: 60px / 40% / 80% of viewport height)
</span>
<LhFloatingPanel
:anchors="anchors"
:model-value.sync="anchorIndex"
:content-draggable="contentDraggable"
:safe-area-inset-bottom="safeArea"
:disabled="disabled"
label="Filter panel"
@change="onChange"
@height-change="onHeightChange"
>
<div style="padding: 12px; display: flex; flex-direction: column; gap: 12px">
<p class="demo-note" style="margin: 0">Drag the header handle or the content area to change the panel height; on release it snaps to the nearest anchor.</p>
<p class="demo-note" style="margin: 0">The header slot lets you customize the handle; when contentDraggable=false only the header is draggable.</p>
</div>
</LhFloatingPanel>
</div>
</template>
<script>
export default {
data: () => ({
anchors: [60, '40%', '80%'],
anchorIndex: 1,
contentDraggable: true,
safeArea: true,
disabled: false,
height: 0,
}),
methods: {
onChange(index) {
this.anchorIndex = index
},
onHeightChange(height) {
this.height = Math.round(height)
},
},
}
</script>
# Anchors and snapping
anchors is an array of heights: a number = px, a string like '40%' = a percentage of the viewport height; internally they are normalized to ascending px (normalizeAnchors). While dragging the header handle, the height follows the pointer via computeDragHeight (the height transition is disabled while --dragging); on release, resolveSnapIndex snaps to the nearest anchor and emits change / update:modelValue:
<LhFloatingPanel :anchors="[60, '40%', '80%']" @change="onChange" />
# Controlled step
modelValue is the index of the currently snapped anchor step (0-based, in ascending anchor order); the controlled value wins — an external update overrides the internal step, and a drag commit only emits the event (the .sync write-back decision):
<LhFloatingPanel :anchors="[60, '40%']" :model-value.sync="index" />
# Drag area and safe area
contentDraggable (default true) enables dragging on the content area; when false, only the header handle is draggable. safeAreaInsetBottom (default true) adds bottom safe-area padding (the --safe-area modifier); disabled disables dragging (the --disabled modifier). The header slot renders the __handle bar by default and can be customized.
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| anchors | Snap height array (numbers in px or 'percentage' strings) | (number \| string)[] | [60, '40%'] |
| modelValue | Index of the current snapped step (controlled; defaults to the highest step when not passed) | number | — |
| contentDraggable | Content area is draggable (when false, only the header) | boolean | true |
| safeAreaInsetBottom | Bottom safe-area padding | boolean | true |
| disabled | Disable dragging | boolean | false |
| label | Accessibility name (falls back to the default "Floating panel step i/N") | string | — |
# Events
| Event | Description | Callback args |
|---|---|---|
| update:modelValue | Step change (controlled .sync) | anchorIndex: number |
| change | Snapped step change | anchorIndex: number |
| heightChange | Panel height change (drag follow / snap landing) | height: number |
# Slots
| Slot | Description |
|---|---|
| header | Header handle area (renders the lh-floating-panel__handle indicator bar by default) |
| default | Panel content |
# Accessibility
The root element has role="region" + aria-label (generated by getFloatingPanelAria as "Floating panel step i/N"; label can override it).
← Descriptions Input →
Copyright © 2024-2026 FengMo WenXue