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): allow disabling calendar popup #5305

Merged
merged 9 commits into from Jul 9, 2017

Conversation

g1shin
Copy link

@g1shin g1shin commented Jun 22, 2017

This adds ability to disable datepicker pop-up in read-only mode.

Fixes #5017

@g1shin g1shin self-assigned this Jun 22, 2017
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 22, 2017
@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Jun 23, 2017
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Jun 23, 2017
@g1shin
Copy link
Author

g1shin commented Jun 23, 2017

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.

@mmalerba mmalerba self-assigned this Jun 23, 2017
@g1shin g1shin force-pushed the dppopup branch 2 times, most recently from 0cd3139 to c2e0ecb Compare June 26, 2017 16:43
@g1shin
Copy link
Author

g1shin commented Jun 26, 2017

Ready for review again :)

@kara kara removed their request for review June 26, 2017 17:21
get disabled() { return this._disabled; }
set disabled(value: any) {
this._disabled = coerceBooleanProperty(value);
if (this._datepicker.disabled === undefined) {
Copy link
Contributor

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) {
Copy link
Contributor

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'

get disabled() { return this._disabled; }
set disabled(value: any) {
this._disabled = coerceBooleanProperty(value);
if (this._disabled === undefined) {
Copy link
Contributor

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()
Copy link
Contributor

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

@g1shin
Copy link
Author

g1shin commented Jun 27, 2017

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"
Copy link
Contributor

@kara kara Jun 27, 2017

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>

@@ -209,6 +220,9 @@ export class MdDatepicker<D> implements OnDestroy {
if (this.opened) {
return;
}
if (this.disabled) {
return;
Copy link
Contributor

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(() => {
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Author

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(() => {
Copy link
Contributor

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>
Copy link
Contributor

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) {
Copy link
Contributor

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>
Copy link
Contributor

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

@mmalerba mmalerba changed the title fix(datepicker): disable pop-up in read-only mode fix(datepicker): allow disabling calendar popup Jun 29, 2017
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jun 29, 2017
@mmalerba mmalerba added presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged labels Jul 7, 2017
@mmalerba
Copy link
Contributor

mmalerba commented Jul 7, 2017

caretaker note: build files need to be updated to reflect datepicker dependency on cdk

@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 6, 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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to disable datepicker pop-up
5 participants