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): reopening closed autocomplete when coming back to tab #12372

Merged
merged 1 commit into from
Aug 23, 2018

Conversation

crisbeto
Copy link
Member

Fixes a closed autocomplete being reopened, if the user moves to another tab and coming back to the current one, while the input is still focused.

Fixes #12337.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jul 25, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 25, 2018
/**
* Whether the autocomplete can open the next time it is focused. Used to prevent a focused,
* closed autocomplete from being reopened if the user switches to another tab and then
* comes back.
Copy link
Member

Choose a reason for hiding this comment

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

Clarify "browser tab" to disambiguate from a tabs component?


ngOnDestroy() {
if (typeof window !== 'undefined') {
window.removeEventListener('blur', this._windowBlurHandler);
Copy link
Member

Choose a reason for hiding this comment

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

This will be a good use for the Page Lifecycle API... someday.

Copy link
Member Author

Choose a reason for hiding this comment

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

The browser support isn't too horrible tbh, but I think that this is case is simple enough that we can get away with the event.

* Event handler for when the window is blurred. Needs to be an
* arrow function in order to preserve the context.
*/
private _windowBlurHandler = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Move this up to live next to the other class properties?

*/
private _windowBlurHandler = () => {
this._canOpenOnNextFocus =
document.activeElement !== this._element.nativeElement || this.panelOpen;
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment that explains the rationale behind this logic?

@crisbeto crisbeto force-pushed the 12337/autocomplete-reopen branch from a2bab41 to b87f005 Compare July 25, 2018 19:20
@crisbeto
Copy link
Member Author

Feedback has been addressed @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Jul 25, 2018
@ngbot
Copy link

ngbot bot commented Aug 1, 2018

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

Fixes a closed autocomplete being reopened, if the user moves to another tab and coming back to the current one, while the input is still focused.

Fixes angular#12337.
@crisbeto crisbeto force-pushed the 12337/autocomplete-reopen branch from b87f005 to 2094132 Compare August 3, 2018 15:35
@jelbourn jelbourn merged commit c2b488e into angular:master Aug 23, 2018
jelbourn pushed a commit that referenced this pull request Aug 29, 2018
…tab (#12372)

Fixes a closed autocomplete being reopened, if the user moves to another tab and coming back to the current one, while the input is still focused.

Fixes #12337.
@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 9, 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 target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mat-autocomplete panel reopens again after browser tab switch
3 participants