General
Button
Usage#
import { WdsButtonComponent } from '@wds/angular/button';Examples#
Size#
size sets the height, padding and icon size: xs (24px), sm (28px), default (32px) and lg (36px). Icon-only buttons use the same sizes.
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
import '@wds/core/icons/lucide/arrow-up';
@Component({
selector: 'app-button-size-demo',
imports: [WdsButtonComponent],
template: `
<div class="flex flex-wrap items-center gap-2">
<wds-button variant="outline" size="xs">Button xs</wds-button>
<wds-button variant="outline" size="sm">Button sm</wds-button>
<wds-button variant="outline">Button</wds-button>
<wds-button variant="outline" size="lg">Button lg</wds-button>
</div>
<div class="flex flex-wrap items-center gap-2">
<wds-button variant="outline" size="xs" label="Send" icon="lucide-arrow-up"></wds-button>
<wds-button variant="outline" size="sm" label="Send" icon="lucide-arrow-up"></wds-button>
<wds-button variant="outline" label="Send" icon="lucide-arrow-up"></wds-button>
<wds-button variant="outline" size="lg" label="Send" icon="lucide-arrow-up"></wds-button>
</div>
`,
})
export class ButtonSizeDemo {}Variants#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-variants-demo',
imports: [WdsButtonComponent],
template: `
<wds-button>Default</wds-button>
<wds-button variant="outline">Outline</wds-button>
<wds-button variant="secondary">Secondary</wds-button>
<wds-button variant="ghost">Ghost</wds-button>
<wds-button variant="destructive">Destructive</wds-button>
<wds-button variant="link">Link</wds-button>
`,
})
export class ButtonVariantsDemo {}Disabled#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-disabled-demo',
imports: [WdsButtonComponent],
template: `
<wds-button disabled>Disabled</wds-button>
<wds-button variant="outline" disabled>Disabled</wds-button>
`,
})
export class ButtonDisabledDemo {}Icon#
icon makes a square, icon-only button of the given size; the button sets the icon size too. An icon-only button needs a label: it becomes its accessible name. Your own <svg> or <wds-icon> as the only content gives the same square.
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
import '@wds/core/icons/lucide/chevron-right';
@Component({
selector: 'app-button-icon-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" label="Next" icon="lucide-chevron-right"></wds-button>
`,
})
export class ButtonIconDemo {}With icon#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
import '@wds/core/icons/lucide/git-branch';
@Component({
selector: 'app-button-with-icon-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" size="sm" icon-start="lucide-git-branch">
New branch
</wds-button>
`,
})
export class ButtonWithIconDemo {}Rounded#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
import '@wds/core/icons/lucide/arrow-up';
@Component({
selector: 'app-button-rounded-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" shape="circle" label="Scroll to top" icon="lucide-arrow-up"></wds-button>
<wds-button shape="circle">Rounded</wds-button>
<wds-button variant="secondary" shape="square">Square</wds-button>
`,
})
export class ButtonRoundedDemo {}Loading#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-loading-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" size="sm" loading>Sending</wds-button>
`,
})
export class ButtonLoadingDemo {}Spinner#
import { Component, signal } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-spinner-demo',
imports: [WdsButtonComponent],
template: `
<wds-button [loading]="saving()" (click)="save()">
{{ saving() ? 'Saving' : 'Save' }}
</wds-button>
`,
})
export class ButtonSpinnerDemo {
protected readonly saving = signal(false);
protected save(): void {
this.saving.set(true);
setTimeout(() => this.saving.set(false), 1500);
}
}As link#
href przycisk renderuje natywny <a>.
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-as-link-demo',
imports: [WdsButtonComponent],
template: `
<wds-button href="https://developer.mozilla.org/docs/Web/HTML/Element/a" target="_blank">Open documentation</wds-button>
<wds-button variant="link" href="#">Link as button</wds-button>
`,
})
export class ButtonAsLinkDemo {}API References#
wds-button#
<button>, or with href a native <a> that looks like a button.
aria-expanded, aria-haspopup, aria-pressed, aria-current, aria-keyshortcuts, aria-description and aria-label on the host are forwarded to the native element.
icon-start and icon-end add a registered icon before or after the text (e.g. icon-start="lucide-plus").
icon makes a square, icon-only button in any size (set label then); content made only of <svg> or
<wds-icon> elements does the same. An icon-only button matches wds-button:state(icon-only) in CSS.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| variant | WdsButtonVariant | 'default' | |
| size | WdsButtonSize | 'default' | xs (24px), sm (28px), default (32px) or lg (36px). |
| shape | WdsButtonShape | 'default' | circle or square. |
| type | WdsButtonType | 'button' | |
| disabled | boolean | false | click listeners, as with a native disabled button. |
| loading | boolean | false | aria-busy. |
| label | string | undefined | aria-label), required for an icon-only button. | |
| icon | string | undefined | lucide-x (after import '@wds/core/icons/lucide/x').
The button becomes a square of its size; set label. While loading the spinner takes its place. | |
| icon-start.iconStart | string | undefined | lucide-plus (after import '@wds/core/icons/lucide/plus').
While loading the spinner takes its place. | |
| icon-end.iconEnd | string | undefined | lucide-chevron-down on a menu trigger. | |
| icon-flip-rtl.iconFlipRtl | WdsIconFlip | undefined | start, end or both.
The icon of an icon-only button is mirrored by any value, also by the attribute without a value. | |
| href | string | undefined | ||
| target | string | undefined |
Slots
| Slot | Description |
|---|---|
| (default) | <svg> or <wds-icon> when an icon attribute is not enough. |
CSS parts (::part)
| Part | Description |
|---|---|
| button | <button> or <a>. |
| icon | icon). |
| icon-start | icon-start). |
| icon-end | icon-end). |
Accessibility#
Screen reader#
wds-button renders a native <button>, or with href a native <a>, so it has the matching role and behavior.
icon) needs a label: it becomes the aria-label.
disabled disables the native button; a disabled link loses its href and gets role="link" and aria-disabled="true". loading sets aria-busy="true" and makes the button inactive.
aria-expanded, aria-haspopup, aria-pressed, aria-current and aria-label set on wds-button are forwarded to the native element.
Keyboard support#
| Key | Function |
|---|---|
Enter). |