General
Button
Usage#
import { WdsButtonComponent } from '@wds/angular/button';Examples#
Size#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@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="icon-xs" label="Send">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
</wds-button>
<wds-button variant="outline" size="icon-sm" label="Send">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
</wds-button>
<wds-button variant="outline" size="icon" label="Send">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
</wds-button>
<wds-button variant="outline" size="icon-lg" label="Send">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
</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#
label: it becomes its accessible name.
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-icon-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" size="icon" label="Next">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6" /></svg>
</wds-button>
`,
})
export class ButtonIconDemo {}With icon#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-with-icon-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" size="sm">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3v12" /><circle cx="18" cy="6" r="3" /><circle cx="6" cy="18" r="3" /><path d="M18 9a9 9 0 0 1-9 9" /></svg>
New branch
</wds-button>
`,
})
export class ButtonWithIconDemo {}Rounded#
import { Component } from '@angular/core';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-button-rounded-demo',
imports: [WdsButtonComponent],
template: `
<wds-button variant="outline" size="icon" shape="circle" label="Scroll to top">
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 7-7 7 7" /><path d="M12 19V5" /></svg>
</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.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| variant | WdsButtonVariant | 'default' | |
| size | WdsButtonSize | 'default' | icon* is a square, icon-only button (set label then). |
| 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 icon* sizes. | |
| href | string | undefined | ||
| target | string | undefined |
Slots
| Slot | Description |
|---|---|
| (default) | <svg> icon). |
CSS parts (::part)
| Part | Description |
|---|---|
| button | <button> or <a>. |
Accessibility#
Screen reader#
wds-button renders a native <button>, or with href a native <a>, so it has the matching role and behavior.
size="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). |