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(autocomplete): unable to click to select items in IE #3188

Merged
merged 1 commit into from
Apr 18, 2017

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Feb 19, 2017

  • 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 #3351.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 19, 2017
let event = document.createEvent('Event');

if (extras) {
Object.assign(event, extras);
Copy link
Contributor

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

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?

@crisbeto
Copy link
Member Author

Addressed the feedback @kara.

@kara
Copy link
Contributor

kara commented Feb 28, 2017

@crisbeto Closing on blur still appears to be broken on Firefox. Have you tried just expanding the old check to include MAT-OPTION?

@crisbeto
Copy link
Member Author

The issue isn't with the node name, I'm testing it against our demo app that uses only md-option. It breaks because IE doesn't assign the relatedTarget.

@kara
Copy link
Contributor

kara commented Feb 28, 2017

Ok. Can you fix Firefox?

@crisbeto
Copy link
Member Author

I will, although it may be worth rethinking the approach since the relatedTarget seems to be pretty brittle.

@crisbeto
Copy link
Member Author

crisbeto commented Mar 1, 2017

@kara could you give this another look?

@Only1MrAnderson
Copy link

Any update on merging this?

@donduni
Copy link

donduni commented Apr 10, 2017

Is there any plan to merge this one?

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.

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

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);
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 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
}

Copy link
Member Author

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.

Copy link
Contributor

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.

@crisbeto
Copy link
Member Author

Fixed the test failures, addressed the feedback and rebased @kara.

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.

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

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();
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 is necessary. Add comment?

Copy link
Member Author

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.

Copy link
Contributor

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

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.

@crisbeto crisbeto force-pushed the ie-autocomplete-click branch 2 times, most recently from 56ac940 to b6ac2a9 Compare April 12, 2017 18:51
@crisbeto
Copy link
Member Author

Addressed the last set of comments @kara.

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. 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. */
Copy link
Contributor

@kara kara Apr 12, 2017

Choose a reason for hiding this comment

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

Typo: clicks

@kara kara assigned crisbeto and unassigned kara Apr 12, 2017
* 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.
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Apr 12, 2017
@kara kara merged commit 78985b7 into angular:master Apr 18, 2017
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug - Can't select an option in autocomplete IE 11
5 participants