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

ClickAwayListener for Focus? #45047

Closed
Matt-Butler opened this issue Jan 17, 2025 · 6 comments
Closed

ClickAwayListener for Focus? #45047

Matt-Butler opened this issue Jan 17, 2025 · 6 comments
Assignees
Labels
support: question Community support but can be turned into an improvement

Comments

@Matt-Butler
Copy link

Matt-Butler commented Jan 17, 2025

Summary

Hey there!

I was wondering if there's something similar to the ClickAwayListener but for focus events. I'm building a custom input with a Popper, and I want to close it when a user tabs out. For clicks, the ClickAwayListener works perfectly, but it would be great if it also handled tabbing away. Does something like this exist?

Thank you for your time!

Examples

No response

Motivation

No response

Search keywords: ClickAwayListener

@Matt-Butler Matt-Butler added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 17, 2025
@DiegoAndai DiegoAndai added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 17, 2025
@DiegoAndai
Copy link
Member

Hey, @Matt-Butler, thanks for reaching out. Have you tried using the blur event (onBlur)? https://developer.mozilla.org/en-US/docs/Web/API/Element/blur_event

@DiegoAndai DiegoAndai self-assigned this Jan 17, 2025
@Matt-Butler
Copy link
Author

Matt-Butler commented Jan 17, 2025

Thanks for the recommendation @DiegoAndai

Here is more context. I am building a custom multi select tree. I'm using the Popper component. I think this behavior might be fairly similar to the autocomplete component.

Screen.Recording.2025-01-17.at.10.07.48.AM.mov

I'm probably missing something simple.

@DiegoAndai
Copy link
Member

I'm probably missing something simple.

onBlur is what I would use.

@DiegoAndai DiegoAndai added the status: waiting for author Issue with insufficient information label Jan 17, 2025
@Matt-Butler
Copy link
Author

This is what ended up working for me:
onBlur={(e) => e.relatedTarget === null && myMethod()}

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jan 17, 2025
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@Matt-Butler How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@Matt-Butler
Copy link
Author

Thanks @DiegoAndai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

2 participants