Skip to content

fix(autocomplete): unable to click to select items in IE - #3188

Merged
kara merged 1 commit into
angular:masterfrom
crisbeto:ie-autocomplete-click
Apr 18, 2017
Merged

kara merged 1 commit into
angular:masterfrom
crisbeto:ie-autocomplete-click

Conversation

@crisbeto

@crisbeto crisbeto commented Feb 19, 2017 •

Copy link
Copy Markdown
Member
  • 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
@crisbeto
crisbeto force-pushed the ie-autocomplete-click branch from 3193bcd to b028856 Compare February 23, 2017 18:31
let event = document.createEvent('Event');

if (extras) {
Object.assign(event, extras);

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Addressed the feedback @kara.

@kara

kara commented Feb 28, 2017

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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

kara commented Feb 28, 2017

Copy link
Copy Markdown
Contributor

Ok. Can you fix Firefox?

@crisbeto

Copy link
Copy Markdown
Member Author

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

@crisbeto

crisbeto commented Mar 1, 2017

Copy link
Copy Markdown
Member Author

@kara could you give this another look?

@Only1MrAnderson

Copy link
Copy Markdown

Any update on merging this?

@donduni

donduni commented Apr 10, 2017

Copy link
Copy Markdown

Is there any plan to merge this one?

@kara kara left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@kara kara assigned crisbeto and unassigned kara Apr 11, 2017
@crisbeto
crisbeto force-pushed the ie-autocomplete-click branch from 83a5673 to aa8cfa6 Compare April 12, 2017 18:14
@crisbeto crisbeto assigned crisbeto and kara and unassigned crisbeto Apr 12, 2017
@crisbeto

Copy link
Copy Markdown
Member Author

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

@kara kara left a comment

Copy link
Copy Markdown
Contributor

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.


constructor(private _element: ElementRef, private _overlay: Overlay,
private _viewContainerRef: ViewContainerRef,
private _renderer: Renderer, private _viewContainerRef: ViewContainerRef,

Copy link
Copy Markdown
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?


this._panelOpen = false;
this._resetPlaceholder();
this._changeDetectorRef.detectChanges();

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

}
}

get outsideClickStream(): Observable<any> {

Copy link
Copy Markdown
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
Copy Markdown
Member Author

Addressed the last set of comments @kara.

@kara kara left a comment

Copy link
Copy Markdown
Contributor

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.

}
}

/** Stream of click outside of the autocomplete panel. */

@kara kara Apr 12, 2017 •

Copy link
Copy Markdown
Contributor

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 force-pushed the ie-autocomplete-click branch from b6ac2a9 to eeca900 Compare April 12, 2017 20:12
@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
Copy Markdown

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