Skip to main content

FloatingPanel

Fixed bottom panel with snap anchors. Anchors are numbers (px) or percentage strings ('40%') resolved against the viewport height via normalizeAnchors (sorted ascending and deduplicated). The header (or the whole content area when contentDraggable) follows the pointer during the drag via computeDragHeight (with the --dragging modifier disabling the height transition), and on release the panel snaps to the nearest anchor via resolveSnapIndex. All anchor geometry, clamping and snapping is consumed from @lh-ui/share/core/floating-panel pure functions, so the semantics are identical across platforms.

  • Default anchors are [60, '40%']; the default snap index is 0 (the lowest anchor).
  • modelValue controls the snap index. When it is not provided the component keeps its own state; onIndexChange fires only when the index actually changes, while onHeightChange reports every height (drag follow values plus the final snapped value).
  • Percent anchors re-resolve on viewport resize, so the panel tracks rotation / resize.
  • safeAreaInsetBottom pads the bottom safe-area inset (default on).

Basic usage​

FloatingPanel (default anchors / controlled index / drag to snap)
当前档位下标:0

按住头部把手或内容区上下拖拽,松手吸附到最近锚点档。

条目 1

条目 2

条目 3

条目 4

条目 5

条目 6

条目 7

条目 8

条目 9

条目 10

条目 11

条目 12

条目 13

条目 14

条目 15

条目 16

条目 17

条目 18

条目 19

条目 20

条目 21

条目 22

条目 23

条目 24

import { useState } from 'react'
import { LhFloatingPanel } from '@lh-ui/react'

export default function Demo() {
const [index, setIndex] = useState(0)
return (
<LhFloatingPanel
anchors={[60, '40%']}
modelValue={index}
onIndexChange={setIndex}
>
<div style={{ padding: '4px 16px 12px' }}>面板内容</div>
</LhFloatingPanel>
)
}

Anchors and control​

Anchors accept px numbers and percent strings mixed together; the final height of an index comes from the resolved ascending px list, so anchors={[300, 100]} means index 0 is 100px:

<LhFloatingPanel anchors={[100, 200, 400]} contentDraggable={false} />

Use renderHeader to replace the default handle bar (aligning with the header slot of the other platforms):

<LhFloatingPanel renderHeader={() => <strong>拖我</strong>} />

FloatingPanel API​

PropDescriptionTypeDefault
anchorsSnap heights (px numbers or percent strings)(number | string)[][60, '40%']
modelValueCurrent snap index (controlled; internal state starts at 0)number0
contentDraggableMake the content area draggable toobooleantrue
safeAreaInsetBottomBottom safe-area padding (adds --safe-area)booleantrue
disabledDisable dragging (adds --disabled, blocks pointers)booleanfalse
onIndexChangeFired when the snap index actually changes(index: number) => void—
onHeightChangeFired on every height change (drag follow + snap final)(height: number) => void—
renderHeaderCustom header content (header slot)() => ReactNodehandle bar
labelAccessible name (aria-label)string悬浮面板 第 i / N 档
childrenPanel content (default slot)ReactNode—
sxQuick layout propsLhSxProps—

Accessibility​

  • The root carries role="region" with aria-label (the label prop or the 悬浮面板 第 i / N 档 fallback), so screen readers announce the current snap step.
  • The disabled state is conveyed by the lh-floating-panel--disabled modifier (pointer blocking plus reduced opacity); the drag-in-progress state is conveyed by lh-floating-panel--dragging.
  • The panel is pointer-driven; the header is a plain drag handle (not a button), so pair it with external controls if keyboard step switching is required.