Docs Components Primitives

ButtonGroup

React example follows below.
ts
import { ButtonGroup, Button } from "@grassroot/ui-react";
const buttonGroupFixture = {
id: "button-group",
role: "group",
buttons: [
{ id: "day", label: "Day", variant: "ghost" },
{ id: "week", label: "Week", variant: "ghost" },
{ id: "month", label: "Month", variant: "ghost" },
],
} satisfies {
id: string;
role: "group";
buttons: Array<{ id: string; label: string; variant: "ghost" }>;
};
export default function ButtonGroupDemo() {
return (
<div>
<ButtonGroup role={buttonGroupFixture.role}>
{buttonGroupFixture.buttons.map((button) => (
<Button key={button.id} variant={button.variant}>
{button.label}
</Button>
))}
</ButtonGroup>
</div>
);
}
ts
<script setup lang="ts">
import { ButtonGroup, Button } from "@grassroot/ui-vue";
const buttonGroupFixture = {
id: "button-group",
role: "group",
buttons: [
{ id: "day", label: "Day", variant: "ghost" },
{ id: "week", label: "Week", variant: "ghost" },
{ id: "month", label: "Month", variant: "ghost" },
],
} satisfies {
id: string;
role: "group";
buttons: Array<{ id: string; label: string; variant: "ghost" }>;
};
</script>
<template>
<ButtonGroup :role="buttonGroupFixture.role">
<Button
v-for="button in buttonGroupFixture.buttons"
:key="button.id"
:variant="button.variant"
>{{ button.label }}</Button
>
</ButtonGroup>
</template>
ts
import { Component } from "@angular/core";
import { GrassrootButtonGroup, GrassrootButton } from "@grassroot/ui-angular";
const buttonGroupFixture = {
id: "button-group",
role: "group",
buttons: [
{ id: "day", label: "Day", variant: "ghost" },
{ id: "week", label: "Week", variant: "ghost" },
{ id: "month", label: "Month", variant: "ghost" },
],
} satisfies {
id: string;
role: "group";
buttons: Array<{ id: string; label: string; variant: "ghost" }>;
};
@Component({
selector: "app-button-group-demo",
standalone: true,
imports: [GrassrootButtonGroup, GrassrootButton],
template: `
<grassroot-button-group [role]="fixture.role">
@for (button of fixture.buttons; track button.id) {
<grassroot-button [variant]="button.variant">{{ button.label }}</grassroot-button>
}
</grassroot-button-group>
`,
})
export class ButtonGroupDemoComponent {
protected readonly fixture = buttonGroupFixture;
}
export default ButtonGroupDemoComponent;
ts
<script lang="ts">
import { ButtonGroup, Button } from "@grassroot/ui-svelte";
const buttonGroupFixture = {
id: "button-group",
role: "group",
buttons: [
{ id: "day", label: "Day", variant: "ghost" },
{ id: "week", label: "Week", variant: "ghost" },
{ id: "month", label: "Month", variant: "ghost" },
],
} satisfies {
id: string;
role: "group";
buttons: Array<{ id: string; label: string; variant: "ghost" }>;
};
</script>
<ButtonGroup role={buttonGroupFixture.role}>
{#each buttonGroupFixture.buttons as button (button.id)}
<Button variant={button.variant}>{button.label}</Button>
{/each}
</ButtonGroup>
ts
/** @jsxImportSource solid-js */
import { ButtonGroup, Button } from "@grassroot/ui-solid";
const buttonGroupFixture = {
id: "button-group",
role: "group",
buttons: [
{ id: "day", label: "Day", variant: "ghost" },
{ id: "week", label: "Week", variant: "ghost" },
{ id: "month", label: "Month", variant: "ghost" },
],
} satisfies {
id: string;
role: "group";
buttons: Array<{ id: string; label: string; variant: "ghost" }>;
};
export default function ButtonGroupDemo() {
return (
<>
<ButtonGroup role={buttonGroupFixture.role}>
{buttonGroupFixture.buttons.map((button) => (
<Button variant={button.variant}>{button.label}</Button>
))}
</ButtonGroup>
</>
);
}

Installation

API Reference

Import

import { ButtonGroup, Button } from "@grassroot/ui-react";

Props

Prop
Type
Default
Requirement
Description
role
string | undefined
"group"
optional
ARIA grouping role.
Prop
role
Type
string | undefined
Default
"group"
Requirement
optional
Description
ARIA grouping role.

Content regions

  • children

Native attributes

Standard DOM and ARIA attributes not listed above spread onto the root element.

Import

import { ButtonGroup, Button } from "@grassroot/ui-vue";

Props

Prop
Type
Default
Requirement
role
string | undefined
"group"
optional
Prop
role
Type
string | undefined
Default
"group"
Requirement
optional

Content regions

  • default

Import

import { Component } from "@angular/core";
import { GrassrootButtonGroup, GrassrootButton } from "@grassroot/ui-angular";

Props

Prop
Type
Default
Requirement
role
string
"group"
optional
Prop
role
Type
string
Default
"group"
Requirement
optional

Content regions

  • default

Import

import { ButtonGroup, Button } from "@grassroot/ui-svelte";

Props

Prop
Type
Default
Requirement
role
string
"group"
optional
Prop
role
Type
string
Default
"group"
Requirement
optional

Content regions

  • children

Import

import { ButtonGroup, Button } from "@grassroot/ui-solid";

Props

Prop
Type
Default
Requirement
role
string
"group"
optional
className
string
optional
Prop
role
Type
string
Default
"group"
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional

Content regions

  • children