Components
Floating Action Button
A fixed circular action for the primary task on a screen.
Installation
$ npx veil-ui@latest add fabUsage
import { Fab } from "@/components/ui/fab";
import { Plus } from "lucide-react";
<Fab aria-label="Create item">
<Plus />
</Fab>;Examples
Basic
Floating above the page
Extended
Floating above the page
Positions
Floating above the page
Pass a className with absolute inside a positioned container to keep the
button scoped to a panel instead of the viewport.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| position | "bottom-right" | "bottom-left" | "bottom-center" | "bottom-right" | Corner of the viewport where the button floats. |
| size | "default" | "lg" | "default" | Icon-only diameter: 48px or 56px. |
| label | React.ReactNode | — | Visible label; turns the button into an extended FAB. |
| ...props | React.ComponentProps<"button"> | — | All native button attributes, including aria-label. |
Accessibility
- Icon-only FABs need an
aria-label; extended FABs use their visible label. - Defaults to
type="button"so it never submits a surrounding form by accident. - Only one FAB should be visible at a time; it marks the single primary action.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add fab --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed } from "vue";
import { cn } from "@/lib/utils";
const positions = {
"bottom-right": "bottom-6 right-6",
"bottom-left": "bottom-6 left-6",
"bottom-center": "bottom-6 left-1/2 -translate-x-1/2",
} as const;
const sizes = {
default: "size-12",
lg: "size-14",
} as const;
const props = withDefaults(
defineProps<{
/** Corner of the viewport where the button floats. */
position?: keyof typeof positions;
/** Icon-only size. Ignored when a label is provided. */
size?: keyof typeof sizes;
/** Optional visible label, turning the button into an extended FAB. */
label?: string;
type?: "button" | "submit" | "reset";
class?: string;
}>(),
{ position: "bottom-right", size: "default", type: "button" },
);
const classes = computed(() =>
cn(
"fixed z-50 inline-flex items-center justify-center gap-2 rounded-full bg-primary text-primary-foreground shadow-lg outline-none transition-[color,background-color,box-shadow] hover:bg-primary/90 focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-5 [&_svg]:shrink-0",
positions[props.position],
props.label ? "h-12 px-5 text-sm font-medium" : sizes[props.size],
props.class,
),
);
</script>
<template>
<button
data-slot="fab"
:data-position="position"
:type="type"
:class="classes"
>
<slot />
<span v-if="label">{{ label }}</span>
</button>
</template>