Docs Components Primitives

ToggleGroup

React example follows below.
ts
const toggleGroupFixture = {
id: "toggle-group",
single: {
defaultValue: "left",
options: [
{ value: "left", label: "Left" },
{ value: "center", label: "Center" },
{ value: "right", label: "Right", disabled: true },
],
},
multiple: {
defaultValue: ["bold"],
options: [
{ value: "bold", label: "Bold" },
{ value: "italic", label: "Italic" },
{ value: "underline", label: "Underline" },
],
},
} as const;
import { ToggleGroup } from "@grassroot/ui-react";
export default function ToggleGroupDemo() {
return (
<div>
<ToggleGroup
options={[...toggleGroupFixture.single.options]}
defaultValue={toggleGroupFixture.single.defaultValue}
/>
<ToggleGroup
type="multiple"
options={[...toggleGroupFixture.multiple.options]}
defaultValue={[...toggleGroupFixture.multiple.defaultValue]}
/>
</div>
);
}
ts
<script setup lang="ts">
import { ref } from "vue";
const toggleGroupFixture = {
id: "toggle-group",
single: {
defaultValue: "left",
options: [
{ value: "left", label: "Left" },
{ value: "center", label: "Center" },
{ value: "right", label: "Right", disabled: true },
],
},
multiple: {
defaultValue: ["bold"],
options: [
{ value: "bold", label: "Bold" },
{ value: "italic", label: "Italic" },
{ value: "underline", label: "Underline" },
],
},
} as const;
import { ToggleGroup } from "@grassroot/ui-vue";
const single = ref(toggleGroupFixture.single.defaultValue);
const multiple = ref([...toggleGroupFixture.multiple.defaultValue]);
</script>
<template>
<div>
<ToggleGroup v-model="single" :options="[...toggleGroupFixture.single.options]" /><ToggleGroup
v-model="multiple"
type="multiple"
:options="[...toggleGroupFixture.multiple.options]"
/>
</div>
</template>
ts
import { Component } from "@angular/core";
const toggleGroupFixture = {
id: "toggle-group",
single: {
defaultValue: "left",
options: [
{ value: "left", label: "Left" },
{ value: "center", label: "Center" },
{ value: "right", label: "Right", disabled: true },
],
},
multiple: {
defaultValue: ["bold"],
options: [
{ value: "bold", label: "Bold" },
{ value: "italic", label: "Italic" },
{ value: "underline", label: "Underline" },
],
},
} as const;
import { GrassrootToggleGroup } from "@grassroot/ui-angular";
@Component({
selector: "app-toggle-group-demo",
standalone: true,
imports: [GrassrootToggleGroup],
template: `<div>
<grassroot-toggle-group
[options]="fixture.single.options"
[defaultValue]="fixture.single.defaultValue"
/><grassroot-toggle-group
type="multiple"
[options]="fixture.multiple.options"
[defaultValue]="fixture.multiple.defaultValue"
/>
</div>`,
})
export class ToggleGroupDemoComponent {
protected readonly fixture = toggleGroupFixture;
}
export default ToggleGroupDemoComponent;
ts
<script lang="ts">
const toggleGroupFixture = {
id: "toggle-group",
single: {
defaultValue: "left",
options: [
{ value: "left", label: "Left" },
{ value: "center", label: "Center" },
{ value: "right", label: "Right", disabled: true },
],
},
multiple: {
defaultValue: ["bold"],
options: [
{ value: "bold", label: "Bold" },
{ value: "italic", label: "Italic" },
{ value: "underline", label: "Underline" },
],
},
} as const;
import { ToggleGroup } from "@grassroot/ui-svelte";
</script>
<div>
<ToggleGroup
options={[...toggleGroupFixture.single.options]}
defaultValue={toggleGroupFixture.single.defaultValue}
/><ToggleGroup
type="multiple"
options={[...toggleGroupFixture.multiple.options]}
defaultValue={[...toggleGroupFixture.multiple.defaultValue]}
/>
</div>
ts
/** @jsxImportSource solid-js */
const toggleGroupFixture = {
id: "toggle-group",
single: {
defaultValue: "left",
options: [
{ value: "left", label: "Left" },
{ value: "center", label: "Center" },
{ value: "right", label: "Right", disabled: true },
],
},
multiple: {
defaultValue: ["bold"],
options: [
{ value: "bold", label: "Bold" },
{ value: "italic", label: "Italic" },
{ value: "underline", label: "Underline" },
],
},
} as const;
import { ToggleGroup } from "@grassroot/ui-solid";
export default function ToggleGroupDemo() {
return (
<div>
<ToggleGroup
options={[...toggleGroupFixture.single.options]}
defaultValue={toggleGroupFixture.single.defaultValue}
/>
<ToggleGroup
type="multiple"
options={[...toggleGroupFixture.multiple.options]}
defaultValue={[...toggleGroupFixture.multiple.defaultValue]}
/>
</div>
);
}

