Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Navigation

  • TabBar
  • Fab

Overlays

  • ActionSheet

Input

  • Picker

Gestures

  • SwipeAction
  • PullToRefresh

Layout

  • SafeArea

Fab

fab

Places a prominent floating mobile action button above page content.

Usage

Basic usage

By default, fixed is attached to the lower right side of the viewport; without actions, the main button directly triggers onClick.

Floating button in the lower right corner.
tsx
<Fab icon={<Plus />} onClick={() => alert("New")} />

Extended Capsules

According to label, the rear main button changes from a circle to an "icon + text" adaptive width capsule.

Floating button in the lower right corner(extended capsule form).
tsx
<Fab label="Return to sample library" icon={<ExternalLink />} />

Speed-dial Sub-Action

If actions is provided, click the main button to expand/collapse a group of sub-actions, and the main button icon will rotate 45°.

Floating button in the lower right corner(Click to expand sub-action).
Search
Copy
Share
tsx
<Fab
  actions={[
    { key: "search", icon: <Search />, label: "Search" },
    { key: "copy", icon: <Copy />, label: "Copy" },
    { key: "link", icon: <ExternalLink />, label: "Share" },
  ]}
/>

Can be dragged

draggable is closed by default (press and hold if not open). After turning it on, press and hold the main button to drag to any position; the displacement exceeds 3px as dragging, and raising your hand this time will not trigger onClick.

Press and hold the floating button to drag it away (let go and stop in place).
tsx
<Fab draggable label="Hold and drag me" icon={<GripVertical />} onClick={() => alert("New")} />

When to Use

Use it when one primary page action, such as create, back to top, or share, needs a persistent floating entry point. A speed dial can reveal several related actions. Use TabBar for top-level app navigation, or ActionSheet for a dismissible list of actions that opens after a tap.

Import

ts
import { Fab } from "@hulianui/ui"

Props

NameTypeDefaultDescription
labelstring-Main button text (extended capsule state); provides the rear main button to change to "icon + text" adaptive capsule, and defaults to aria-label
actionsFabAction[]-speed-dial sub-action; if provided, click the main button to expand/collapse, otherwise directly trigger onClick
position"bottom-right" | "bottom-left" | "bottom-center""bottom-right"Welt position
size"sm" | "md""md"md=56px main button, sm=48px (compact scene)
draggablebooleanfalsePress and drag to reposition (displacement >3px is regarded as dragging, onClick will not be triggered this time)
aria-labelstring"\u64cd\u4f5c" ("Action")Main Button Accessibility Label
classNamestring--

FabAction: key: string · icon: ReactNode · label?: string (displayed on the side of the icon as aria-label when expanded) · onClick?: () => void.

Events

EventTypeDescription
onClick() => voidMain button click without actions

Slots

SlotTypeDescription
iconReactNodeMain button icon (default Plus); rotated 45° when speed-dial is expanded

Usage Guidelines

  • The root uses fixed positioning at a viewport corner. In a gallery or bounded container, override it to absolute through className, and give the container position: relative and overflow-hidden.
  • With actions, the main button expands or collapses the speed dial and does not call onClick. Without actions, it calls onClick directly.
  • draggable defaults to false; holding the button without enabling it intentionally causes no movement.
  • A drag farther than 3px suppresses the release click to prevent accidental activation.
  • The drag offset is written on the inline transform of the root node, and is only the internal state of the component: it is not persisted and is not controlled (no onDragEnd / controlled position input parameter). Refresh or remount will return to the edge specified by position.
  • Dragging is relative to the press point and is not clamped to viewport bounds. It can move off-screen; bounded demos should use overflow-hidden.
  • Draggable mode applies touch-action: none to the main button, so touch gestures on it drag the button instead of scrolling the page.

Related

TabBar · ActionSheet · Picker · SwipeAction · PullToRefresh · SafeArea

PreviousTabBarMobileNextActionSheet

On this page

  • Usage
  • Documentation
    • When to Use
    • Import
    • Props
    • Events
    • Slots
    • Usage Guidelines
    • Related