Skip to content
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

fix(datepicker): use disabled state from FormControl #7514

Merged
merged 1 commit into from
Oct 6, 2017

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Oct 3, 2017

fixes #6973

@mmalerba mmalerba requested review from kara and crisbeto October 3, 2017 22:05
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 3, 2017
@@ -147,7 +147,7 @@ export class MatDatepickerInput<D> implements AfterContentInit, ControlValueAcce

/** Whether the datepicker-input is disabled. */
@Input()
get disabled() { return this._disabled; }
get disabled() { return !!this._disabled; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question, is this (and some others in this PR) "coercion" really necessary? Isn't _disabled already being coerced in set disabled(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In most cases the coerceBooleanProperty would take care of it. Datepicker is a special case because of its cascading disabled state. We need to distinguish between never set and false to make this work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, thanks for explaining :)

@@ -44,39 +45,43 @@ export class MatDatepickerToggle<D> implements OnChanges, OnDestroy {
/** Whether the toggle button is disabled. */
@Input()
get disabled() {
return this._disabled === undefined ? this.datepicker.disabled : this._disabled;
return this._disabled === undefined ? this.datepicker.disabled : !!this._disabled;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be this._disabled == null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Either would work

Copy link
Contributor

Choose a reason for hiding this comment

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

So this disabled is never null? Because if disabled is null this comparison (null === undefined) won't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

coerceBooleanProperty will make sure its never null. The only reason it can be undefined is because we don't set an initial value for _disabled, so if there's no property binding for disabled the setter is never called and it remains undefined

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Oct 4, 2017
@kara
Copy link
Contributor

kara commented Oct 5, 2017

@mmalerba Rebase?

@kara kara assigned mmalerba and unassigned kara and crisbeto Oct 5, 2017
@kara kara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Oct 5, 2017
@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Oct 5, 2017
@mmalerba
Copy link
Contributor Author

mmalerba commented Oct 5, 2017

done

@kara kara merged commit 66e71c8 into angular:master Oct 6, 2017
@mmalerba mmalerba deleted the dp-fc-disabled branch July 31, 2018 21:19
@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 Sep 9, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MdDatepicker and MdDatepickerToggle should be disabled when its input associated is disabled (reactive forms)
5 participants