-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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): allow disabling calendar popup #5305
Conversation
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
CLAs look good, thanks! |
Fixed and ready for review. @mmalerba Input and button already had the "disabled" attribute, so I didn't need to add it to datepicker-input and datepicker-toggle. |
0cd3139
to
c2e0ecb
Compare
Ready for review again :) |
get disabled() { return this._disabled; } | ||
set disabled(value: any) { | ||
this._disabled = coerceBooleanProperty(value); | ||
if (this._datepicker.disabled === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to do this here, only modify your own disabledness
@@ -36,7 +36,7 @@ export class MdDatepickerToggle<D> { | |||
constructor(public _intl: MdDatepickerIntl) {} | |||
|
|||
_open(event: Event): void { | |||
if (this.datepicker) { | |||
if (this.datepicker && !this.datepicker.disabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add your own disabled input:
@Input()
get disabled() {
return this._disabled === undefined ? this.datepicker.disabled : this._disabled;
}
set disabled(value) {
this._disabled = coerceBooleanValue(value);
}
because buttons also have a native disabled attribute you'll have to add the host binding too: '[disabled]': 'disabled'
src/lib/datepicker/datepicker.ts
Outdated
get disabled() { return this._disabled; } | ||
set disabled(value: any) { | ||
this._disabled = coerceBooleanProperty(value); | ||
if (this._disabled === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to how i showed in the other example, put the delegation logic in the getter
@@ -124,6 +125,17 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces | |||
} | |||
private _max: D; | |||
|
|||
/** Whether the datepicker-input is disabled. */ | |||
@Input() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to also add a host binding: '[disabled]': 'disabled'
, to keep the native disabled attribute in sync with this
Changes made. Ready for review |
<button [mdDatepickerToggle]="datePicker2"></button> | ||
<md-input-container> | ||
<input mdInput [mdDatepicker]="datePicker2" [(ngModel)]="date" [min]="minDate" [max]="maxDate" | ||
[mdDatepickerFilter]="filterOdd ? dateFilter : null" [disabled]="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since disabled
will always be true here, you should be able to just use the attribute.
<input mdInput disabled>
src/lib/datepicker/datepicker.ts
Outdated
@@ -209,6 +220,9 @@ export class MdDatepicker<D> implements OnDestroy { | |||
if (this.opened) { | |||
return; | |||
} | |||
if (this.disabled) { | |||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Seems like you can bundle this with the existing early return on line 220:
if (this.opened || this.disabled) {
return;
}
@@ -96,6 +95,20 @@ describe('MdDatepicker', () => { | |||
expect(document.querySelector('md-dialog-container')).not.toBeNull(); | |||
})); | |||
|
|||
it('open in disabled mode should not open the calendar', async(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this test is async. It doesn't look like you're using any of async testing methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point I think calling open
required it to be async, I'm not sure if that's still the case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like open
does not require async, so I removed async from other parts of the code as well.
@@ -96,6 +95,20 @@ describe('MdDatepicker', () => { | |||
expect(document.querySelector('md-dialog-container')).not.toBeNull(); | |||
})); | |||
|
|||
it('open in disabled mode should not open the calendar', async(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At one point I think calling open
required it to be async, I'm not sure if that's still the case
</p> | ||
|
||
<h2>Result</h2> | ||
|
||
<p> | ||
<button [mdDatepickerToggle]="resultPicker"></button> | ||
<button [mdDatepickerToggle]="resultPicker" [disabled]="resultPickerModel.disabled"></button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need to disabled
attr here
constructor(public _intl: MdDatepickerIntl) {} | ||
|
||
_open(event: Event): void { | ||
if (this.datepicker) { | ||
if (this.datepicker && !this._disabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disabled
(_disabled
doesn't have the cascading behavior)
@@ -734,11 +747,12 @@ describe('MdDatepicker', () => { | |||
@Component({ | |||
template: ` | |||
<input [mdDatepicker]="d" [value]="date"> | |||
<md-datepicker #d [touchUi]="touch"></md-datepicker> | |||
<md-datepicker #d [touchUi]="touch" [disabled]="disabled"></md-datepicker> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should add tests for cascade as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
caretaker note: build files need to be updated to reflect datepicker dependency on cdk |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This adds ability to disable datepicker pop-up in read-only mode.
Fixes #5017