Command palette

@yasinsensoy/web

Web · Components

Fab

Floating action button (FAB) and speed dial.

9 exports

Live example

Preview

  • Record 1Last edited: today
  • Record 2Last edited: today
  • Record 3Last edited: today
  • Record 4Last edited: today
  • Record 5Last edited: today
  • Record 6Last edited: today
  • Record 7Last edited: today
  • Record 8Last edited: today
  • Record 9Last edited: today
  • Record 10Last edited: today
  • Record 11Last edited: today
  • Record 12Last edited: today
  • Record 13Last edited: today
  • Record 14Last edited: today
  • Record 15Last edited: today
  • Record 16Last edited: today
  • Record 17Last edited: today
  • Record 18Last edited: today
  • Record 19Last edited: today
  • Record 20Last edited: today
  • Record 21Last edited: today
  • Record 22Last edited: today
  • Record 23Last edited: today
  • Record 24Last edited: today
  • Record 25Last edited: today
  • Record 26Last edited: today
  • Record 27Last edited: today
  • Record 28Last edited: today
  • Record 29Last edited: today
  • Record 30Last edited: today

Code

import { Fab } from "@yasinsensoy/web";

<div className="relative h-96 overflow-y-auto">
  {/* content */}
  <Fab label="New"
    actions={[
      { label: "Edit", icon: "pencil", onSelect: () => {} },
      { label: "Share", icon: "share", onSelect: () => {} },
      { label: "Copy", icon: "copy", onSelect: () => {} },
      { label: "Download", icon: "download", onSelect: () => {} },
    ]}
  />
</div>

Events

  1. Events appear here when you interact with the preview.

By area: stays in place in a scrolled list, shrinks when scrolling down

  • Record 1Last edited: today
  • Record 2Last edited: today
  • Record 3Last edited: today
  • Record 4Last edited: today
  • Record 5Last edited: today
  • Record 6Last edited: today
  • Record 7Last edited: today
  • Record 8Last edited: today
  • Record 9Last edited: today
  • Record 10Last edited: today
  • Record 11Last edited: today
  • Record 12Last edited: today
  • Record 13Last edited: today
  • Record 14Last edited: today
  • Record 15Last edited: today
  • Record 16Last edited: today
  • Record 17Last edited: today
  • Record 18Last edited: today
  • Record 19Last edited: today
  • Record 20Last edited: today
  • Record 21Last edited: today
  • Record 22Last edited: today
  • Record 23Last edited: today
  • Record 24Last edited: today
  • Record 25Last edited: today

Narrow card: opens sideways if there's no room above, labels move to tooltips

Short card
Top left; no room below

Centered, with backdrop, surface appearance

The center button dims the area while open; tapping outside closes it.

Import

import { Fab } from "@yasinsensoy/web";

Fab

componentClient component

Floating action button (FAB) and speed dial. Sits in the corner of the screen or of the area you put it in; with actions, small action buttons open one after another with a spring on press.

  • Area-relative position: With the default scope="container", it sits in the corner of whatever element you put the Fab in (a static element is made relative automatically). If the element scrolls, the button doesn't scroll with the content; in supporting browsers it follows scrolling off the main thread, without jitter. For the screen corner, use scope="viewport".
  • Smart direction: direction="auto" picks the direction where the actions fit; in the corner of a small card with no room above, it opens sideways.
  • Keyboard: The arrow key in the opening direction opens the menu and moves to the first action; arrows move between actions, Esc closes and returns focus to the main button. The menu closes when focus leaves it.
  • Mobile: Action names appear as thumb-readable labels, tapping outside and the back button close the menu, touch targets are at least 44 px, and with scrollBehavior it hides or shrinks while scrolling.
  • Animations are disabled with the "reduced motion" preference.
Fab({ label, icon, openIcon, extended, actions, onClick, href, position, direction, scope, offset, variant: variantProp, effect, tone, size, actionLabels, scrim, scrollBehavior, tooltip, open: openProp, defaultOpen, onOpenChange, disabled, className, }: FabProps): JSX.Element

Examples

// In the bottom right corner of a card, with a speed dial:
<Card className="h-96">
  …
  <Fab
    label="New"
    actions={[
      { label: "Document", icon: "document", onSelect: newDocument },
      { label: "Folder", icon: "folder", onSelect: newFolder },
      { label: "Upload", icon: "upload", href: "/upload" },
    ]}
  />
</Card>

// In the screen corner, extended, a single action that shrinks on scroll:
<Fab scope="viewport" extended label="New message" icon="pencil" scrollBehavior="shrink" onClick={compose} />

