Float Button
A floating action button for the main action of a screen, which can expand into a speed dial of related actions.
c2-float-button
A raised button pinned to a corner of the viewport for the screen's main action ("Compose", "New task"). Give it
c2-float-button-action children and it becomes a speed dial: the button opens a short menu of related actions
that fan out in direction, its plus turning into a cross.
Without actions it is a plain button and fires the native click. With actions the button follows the menu-button
pattern: Enter, Space or an arrow key opens the dial and focuses the first action, the arrow keys move between
actions, Escape closes it and returns focus, and Tab or a click outside closes it.
The button is position: fixed 24px from the bottom-right corner by default; set --c2-float-button--position
and --c2-float-button--inset to place it elsewhere or in the flow. Show its label next to the icon (an
"extended" button) with --c2-float-button__label--display: inline.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | Accessible name of the button and its speed dial, also the visible text of an extended button. Defaults to "Actions". |
open | boolean | false | Whether the speed dial is expanded. Has no effect without actions. |
direction | FloatButtonDirection | up | Where the actions fan out from the button. |
trigger | FloatButtonTrigger | click | hover also opens the dial while a mouse pointer is over it; a click or the keyboard still toggle it. |
disabled | boolean | false | Disables the button and closes the dial. |
Slots
| Name | Description |
|---|---|
(default) | The speed dial's c2-float-button-action elements, nearest the button first. |
icon | The button's icon. Defaults to a plus that turns into a cross while the dial is open. |
open-icon | Replaces the icon while the dial is open. |
Events
| Name | Type | Description |
|---|---|---|
action-select | CustomEvent<FloatButtonSelectEventDetail> | An action was activated by a click, Enter or Space: detail.value and detail.action. Cancelable: preventDefault() keeps the dial open. |
toggle | ToggleEvent | The speed dial opened or closed; newState is open or closed. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
button | The native button. |
label | The visible label of an extended button. |
actions | The speed dial's menu container. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-float-button--position | position | fixed | absolute to pin the button inside a positioned container, static to keep it in the flow. |
--c2-float-button--inset | inset | auto 24px 24px auto | Distance from the edges of the viewport (or container); top right bottom left. |
--c2-float-button--z-index | number | 100 | |
--c2-float-button__button--size | pixel | 56px | Height, and minimum width, of the button. |
--c2-float-button__button--padding-inline | padding | 16px | Side padding; with the 24px icon it makes a 56px circle. |
--c2-float-button__button--gap | pixel | 8px | Space between the icon and the visible label. |
--c2-float-button__button--border-radius | border-radius | 999px | |
--c2-float-button__button--border | border | none | |
--c2-float-button__button--background-color | color | rgb(2, 101, 220) | |
--c2-float-button__button--color | color | #ffffff | Icon and label colour. |
--c2-float-button__button--box-shadow | shadow | 0 6px 16px rgba(24, 24, 27, 0.2), 0 2px 4px rgba(24, 24, 27, 0.12) | |
--c2-float-button__button__hover--background-color | color | #0154b8 | |
--c2-float-button__button__hover--box-shadow | shadow | 0 10px 24px rgba(24, 24, 27, 0.24), 0 3px 6px rgba(24, 24, 27, 0.14) | |
--c2-float-button__button__open--background-color | color | #0154b8 | |
--c2-float-button__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-float-button__focus--outline-offset | pixel | 3px | |
--c2-float-button__disabled--opacity | opacity | 0.38 | |
--c2-float-button__icon--size | pixel | 24px | |
--c2-float-button__icon__open--transform | transform | rotate(45deg) | The icon's turn while open; none to keep it still. |
--c2-float-button__label--display | display | none | inline shows label next to the icon (an extended button). |
--c2-float-button__label--font-size | font-size | 14px | |
--c2-float-button__label--font-weight | font-weight | 600 | |
--c2-float-button__actions--gap | pixel | 12px | Space between actions. |
--c2-float-button__actions--offset | pixel | 16px | Space between the button and the nearest action. |
--c2-float-button__actions--transition-duration | time | 200ms | |
--c2-float-button__actions--stagger | time | 30ms | Delay added per action as the dial opens. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under float-button, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
actions | Actions | — |
c2-float-button-action
One action of a c2-float-button speed dial: a small round button with a label chip beside it. The host is the
menu item (role="menuitem" through ElementInternals); the owning c2-float-button assigns the roving
tabindex, places the chip on the side that suits its direction and fires action-select when it is activated.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | Accessible name of the action, also shown in the label chip. |
value | string | — | Reported as detail.value of the owner's action-select event. |
disabled | boolean | false | A disabled action is skipped by the arrow keys and never fires action-select. |
Slots
| Name | Description |
|---|---|
(default) | The icon (an inline <svg>, a c2-feather-* or a c2-mat-icon element). |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
button | The round button. |
label | The label chip beside the button. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-float-button-action__button--size | pixel | 40px | Diameter of the button. |
--c2-float-button-action__button--border-radius | border-radius | 999px | |
--c2-float-button-action__button--background-color | color | #ffffff | |
--c2-float-button-action__button--color | color | #18181b | Icon colour. |
--c2-float-button-action__button--border | border | 1px solid #e4e4e7 | |
--c2-float-button-action__button--box-shadow | shadow | 0 2px 6px rgba(24, 24, 27, 0.16) | |
--c2-float-button-action__button__hover--background-color | color | #f4f4f5 | |
--c2-float-button-action__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-float-button-action__focus--outline-offset | pixel | 2px | |
--c2-float-button-action__disabled--opacity | opacity | 0.38 | |
--c2-float-button-action__icon--size | pixel | 20px | |
--c2-float-button-action__label--display | display | block | none for icon-only actions. |
--c2-float-button-action__label--background-color | color | #ffffff | |
--c2-float-button-action__label--color | color | #18181b | |
--c2-float-button-action__label--border | border | 1px solid #e4e4e7 | |
--c2-float-button-action__label--font-size | font-size | 12px | |
--c2-float-button-action__label--font-weight | font-weight | 500 | |
--c2-float-button-action__label--padding | padding | 4px 10px | |
--c2-float-button-action__label--border-radius | border-radius | 6px | |
--c2-float-button-action__label--box-shadow | shadow | 0 2px 6px rgba(24, 24, 27, 0.12) | |
--c2-float-button-action__label--inset | inset | — | Where the chip sits around the button. Defaults to the inline start for a vertical dial and above it for a horizontal one; set 50% auto auto calc(100% + 12px) to put it on the right. |
--c2-float-button-action__label--transform | transform | — | Centres the chip on the button's axis; pair it with --c2-float-button-action__label--inset (translateY(-50%) beside, translateX(-50%) above). |