1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-12 22:44:11 +00:00

[CL-494] Wrap long words in toggle group (#11659)

This commit is contained in:
Victoria League
2024-10-25 11:48:57 -04:00
committed by GitHub
parent 30d7ef712d
commit 4fe48fc913
5 changed files with 57 additions and 39 deletions

View File

@@ -25,7 +25,7 @@ export class ToggleGroupComponent<TValue = unknown> {
@HostBinding("attr.role") role = "radiogroup";
@HostBinding("class")
get classList() {
return ["tw-flex"].concat(this.fullWidth ? ["tw-w-full", "[&>*]:tw-grow"] : []);
return ["tw-flex"].concat(this.fullWidth ? ["tw-w-full", "[&>*]:tw-flex-1"] : []);
}
onInputInteraction(value: TValue) {

View File

@@ -21,14 +21,6 @@ within that filter.
<Controls />
## 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).
<Canvas of={stories.LabelWrap} />
## Full width
If a toggle group should span the width of its container, pass the `fullWidth` input to the toggle
@@ -42,6 +34,14 @@ group.
<Canvas of={stories.FullWidth} />
## 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).
<Canvas of={stories.LabelWrap} />
# Accessibility
- Since only 1 button can be selected at a time, the toggle group acts similarly to a radio group.

View File

@@ -47,34 +47,6 @@ export const Default: Story = {
},
};
export const LabelWrap: Story = {
render: (args) => ({
props: args,
template: /* HTML */ `
<bit-toggle-group
[(selected)]="selected"
aria-label="People list filter"
class="tw-max-w-[500px]"
>
<bit-toggle value="all">
All of the best things <span bitBadge variant="info">3</span>
</bit-toggle>
<bit-toggle value="invited"> Invited to a cool party </bit-toggle>
<bit-toggle value="accepted">
Accepted the invitation<span bitBadge variant="info">2</span>
</bit-toggle>
<bit-toggle value="deactivated"> Deactivated forever</bit-toggle>
</bit-toggle-group>
`,
}),
args: {
selected: "all",
},
};
export const FullWidth: Story = {
render: (args) => ({
props: args,
@@ -99,3 +71,49 @@ export const FullWidth: Story = {
fullWidth: true,
},
};
export const LabelWrap: Story = {
render: (args) => ({
props: args,
template: /* HTML */ `
<code>fullWidth=false</code>
<bit-toggle-group
[(selected)]="selected"
aria-label="People list filter"
class="tw-max-w-[500px] tw-overflow-hidden tw-border tw-border-solid tw-border-danger-600 tw-py-3"
>
<bit-toggle value="all"> All</bit-toggle>
<bit-toggle value="invited"> Invited to a cool party with cool people </bit-toggle>
<bit-toggle value="accepted">
Accepted the invitation<span bitBadge variant="info">2</span>
</bit-toggle>
<bit-toggle value="deactivated">Deactivatedinvitationswraplabel</bit-toggle>
</bit-toggle-group>
<br />
<code>fullWidth=true</code>
<bit-toggle-group
[(selected)]="selected"
aria-label="People list filter"
class="tw-max-w-[500px] tw-overflow-hidden tw-border tw-border-solid tw-border-danger-600 tw-py-3"
[fullWidth]="fullWidth"
>
<bit-toggle value="all"> All</bit-toggle>
<bit-toggle value="invited"> Invited to a cool party with cool people </bit-toggle>
<bit-toggle value="accepted">
Accepted the invitation<span bitBadge variant="info">2</span>
</bit-toggle>
<bit-toggle value="deactivated">Deactivatedinvitationswraplabel</bit-toggle>
</bit-toggle-group>
`,
}),
args: {
selected: "all",
fullWidth: true,
},
};

View File

@@ -7,7 +7,7 @@
(change)="onInputInteraction()"
/>
<label for="bit-toggle-{{ id }}" [ngClass]="labelClasses" [title]="labelTextContent">
<span class="tw-line-clamp-2" #labelContent>
<span class="tw-line-clamp-2 tw-break-words" #labelContent>
<ng-content></ng-content>
</span>
<span class="tw-shrink-0" #bitBadgeContainer [hidden]="!bitBadgeContainerHasChidlren()">

View File

@@ -27,7 +27,7 @@ export class ToggleComponent<TValue> implements AfterContentChecked {
constructor(private groupComponent: ToggleGroupComponent<TValue>) {}
@HostBinding("tabIndex") tabIndex = "-1";
@HostBinding("class") classList = ["tw-group/toggle", "tw-flex"];
@HostBinding("class") classList = ["tw-group/toggle", "tw-flex", "tw-min-w-16"];
protected bitBadgeContainerHasChidlren = signal(false);