Corner or edge midpoint of the area the Fab is in.

type FabPosition = "bottom-right" | "bottom-left" | "bottom-center" | "top-right" | "top-left" | "top-center"

Direction the actions open in. "auto" tries vertical first (a bottom button opens up, a top one down); if there is not enough room it goes sideways (left in the right corner, right in the left corner). The direction is re-chosen on each open and whenever the area size changes.

type FabDirection = "auto" | "up" | "down" | "left" | "right"

What the button is positioned relative to.

  • "container": The corner of the element you put the Fab in (its parent). If the element scrolls, the button does not scroll with the content and stays in the corner of the visible area.
  • "viewport": The corner of the screen (position: fixed); notch and home indicator insets (safe area) are added automatically.
type FabScope = "container" | "viewport"

How action names are shown.

  • "visible": A name label appears next to each small button (clearest on mobile).
  • "tooltip": The name appears only as a tooltip.
  • "auto": Label when opening vertically, tooltip when opening sideways.
type FabActionLabels = "auto" | "visible" | "tooltip"

Behavior of the button when the page scrolls.

  • "none": Stays in place.
  • "hide": Shrinks away while scrolling down, comes back when scrolling up; it doesn't cover content.
  • "shrink": An extended button shrinks to just the icon while scrolling down; its text comes back when scrolling up.
type FabScrollBehavior = "none" | "hide" | "shrink"

Appearance of the button: solid is the theme's filled color, surface a colored icon on a light surface (calmer).

type FabVariant = "solid" | "surface"

FabAction

interface

One of the small action buttons that appear when the Fab opens.

NameTypeDefaultDescription
labelstringName of the action; shown in the label or tooltip, read by screen readers.
iconIconPropIcon on the small button: a name ("pencil") or an element.
tone?Tone"neutral"Color of the icon.
disabled?booleanCannot be selected.
tooltip?TooltipPropExtra hint. When actionLabels="tooltip" and this is omitted, label is shown. See TooltipProp.
onSelect?(event: MouseEvent<HTMLElement>) => voidCalled when selected (click, Enter, Space); then the menu closes. Call event.preventDefault() to keep it open.
href?stringIf given, the action becomes a link; rendered with the link component given to UIProvider (e.g. Next.js Link).

FabProps

interface

Props of the Fab component.

NameTypeDefaultDescription
labelstringName of the button. Read by screen readers; with extended it is written on the button, otherwise it appears as a tooltip.
icon?IconPropPlus (+)Icon of the button.
openIcon?IconPropIcon that replaces the icon while the menu is open. The default plus icon rotates into a cross (×) when opened; if you gave your own icon, it swaps with the cross.
extended?booleanThe button also writes label next to the icon (extended, pill-shaped FAB).
actions?readonly FabAction[]Small action buttons that open with an animation on press (speed dial). The first action is the one closest to the main button. If omitted, the button is a single action (onClick or href).
onClick?(event: MouseEvent<HTMLElement>) => voidCalled on click when there are no actions.
href?stringIf given when there are no actions, the button becomes a link.
position?FabPosition"bottom-right"Position in the area. See FabPosition.
direction?FabDirection"auto"Direction the actions open in. See FabDirection.
scope?FabScope"container"What it is positioned relative to. See FabScope.
offset?number | string16Distance from the edges: pixels or a CSS length ("1.5rem"). If there is a navigation bar at the bottom, increase it by its height.
variant?FabVariant | CustomVariant<"fab">"solid"Appearance: built-in or a custom style added with defineAppearance. If omitted, UIProvider appearance.defaults.fab.variant. See FabVariant.
effect?EffectPropEffect or effects of the main button (e.g. "ripple", ["pulse", "glow"]). If omitted, UIProvider appearance.defaults.fab.effect, or shrink on press (scale) if that is missing too. See BuiltinEffect.
tone?Tone"primary"Color. See Tone.
size?Size"md"Size: sm 40 px, md 56 px, lg 64 px.
actionLabels?FabActionLabels"auto"How action names are shown. See FabActionLabels.
scrim?booleanfalseDraws a semi-transparent scrim over the area while the menu is open.
scrollBehavior?FabScrollBehavior"none"Behavior on scroll. See FabScrollBehavior.
tooltip?TooltipPropTooltip. If omitted, label is shown on a button without text; disable with false. See TooltipProp.
open?booleanWhether the menu is open when controlled.
defaultOpen?booleanfalseIs it initially open when uncontrolled?
onOpenChange?(open: boolean) => voidCalled with the new state when the menu opens or closes.
disabled?booleanDisabled.
className?stringClasses added to the main button.