-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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.
A few more nits, then should be good to go.
@@ -100,9 +102,11 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
} | |||
|
|||
constructor(private _element: ElementRef, private _overlay: Overlay, | |||
private _viewContainerRef: ViewContainerRef, | |||
private _renderer: Renderer, private _viewContainerRef: ViewContainerRef, |
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.
Looks like you're not using the renderer anymore. Remove?
@@ -144,6 +148,7 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
|
|||
this._panelOpen = false; | |||
this._resetPlaceholder(); | |||
this._changeDetectorRef.detectChanges(); |
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 is necessary. Add comment?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Just for posterity, would be good to have that documented.
@@ -170,6 +175,17 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
} | |||
} | |||
|
|||
get outsideClickStream(): Observable<any> { |
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.
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. |
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. Found a typo, so apply merge label whenever you're ready.
@@ -170,6 +179,18 @@ export class MdAutocompleteTrigger implements ControlValueAccessor, OnDestroy { | |||
} | |||
} | |||
|
|||
/** Stream of click outside of the autocomplete panel. */ |
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.
Typo: clicks
* 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.relatedTarget
for blur events.mat-option
, instead ofmd-option
.Fixes #3351.