Fab
HkFab is the floating action button: a round, anchored trigger for the single primary action of a surface, with an optional speed dial of labelled mini-actions that fan out from it. It is positioned by CSS alone — positioning and corner pick the corner of the nearest positioned ancestor (or of the viewport), and offsetX / offsetY fine-tune the insets.
- A page's ordinary actions belong in its toolbar or footer as Buttons; the fab is reserved for the one action that is available from anywhere on the surface.
- An icon-only action inside a row is an HkIconButton, which is not anchored and has no dial.
Import
import { HkFab, type HFabAction } from "@celestia-island/hikari";
use hikari_components::*; use hikari_components::prelude::*;
Sizes and variants
Three sizes — sm, md (the default), lg — and two inks: glass, the default translucent surface, and primary, filled with the primary colour. Each stage below is a positioned box, so the fab anchors to the stage rather than to the page.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { HkFab } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "12px" };
const stage: CSSProperties = {
position: "relative",
height: "180px",
flex: "1 1 0",
minWidth: "140px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={row}>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" size="sm" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" size="lg" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" variant="primary" />
</div>
</div>
);
rsx! {
div { style: "display:flex;gap:12px",
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), size: FabSize::Sm }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string() }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), size: FabSize::Lg }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), variant: FabVariant::Primary }
}
}
}
import { HkFab } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const row: CSSProperties = { display: "flex", gap: "12px" };
const stage: CSSProperties = {
position: "relative",
height: "180px",
flex: "1 1 0",
minWidth: "140px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={row}>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" size="sm" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" size="lg" />
</div>
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" variant="primary" />
</div>
</div>
);rsx! {
div { style: "display:flex;gap:12px",
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), size: FabSize::Sm }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string() }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), size: FabSize::Lg }
}
div { style: "position:relative;height:180px;flex:1 1 0;min-width:140px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), variant: FabVariant::Primary }
}
}
}Corners and offsets
corner is one of bottom-right (the default), bottom-left, top-right, top-left; offsetX and offsetY are CSS lengths added to the corner's inset. With positioning="fixed" the anchor is the viewport instead of the ancestor — the usual choice for an app-wide fab, not shown here because it would leave the stage.
import { HkFab } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const stage: CSSProperties = {
position: "relative",
height: "220px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" corner="bottom-left" />
<HkFab icon="Pencil" aria-label="Compose" corner="top-right" offsetX="24px" offsetY="24px" />
</div>
);
rsx! {
div { style: "position:relative;height:220px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), corner: FabCorner::BottomLeft }
Fab {
icon: Some(MdiIcon::Pencil),
aria_label: "Compose".to_string(),
corner: FabCorner::TopRight,
offset_x: Some("24px".to_string()),
offset_y: Some("24px".to_string()),
}
}
}
import { HkFab } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const stage: CSSProperties = {
position: "relative",
height: "220px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={stage}>
<HkFab icon="Plus" aria-label="Add" corner="bottom-left" />
<HkFab icon="Pencil" aria-label="Compose" corner="top-right" offsetX="24px" offsetY="24px" />
</div>
);rsx! {
div { style: "position:relative;height:220px;border:1px dashed #a1a1aa;border-radius:8px",
Fab { icon: Some(MdiIcon::Plus), aria_label: "Add".to_string(), corner: FabCorner::BottomLeft }
Fab {
icon: Some(MdiIcon::Pencil),
aria_label: "Compose".to_string(),
corner: FabCorner::TopRight,
offset_x: Some("24px".to_string()),
offset_y: Some("24px".to_string()),
}
}
}Speed dial
With actions the main button toggles a dial: each action is a mini button with a glyph and a visible label, and expandDirection says which way they fan out (up by default). Pressing the main button emits click, then toggle with the requested open state; pressing an action runs its onClick and closes the dial. Escape and an outside pointer-down close it too. In the Vue example the dial opens when you press the button.
The Rust mirror keeps no state of its own: open is a prop the host flips from on_open_change, so the snapshot below shows the dial open.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { HkFab, type HFabAction } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const actions: HFabAction[] = [
{ key: "doc", label: "New document", icon: "FileText" },
{ key: "upload", label: "Upload", icon: "Upload" },
];
const stage: CSSProperties = {
position: "relative",
height: "220px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={stage}>
<HkFab icon="Plus" aria-label="Create" actions={actions} corner="bottom-right" expandDirection="up" />
</div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
rsx! {
div { style: "position:relative;height:220px;border:1px dashed #a1a1aa;border-radius:8px",
Fab {
icon: Some(MdiIcon::Plus),
aria_label: "Create".to_string(),
corner: FabCorner::BottomRight,
expand_direction: FabExpandDirection::Up,
open: true,
actions: Some(vec![
FabAction {
key: "doc".to_string(),
label: Some("New document".to_string()),
icon: Some(MdiIcon::FileEdit),
..Default::default()
},
FabAction {
key: "upload".to_string(),
label: Some("Upload".to_string()),
icon: Some(MdiIcon::Upload),
..Default::default()
},
]),
}
}
}
import { HkFab, type HFabAction } from "@celestia-island/hikari";
import type { CSSProperties } from "vue";
const actions: HFabAction[] = [
{ key: "doc", label: "New document", icon: "FileText" },
{ key: "upload", label: "Upload", icon: "Upload" },
];
const stage: CSSProperties = {
position: "relative",
height: "220px",
border: "1px dashed #a1a1aa",
borderRadius: "8px",
};
export default () => (
<div style={stage}>
<HkFab icon="Plus" aria-label="Create" actions={actions} corner="bottom-right" expandDirection="up" />
</div>
);rsx! {
div { style: "position:relative;height:220px;border:1px dashed #a1a1aa;border-radius:8px",
Fab {
icon: Some(MdiIcon::Plus),
aria_label: "Create".to_string(),
corner: FabCorner::BottomRight,
expand_direction: FabExpandDirection::Up,
open: true,
actions: Some(vec![
FabAction {
key: "doc".to_string(),
label: Some("New document".to_string()),
icon: Some(MdiIcon::FileEdit),
..Default::default()
},
FabAction {
key: "upload".to_string(),
label: Some("Upload".to_string()),
icon: Some(MdiIcon::Upload),
..Default::default()
},
]),
}
}
}
API
Vue
Props
Emits
Rust
Props — Fab
Notes
- layer="top" floats the fab above every window through the floating layer, so its dial stays reachable while a modal or a sheet is open; the layer then owns the corner and the offsets. The Rust form has no such layer and renders in tree.
- Always pass aria-label: the main button is icon-only. When the dial exists it also publishes aria-expanded.
- The mini-actions are keyboard-reachable only while the dial is open, and each one is named by its label (or its key when there is no label).
Related components
- Button — the actions that live in a toolbar or a footer.
- HkIconButton — an icon-only action inside a row.
- HkAddTile — a dashed in-content "add" affordance, for lists rather than pages.