Installation

API Reference

Import

import { ToggleGroup } from "@grassroot/ui-react";

Props

Prop
Type
Default
Requirement
options
ToggleGroupOption[]
required
className
string | undefined
optional
type
"single" | "multiple" | undefined
optional
value
string | string[] | undefined
optional
defaultValue
string | string[] | undefined
optional
onValueChange
((value: string) => void) | ((value: string[]) => void) | undefined
optional
Prop
options
Type
ToggleGroupOption[]
Default
Requirement
required
Prop
className
Type
string | undefined
Default
Requirement
optional
Prop
type
Type
"single" | "multiple" | undefined
Default
Requirement
optional
Prop
value
Type
string | string[] | undefined
Default
Requirement
optional
Prop
defaultValue
Type
string | string[] | undefined
Default
Requirement
optional
Prop
onValueChange
Type
((value: string) => void) | ((value: string[]) => void) | undefined
Default
Requirement
optional

Events

EventPayload
onValueChange((value: string) => void) | ((value: string[]) => void) | undefined

Import

import { ref } from "vue";
import { ToggleGroup } from "@grassroot/ui-vue";

Props

Prop
Type
Default
Requirement
options
ToggleGroupOption[]
required
type
"single" | "multiple" | undefined
"single"
optional
modelValue
string | string[] | undefined
optional
Prop
options
Type
ToggleGroupOption[]
Default
Requirement
required
Prop
type
Type
"single" | "multiple" | undefined
Default
"single"
Requirement
optional
Prop
modelValue
Type
string | string[] | undefined
Default
Requirement
optional

Events

EventPayload
update:modelValue[value: string | string[]]

Import

import { Component } from "@angular/core";
import { GrassrootToggleGroup } from "@grassroot/ui-angular";

Props

Prop
Type
Default
Requirement
options
readonly ToggleGroupOption[]
required
type
"single" | "multiple"
"single"
optional
value
string | string[]
optional
defaultValue
string | string[]
optional
Prop
options
Type
readonly ToggleGroupOption[]
Default
Requirement
required
Prop
type
Type
"single" | "multiple"
Default
"single"
Requirement
optional
Prop
value
Type
string | string[]
Default
Requirement
optional
Prop
defaultValue
Type
string | string[]
Default
Requirement
optional

Events

EventPayload
valueChangestring | string[]

Import

import { ToggleGroup } from "@grassroot/ui-svelte";

Props

Prop
Type
Default
Requirement
options
ToggleGroupOption[]
required
type
"single" | "multiple"
"single"
optional
value
string | string[]
optional
defaultValue
string | string[]
optional
onValueChange
(value: string | string[]) => void
optional
className
string
optional
Prop
options
Type
ToggleGroupOption[]
Default
Requirement
required
Prop
type
Type
"single" | "multiple"
Default
"single"
Requirement
optional
Prop
value
Type
string | string[]
Default
Requirement
optional
Prop
defaultValue
Type
string | string[]
Default
Requirement
optional
Prop
onValueChange
Type
(value: string | string[]) => void
Default
Requirement
optional
Prop
className
Type
string
Default
Requirement
optional

Events

EventPayload
onValueChange(value: string | string[]) => void

Import

import { ToggleGroup } from "@grassroot/ui-solid";

Props

Prop
Type
Default
Requirement
options
ToggleGroupOption[]
required
className
string
optional
type
"single" | "multiple" | undefined
"single"
optional
value
string | string[] | undefined
optional
defaultValue
string | string[] | undefined
optional
onValueChange
((value: string) => void) | ((value: string[]) => void) | undefined
optional
Prop
options
Type
ToggleGroupOption[]
Default
Requirement
required
Prop
className
Type
string
Default
Requirement
optional
Prop
type
Type
"single" | "multiple" | undefined
Default
"single"
Requirement
optional
Prop
value
Type
string | string[] | undefined
Default
Requirement
optional
Prop
defaultValue
Type
string | string[] | undefined
Default
Requirement
optional
Prop
onValueChange
Type
((value: string) => void) | ((value: string[]) => void) | undefined
Default
Requirement
optional

Events

EventPayload
onValueChange((value: string) => void) | ((value: string[]) => void) | undefined