Floating Button
ProNewOne 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
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| label | stringThe text on the button. Leave it out for an icon-only button and pass `aria-label`. | — |
| sublabel | stringA second, quieter line under the label: a handle, opening hours. | — |
| icon | React.ReactNode | — |
| iconSide | "start" | "end"Which side of the label the icon sits on. | "start" |
| href | stringMakes the button a link. Ignored when `actions` are given. | — |
| external | booleanOpens `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" |
| color | stringThe fill, or the border and text of an `outline` button. | "var(--primary)" |
| textColor | stringColor of the label on a `filled` button. | "var(--primary-foreground)" |
| hoverColor | stringHover fill and text colors, independent of the resting colors. | — |
| hoverTextColor | string | — |
| outlineBackground | stringOptional styling of the Button family's embedded appearance. | — |
| borderColor | string | — |
| borderWidth | number | — |
| cornerRadius | number | — |
| width | number | string | — |
| minHeight | number | — |
| horizontalPadding | number | — |
| verticalPadding | number | — |
| labelFontSize | number | — |
| labelWeight | 400 | 700 | — |
| sublabelFontSize | number | — |
| lineHeight | number | — |
| shadow | boolean | — |
| supportingText | stringEmbedded text can sit above or below the control. | — |
| captionColor | string | — |
| supportingTextColor | string | — |
| align | "left" | "center" | "right" | "center" |
| attached | booleanSits flush against the edge of the screen, with only its outer corners rounded. Tabs always do. | false |
| pulse | booleanSends a soft ring out from the button every two seconds to draw the eye. | false |
| caption | stringA line of text above an `inline` button. | — |
| actions | FloatingButtonAction[]Turns the button into a menu: these fan out when it is pressed. | — |
| disabled | boolean | false |
| contained | booleanPositions it inside the nearest `relative` parent instead of the window. | false |
| offset | numberDistance from the edges in pixels. | 16 |
| offsetX | number | — |
| offsetY | number | — |
| "aria-label" | string | — |
| className | string | — |
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.