Skip to content

Commit aa40684

Browse files
authored
docs: add signal form example for button toggle (#33592)
* docs: add signal form example for button toggle * docs: update copy related to forms for Button Toggle
1 parent 1a3d972 commit aa40684

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎src/components-examples/material/button-toggle/button-toggle-forms/button-toggle-forms-example.html‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<section>
2+
<h4>Button Toggle inside of a Signal form</h4>
3+
<mat-button-toggle-group [formField]="fontStyleForm" aria-label="Font Style">
4+
<mat-button-toggle value="bold">Bold</mat-button-toggle>
5+
<mat-button-toggle value="italic">Italic</mat-button-toggle>
6+
<mat-button-toggle value="underline">Underline</mat-button-toggle>
7+
</mat-button-toggle-group>
8+
<p>Chosen value is {{ fontStyleForm().value() }}</p>
9+
</section>
10+
111
<section>
212
<h4>Button Toggle inside of a Template-driven form</h4>
313
<mat-button-toggle-group [(ngModel)]="fontStyle" aria-label="Font Style">
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Component, signal} from '@angular/core';
22
import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms';
3+
import {form, FormField} from '@angular/forms/signals';
34
import {MatButtonToggleModule} from '@angular/material/button-toggle';
45

56
/**
@@ -8,9 +9,10 @@ import {MatButtonToggleModule} from '@angular/material/button-toggle';
89
@Component({
910
selector: 'button-toggle-forms-example',
1011
templateUrl: 'button-toggle-forms-example.html',
11-
imports: [MatButtonToggleModule, FormsModule, ReactiveFormsModule],
12+
imports: [MatButtonToggleModule, FormsModule, ReactiveFormsModule, FormField],
1213
})
1314
export class ButtonToggleFormsExample {
14-
fontStyleControl = new FormControl('');
15-
fontStyle = signal<string | undefined>(undefined);
15+
readonly fontStyleControl = new FormControl('');
16+
readonly fontStyle = signal<string | undefined>(undefined);
17+
readonly fontStyleForm = form(signal(''));
1618
}

‎src/material/button-toggle/button-toggle.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ be configured globally using the `MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS` injection t
2424

2525
<!-- example(button-toggle-appearance) -->
2626

27-
### Use with `@angular/forms`
28-
`<mat-button-toggle-group>` is compatible with `@angular/forms` and supports both `FormsModule`
29-
and `ReactiveFormsModule`.
27+
### Use with Angular Forms
28+
`<mat-button-toggle-group>` is compatible with `@angular/forms` and supports `FormField`, `FormsModule`, and `ReactiveFormsModule`.
3029

3130
### Orientation
3231
The button-toggles can be rendered in a vertical orientation by adding the `vertical` attribute.

0 commit comments

Comments
 (0)