Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Allow to exclude all child elements of an element #71

Open
LexLuengas opened this issue Nov 21, 2020 · 4 comments
Open

Allow to exclude all child elements of an element #71

LexLuengas opened this issue Nov 21, 2020 · 4 comments

Comments

@LexLuengas
Copy link

Say we have the structure <div class="ancestor"><div class="descendant"></div></div>.

When using [exclude]="'.ancestor'", only elements with the class "ancestor" are excluded from the clickOutside event handler. Child elements are not excluded, so clicking on the ".descendant" element would cause clickOutside to emit.

I would like to exclude the elements matching the selector, as well as all descendant elements. For this I would propose to use a new input property excludeDescendants of boolean type. When true, the elements specified in exclude as well as all their descendants are excluded from the clickOutside event.

Not sure if excludeDescendants should also default to true, because I think most use cases for clickOutside would want to consider descendants when excluding elements anyway. In that case, I would consider to just change the behavior of exclude.

@LexLuengas
Copy link
Author

Would make sense to use Element.closest() (https://developer.mozilla.org/en-US/docs/Web/API/Element/closest), because it also returns the element itself when it matches the selector.

@arkon
Copy link
Owner

arkon commented Nov 21, 2020

Why not just make the selector include children?

@LexLuengas
Copy link
Author

You mean why not use [exclude]="'.ancestor,.descendant'"? The example was oversimplifying. In my actual use case, I want to exclude a dropdown that is injected by a library. The dropdown has quite a few dynamically added children, which is why it would be easier and less verbose to use [exclude]="'.dropdown'" and have it exclude all descendants as well.

@arkon
Copy link
Owner

arkon commented Nov 22, 2020

I mean something like .ancestor *.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants