Repository navigation
fix(autocomplete): unable to click to select items in IE - #3188
Conversation
3193bcd to
b028856
Compare
| let event = document.createEvent('Event'); | ||
|
|
||
| if (extras) { | ||
| Object.assign(event, extras); |
There was a problem hiding this comment.
Can you use extendObject from core utils instead?
| // Only emit blur event if the new focus is *not* on an option. | ||
| if (newlyFocusedTag !== 'MD-OPTION') { | ||
| // Only emit blur event if the new focus is *not* on an element inside the panel. | ||
| if (relatedTarget && !this._overlayRef.overlayElement.contains(relatedTarget)) { |
There was a problem hiding this comment.
This appears to break clicking outside the panel to close it in Chrome and Firefox. Can you fix?
b028856 to
ba31165
Compare
|
Addressed the feedback @kara. |
|
@crisbeto Closing on blur still appears to be broken on Firefox. Have you tried just expanding the old check to include MAT-OPTION? |
|
The issue isn't with the node name, I'm testing it against our demo app that uses only |
|
Ok. Can you fix Firefox? |
|
I will, although it may be worth rethinking the approach since the |
|
@kara could you give this another look? |
|
Any update on merging this? |
|
Is there any plan to merge this one? |
kara
left a comment
There was a problem hiding this comment.
Sorry for the late review on this. Seems to be working great on both Firefox and Chrome now, but I think it needs a rebase.
| this._outsideClickStream.next(null); | ||
| } | ||
| }); | ||
| } |
There was a problem hiding this comment.
openPanel is getting a bit heavy. Can you move this new block into its own method?
| (event: MouseEvent) => { | ||
| if (!this._inputContainer._elementRef.nativeElement.contains(event.target) && | ||
| !this._overlayRef.overlayElement.contains(event.target as HTMLElement)) { | ||
| this._outsideClickStream.next(null); |
There was a problem hiding this comment.
Have you thought about using Observable.fromEvent here? I think it would be cleaner, because then we don't have the maintain the subscription or manually emit (we can just pass it to panelClosingActions).
get outsideClickStream() {
return Observable.fromEvent(this._document, 'click')
.filter(event => // check if contains target);
}
get panelClosingActions() {
...
this.outsideClickStream
}There was a problem hiding this comment.
IIRC, I didn't go with fromEvent, because it may break server-side rendering. Thinking about it again, it should be fine since the menu shows up as a result from a user action.
There was a problem hiding this comment.
I see. Yeah, had the same train of thought. I think it will be fine given that it's not on initial render.
83a5673 to
aa8cfa6
Compare
|
Fixed the test failures, addressed the feedback and rebased @kara. |
kara
left a comment
There was a problem hiding this comment.
A few more nits, then should be good to go.
|
|
||
| constructor(private _element: ElementRef, private _overlay: Overlay, | ||
| private _viewContainerRef: ViewContainerRef, | ||
| private _renderer: Renderer, private _viewContainerRef: ViewContainerRef, |
There was a problem hiding this comment.
Looks like you're not using the renderer anymore. Remove?
|
|
||
| this._panelOpen = false; | ||
| this._resetPlaceholder(); | ||
| this._changeDetectorRef.detectChanges(); |
There was a problem hiding this comment.
Curious why this is necessary. Add comment?
There was a problem hiding this comment.
I'll add a comment. It seems like using fromEvent doesn't trigger change detection, or at least it doesn't trigger it at the proper time. This means that the placeholder doesn't get reset when you click on the backdrop.
There was a problem hiding this comment.
Makes sense. Just for posterity, would be good to have that documented.
| } | ||
| } | ||
|
|
||
| get outsideClickStream(): Observable<any> { |
There was a problem hiding this comment.
Hmm let's keep this private? I think I may have omitted the _ in my comment above by mistake, but I liked that you originally had it private.
56ac940 to
b6ac2a9
Compare
|
Addressed the last set of comments @kara. |
kara
left a comment
There was a problem hiding this comment.
LGTM. Found a typo, so apply merge label whenever you're ready.
| } | ||
| } | ||
|
|
||
| /** Stream of click outside of the autocomplete panel. */ |
* Fixes being unable to select autocomplete items by clicking in IE. This was due to IE not setting the event.relatedTarget for blur events. * Fixes potential issue if the user uses mat-option, instead of md-option. Fixes angular#3351.
b6ac2a9 to
eeca900
Compare
|
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. |
event.relatedTargetfor blur events.mat-option, instead ofmd-option.Fixes #3351.