-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(material/select): add opt-in input that allows selection of nulla…
…ble options (#30142) By default `mat-select` treats options with nullable values as "reset options", meaning that they can't be selected, but rather they clear the select's value. This behavior is based on how the native `select` works, however in some cases it's not desirable. These changes add an input that users can use to opt out of the default behavior. Fixes #25120. (cherry picked from commit 0296713)
- Loading branch information
Showing
7 changed files
with
175 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...nents-examples/material/select/select-selectable-null/select-selectable-null-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h4>mat-select allowing selection of nullable options</h4> | ||
<mat-form-field> | ||
<mat-label>State</mat-label> | ||
<mat-select [(ngModel)]="value" canSelectNullableOptions> | ||
@for (option of options; track option) { | ||
<mat-option [value]="option.value">{{option.label}}</mat-option> | ||
} | ||
</mat-select> | ||
</mat-form-field> | ||
|
||
<h4>mat-select with default configuration</h4> | ||
<mat-form-field> | ||
<mat-label>State</mat-label> | ||
<mat-select [(ngModel)]="value"> | ||
@for (option of options; track option) { | ||
<mat-option [value]="option.value">{{option.label}}</mat-option> | ||
} | ||
</mat-select> | ||
</mat-form-field> |
21 changes: 21 additions & 0 deletions
21
...ponents-examples/material/select/select-selectable-null/select-selectable-null-example.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {MatInputModule} from '@angular/material/input'; | ||
import {MatSelectModule} from '@angular/material/select'; | ||
import {MatFormFieldModule} from '@angular/material/form-field'; | ||
|
||
/** @title Select with selectable null options */ | ||
@Component({ | ||
selector: 'select-selectable-null-example', | ||
templateUrl: 'select-selectable-null-example.html', | ||
imports: [MatFormFieldModule, MatSelectModule, MatInputModule, FormsModule], | ||
}) | ||
export class SelectSelectableNullExample { | ||
value: number | null = null; | ||
options = [ | ||
{label: 'None', value: null}, | ||
{label: 'One', value: 1}, | ||
{label: 'Two', value: 2}, | ||
{label: 'Three', value: 3}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters