Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Floating Button

ProNew

One call to action for anywhere: in the page, floating in a corner or as a tab on the edge; with configurable embedded text, colors, spacing and hover styles.

Installation

pnpm dlx shadcn@latest add @viewport/floating-button

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
labelstring

The text on the button. Leave it out for an icon-only button and pass `aria-label`.

—
sublabelstring

A second, quieter line under the label: a handle, opening hours.

—
iconReact.ReactNode—
iconSide"start" | "end"

Which side of the label the icon sits on.

"start"
hrefstring

Makes the button a link. Ignored when `actions` are given.

—
externalboolean

Opens `href` in a new tab.

false
onClick(event: React.MouseEvent<HTMLElement>) => void—
placement"inline" | "bottom-right" | "bottom-left" | "top-right" | "top-left" | "left" | "right"

`inline` sits in the page. A corner floats over it. `left` and `right` are tabs on the edge with the label turned on its side.

"inline"
shape"rounded" | "pill" | "square""rounded"
variant"filled" | "outline""filled"
size"sm" | "md" | "lg""md"
colorstring

The fill, or the border and text of an `outline` button.

"var(--primary)"
textColorstring

Color of the label on a `filled` button.

"var(--primary-foreground)"
hoverColorstring

Hover fill and text colors, independent of the resting colors.

—
hoverTextColorstring—
outlineBackgroundstring

Optional styling of the Button family's embedded appearance.

—
borderColorstring—
borderWidthnumber—
cornerRadiusnumber—
widthnumber | string—
minHeightnumber—
horizontalPaddingnumber—
verticalPaddingnumber—
labelFontSizenumber—
labelWeight400 | 700—
sublabelFontSizenumber—
lineHeightnumber—
shadowboolean—
supportingTextstring

Embedded text can sit above or below the control.

—
captionColorstring—
supportingTextColorstring—
align"left" | "center" | "right""center"
attachedboolean

Sits flush against the edge of the screen, with only its outer corners rounded. Tabs always do.

false
pulseboolean

Sends a soft ring out from the button every two seconds to draw the eye.

false
captionstring

A line of text above an `inline` button.

—
actionsFloatingButtonAction[]

Turns the button into a menu: these fan out when it is pressed.

—
disabledbooleanfalse
containedboolean

Positions it inside the nearest `relative` parent instead of the window.

false
offsetnumber

Distance from the edges in pixels.

16
offsetXnumber—
offsetYnumber—
"aria-label"string—
classNamestring—

Accessibility

  • A link when it has an `href`, a button otherwise; icon-only buttons take an `aria-label`.
  • With actions it is a menu button: Enter or Space opens it, arrow keys move, Escape closes and focus returns to the button.
  • A disabled link keeps its role and is announced as unavailable.
  • The pulse and the fan-out are switched off under reduced motion.