diff --git a/libs/components/src/toggle-group/toggle-group.component.ts b/libs/components/src/toggle-group/toggle-group.component.ts index 907b5c9c582..b59b90e894f 100644 --- a/libs/components/src/toggle-group/toggle-group.component.ts +++ b/libs/components/src/toggle-group/toggle-group.component.ts @@ -1,4 +1,11 @@ -import { Component, EventEmitter, HostBinding, Input, Output } from "@angular/core"; +import { + booleanAttribute, + Component, + EventEmitter, + HostBinding, + Input, + Output, +} from "@angular/core"; let nextId = 0; @@ -11,11 +18,15 @@ export class ToggleGroupComponent { private id = nextId++; name = `bit-toggle-group-${this.id}`; + @Input({ transform: booleanAttribute }) fullWidth?: boolean; @Input() selected?: TValue; @Output() selectedChange = new EventEmitter(); @HostBinding("attr.role") role = "radiogroup"; - @HostBinding("class") classList = ["tw-flex"]; + @HostBinding("class") + get classList() { + return ["tw-flex"].concat(this.fullWidth ? ["tw-w-full", "[&>*]:tw-grow"] : []); + } onInputInteraction(value: TValue) { this.selected = value; diff --git a/libs/components/src/toggle-group/toggle-group.mdx b/libs/components/src/toggle-group/toggle-group.mdx index cd487934cec..252627f3d32 100644 --- a/libs/components/src/toggle-group/toggle-group.mdx +++ b/libs/components/src/toggle-group/toggle-group.mdx @@ -15,21 +15,34 @@ Toggle groups function as radio buttons and a radio group under the hood. A button in a toggle group can have a badge counter added to show the number of items existing within that filter. +## Default + + + + + +## Label wrap + If the labels in a toggle group would overflow the width of the toggle group container, then the labels will wrap to 2 lines and truncate with an ellipsis past that. The full label text is accessible via the `title` prop (i.e. visible on hover). - - - + - - - +## Full width - +If a toggle group should span the width of its container, pass the `fullWidth` input to the toggle +group. -## Accessibility +``` + +...toggle components here... + +``` + + + +# Accessibility - Since only 1 button can be selected at a time, the toggle group acts similarly to a radio group. - The user may navigate the options via left/right arrow keys. diff --git a/libs/components/src/toggle-group/toggle-group.stories.ts b/libs/components/src/toggle-group/toggle-group.stories.ts index 78f7d700b57..f6e10291e1d 100644 --- a/libs/components/src/toggle-group/toggle-group.stories.ts +++ b/libs/components/src/toggle-group/toggle-group.stories.ts @@ -74,3 +74,28 @@ export const LabelWrap: Story = { selected: "all", }, }; + +export const FullWidth: Story = { + render: (args) => ({ + props: args, + template: /* HTML */ ` + + All 3 + + Invited + + Accepted 2 + + Deactivated + + `, + }), + args: { + selected: "all", + fullWidth: true, + }, +}; diff --git a/libs/components/src/toggle-group/toggle.component.ts b/libs/components/src/toggle-group/toggle.component.ts index b42d03f3256..a6a27180a87 100644 --- a/libs/components/src/toggle-group/toggle.component.ts +++ b/libs/components/src/toggle-group/toggle.component.ts @@ -50,8 +50,10 @@ export class ToggleComponent implements AfterContentChecked { get labelClasses() { return [ "tw-h-full", + "tw-w-full", "tw-flex", "tw-items-center", + "tw-justify-center", "tw-gap-1.5", "!tw-font-semibold", "tw-leading-5",