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): better support for input and change events #4826

Merged
merged 5 commits into from Jul 20, 2017

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented May 26, 2017

fixes: #4615

@mmalerba mmalerba requested a review from kara May 26, 2017 19:16
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 26, 2017
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

Some nits. Also looks like the linting task failed, if you want to take a look at that


### Input and change events
The input's native `input` and `change` events will only trigger due to user interaction with the
input element, they will not fire when the user selects a date from the calendar popup. Because of
Copy link
Contributor

Choose a reason for hiding this comment

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

Grammar nit: with the input element, they will not fire => with the input element; they will not fire

The input's native `input` and `change` events will only trigger due to user interaction with the
input element, they will not fire when the user selects a date from the calendar popup. Because of
this limitation, the datepicker input also has support for `dateInput` and `dateChange` events,
these trigger when the user interacts with either the input or the popup.
Copy link
Contributor

Choose a reason for hiding this comment

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

Grammar nit: events, these trigger => events. These trigger when

@@ -43,6 +44,21 @@ export const MD_DATEPICKER_VALIDATORS: any = {
};


/** An event used for datepicker input and change events. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe add something to the comment about why you don't just use the regular event objects from (input) and (change).

@@ -152,7 +174,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
Validators.compose([this._minValidator, this._maxValidator, this._filterValidator]);

constructor(
private _elementRef: ElementRef,
public _elementRef: ElementRef,
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered passing the element and the value to MdDatepickerInputEvent separately (instead of this), so you can keep _elementRef private?

testComponent = fixture.componentInstance;
inputEl = fixture.debugElement.query(By.css('input')).nativeElement;

spyOn(testComponent, 'onChange');
Copy link
Contributor

Choose a reason for hiding this comment

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

Another option would be to use jasmine.createSpy() here. It would remove the need for creating the empty functions in lines 720 on.

testComponent.onChange = jasmine.createSpy('onChange');
testComponent.onInput = jasmine.createSpy('onInput');
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It won't let me just add properties like that, it complains that onChange isn't a member of testComponent

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I guess you'd need to add them on the testComponent too anyway. So I guess it doesn't really help.

@mmalerba
Copy link
Contributor Author

@kara whoops forgot about this for a while, but comments addressed, PTAL

@mmalerba
Copy link
Contributor Author

rebased

Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM, one nit. Apply label when ready.

/**
* An event used for datepicker input and change events. We don't always have access to a native
* input or change event because the event may have been triggered by the user clicking on the
* calendar popup. For consistency we always use MdDatepickerInputEvent instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: For consistency we always -> For consistency, we always use

@@ -134,6 +152,10 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
}
private _disabled: boolean;

@Output() dateChange = new EventEmitter<MdDatepickerInputEvent<D>>();

@Output() dateInput = new EventEmitter<MdDatepickerInputEvent<D>>();
Copy link
Member

Choose a reason for hiding this comment

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

Add user-facing JsDoc for these events

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jul 17, 2017
@kara kara merged commit 35eb294 into angular:master Jul 20, 2017
@mmalerba mmalerba deleted the dp-change branch April 3, 2018 15:18
@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 8, 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.

datepicker: (change) event does not work in mdInput
4 participants