Skip to content

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 6, 2024

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.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Dec 6, 2024
@crisbeto crisbeto requested a review from a team as a code owner December 6, 2024 13:28
@crisbeto crisbeto requested review from andrewseguin and mmalerba and removed request for a team December 6, 2024 13:28

### Allowing nullable options to be selected

By default any options with a `null` or `undefined` value will reset the select's value. This is
Copy link
Contributor

@andrewseguin andrewseguin Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably remove the statement about mimicing native behavior, since I don't think that's the actual case anymore. It's enough to include the first sentence to basically say "this is how we handle null by default"

@andrewseguin andrewseguin added the action: merge The PR is ready for merge by the caretaker label Dec 10, 2024
@crisbeto crisbeto removed the request for review from mmalerba December 10, 2024 20:36
…ble options

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 angular#25120.
@crisbeto crisbeto force-pushed the 25120/select-nullable branch from d489620 to 23d28b5 Compare December 10, 2024 20:38
@crisbeto crisbeto merged commit 0296713 into angular:main Dec 10, 2024
18 of 20 checks passed
crisbeto added a commit that referenced this pull request Dec 10, 2024
…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)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: material/select target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mat-select does not display default (null) option text in mat-option

2 participants