Skip to content

fix(material/select): show required asterisk when using required validator #23500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2021

Conversation

crisbeto
Copy link
Member

Similar to #23362. Fixes that the required asterisk wasn't being shown when a select is required.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release labels Aug 31, 2021
@crisbeto crisbeto added this to the 13.0.0 milestone Aug 31, 2021
@crisbeto crisbeto requested a review from jelbourn August 31, 2021 19:41
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 31, 2021
…dator

Similar to angular#23362. Fixes that the required asterisk wasn't being shown when a select is required.
@crisbeto crisbeto force-pushed the select-required-asterisk branch from b2671d1 to 5df0079 Compare August 31, 2021 19:58
@@ -317,12 +323,14 @@ export abstract class _MatSelectBase<C> extends _MatSelectMixinBase implements A

/** Whether the component is required. */
@Input()
get required(): boolean { return this._required; }
get required(): boolean {
return this._required ?? this.ngControl?.control?.hasValidator(Validators.required) ?? false;
Copy link
Member

Choose a reason for hiding this comment

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

Should this also have a test for explicitly setting required overriding the form control required state?

Copy link
Member Author

Choose a reason for hiding this comment

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

The forms module will log a deprecation warning if required is used on an element with formControl.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

lgtm

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Sep 7, 2021
@mmalerba mmalerba merged commit 64ba72f into angular:master Oct 5, 2021
@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 Nov 5, 2021
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 cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants