Overview
Get Started
Button Group
A group of buttons that can be rendered together with shared styling and behavior.
Installation
import { cva, type VariantProps } from "class-variance-authority";
import { mergeProps, useRender } from "@base-ui/react";
import { cn } from "@/lib/cn";
const buttonGroupVariants = cva(
"inline-flex items-stretch *:focus-visible:relative *:focus-visible:z-10 has-[>[data-slot=button-group]]:gap-2 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",
{
variants: {
orientation: {
horizontal:
"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",
vertical:
"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none",
},
},
defaultVariants: {
orientation: "horizontal",
},
}
);
function ButtonGroup({
className,
orientation,
render,
...props
}: useRender.ComponentProps<"div"> & VariantProps<typeof buttonGroupVariants>) {
const defaultProps = {
className: cn(buttonGroupVariants({ orientation }), className),
"data-slot": "button-group",
};
return useRender({
defaultTagName: "div",
render,
props: mergeProps<"div">(defaultProps, props),
});
}
export { ButtonGroup, buttonGroupVariants };