Skip to content

refactor(cdk/overlay): remove logic which tracks excluded elements from outside clicks #19887

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

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

andy9775
Copy link
Contributor

@andy9775 andy9775 commented Jul 7, 2020

This removes the ability to track excluded elements from the overlay and only stops outside
click event notifications if the click event occurred within an overlay element itself. The
overlay should not track elements to be excluded from outside click - this should be up
to the developer. This allows for custom closeout logic to be implemented by the developer leaving
the cdk to be unopinionated.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 7, 2020
@andy9775 andy9775 requested a review from teflonwaffles July 7, 2020 16:31
/**
* Array of HTML elements clicking on which should not be considered as outside click
*/
excludeFromOutsideClick?: HTMLElement[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

I think we talked about having this be a predicate function instead of an array of elements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jelbourn we later agreed that we should just emit on the _outsidePointerEvents subject and have the user decide correct?

Copy link
Member

@jelbourn jelbourn Jul 7, 2020

Choose a reason for hiding this comment

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

Yeah, when Andy and I followed-up on the discussion in the team meeting, I remembered that the outsidePointerEvents stream is, well, a stream that people can filter themselves however they want, so adding a predication would literally just be adding a call to filter, so calling the API is the same amount of work as adding a filter yourself.

Copy link
Contributor Author

@andy9775 andy9775 Jul 8, 2020

Choose a reason for hiding this comment

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

@jelbourn thinking about it now, adding a predicate can stop overlays added earlier from being processed since the loop would just break based on the predicates return. I can implement the menu with either approach but I'm not sure if there's some edge cases where we may want an early break.

Edit: agreed to leave as is

@andy9775 andy9775 force-pushed the cdk-overlay-outside-click branch from 0949dba to 0ff7434 Compare July 7, 2020 16:40

overlayRef.attach(new ComponentPortal(TestComponent));
button.parentNode!.removeChild(button);
overlayRef.dispose();

Choose a reason for hiding this comment

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

Should these disposals happen in an afterEach() block, so they happen even if the test fails?

Copy link
Member

Choose a reason for hiding this comment

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

Slightly tricky because different tests create a different number of overlays; it would probably be better to de-dupe the dispose calls, but I wouldn't hold up the PR on it since it was already like this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teflonwaffles I agree that it should be cleaned up, but I opted to keep with the structure of the existing tests rather than polluting this PR with a test refactor.

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


overlayRef.attach(new ComponentPortal(TestComponent));
button.parentNode!.removeChild(button);
overlayRef.dispose();
Copy link
Member

Choose a reason for hiding this comment

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

Slightly tricky because different tests create a different number of overlays; it would probably be better to de-dupe the dispose calls, but I wouldn't hold up the PR on it since it was already like this

@jelbourn jelbourn added lgtm action: merge The PR is ready for merge by the caretaker P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release labels Jul 7, 2020
@jelbourn
Copy link
Member

jelbourn commented Jul 8, 2020

@googlebot ping

@andy9775 andy9775 force-pushed the cdk-overlay-outside-click branch from 0ff7434 to 8aae895 Compare July 28, 2020 14:05
@andy9775 andy9775 requested a review from a team as a code owner July 28, 2020 14:05
@andy9775 andy9775 force-pushed the cdk-overlay-outside-click branch 2 times, most recently from afc8141 to 236c2e1 Compare July 28, 2020 14:19
…om outside clicks

This removes the ability to track excluded elements from the overlay and only stops outside
click event notifications if the click event occurred within an overlay element itself. The
overlay should not track elements to be excluded from outside click - this should be up
to the developer. This allows for custom closeout logic to be implemented by the developer leaving
the cdk to be unopinionated.
@andy9775 andy9775 force-pushed the cdk-overlay-outside-click branch from 236c2e1 to f824928 Compare July 28, 2020 14:30
@jelbourn jelbourn merged commit 1565fa3 into angular:master Jul 29, 2020
@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 Aug 29, 2020
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 P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants