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 is0(the lowest anchor). modelValuecontrols the snap index. When it is not provided the component keeps its own state;onIndexChangefires only when the index actually changes, whileonHeightChangereports every height (drag follow values plus the final snapped value).- Percent anchors re-resolve on viewport resize, so the panel tracks rotation / resize.
safeAreaInsetBottompads the bottom safe-area inset (default on).
Basic usage
按住头部把手或内容区上下拖拽,松手吸附到最近锚点档。
条目 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
| Prop | Description | Type | Default |
|---|---|---|---|
| anchors | Snap heights (px numbers or percent strings) | (number | string)[] | [60, '40%'] |
| modelValue | Current snap index (controlled; internal state starts at 0) | number | 0 |
| contentDraggable | Make the content area draggable too | boolean | true |
| safeAreaInsetBottom | Bottom safe-area padding (adds --safe-area) | boolean | true |
| disabled | Disable dragging (adds --disabled, blocks pointers) | boolean | false |
| onIndexChange | Fired when the snap index actually changes | (index: number) => void | — |
| onHeightChange | Fired on every height change (drag follow + snap final) | (height: number) => void | — |
| renderHeader | Custom header content (header slot) | () => ReactNode | handle bar |
| label | Accessible name (aria-label) | string | 悬浮面板 第 i / N 档 |
| children | Panel content (default slot) | ReactNode | — |
| sx | Quick layout props | LhSxProps | — |
Accessibility
- The root carries
role="region"witharia-label(thelabelprop or the悬浮面板 第 i / N 档fallback), so screen readers announce the current snap step. - The disabled state is conveyed by the
lh-floating-panel--disabledmodifier (pointer blocking plus reduced opacity); the drag-in-progress state is conveyed bylh-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.