-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
AutocompleteUI: Close popup when click happens outside of the popover. #44795
Conversation
Size Change: +81 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
35b198b
to
13f4944
Compare
Will fix the linting issues and investigate the failed e2e tests this weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this, @BE-Webdesign !
Cc'ing @jasmussen and @jameskoster in case they have any feedback, UX-wise.
Also:
- should we add tests ?
- we'll need to add a CHANGELOG entry before merging.
useOnClickOutside( popoverRef, () => { | ||
reset(); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're currently passing a new function every render, meaning that the useEffect
inside useOnClickOutside
will re-run every time.
Instead, we could either:
- pass
reset
directly:useOnClickOutside( popoverRef, reset )
- extract the callback as a separate variable and wrap in in
useCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing reset
directly sounds good. I think I accidentally left it this way when I was doing some testing with console.log in the callback.
@@ -63,6 +70,7 @@ export function getAutoCompleterUI( autocompleter ) { | |||
id={ listBoxId } | |||
role="listbox" | |||
className="components-autocomplete__results" | |||
ref={ popoverRef } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this ref
be applied to the Popover
component, instead of this div
? Currently, clicking on the "padding" of the popover closes the autocomplete list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. I think the ref is already forwarded in Popover
, so that should work fine.
It makes sense to me and seems to be working well. Before before.mp4After after.mp4 |
Cool! I'll have a final round of review once all feedback gets addressed.
When setting up unit tests for this component, you can refer to other components (e.g. Actually, there's a chance that adding unit tests to this component may prove difficult (cc @chad1008 who previously resorted to e2e tests instead) — let us know in case you don't manage and what obstacles you met. Thanks! 🙏 |
@ciampo Changes made, and tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! 🚀
Thank you so much for working on this!
I went ahead and solved CHANGELOG conflicts — I will merge as soon as CI is ✅
5ad5f25
to
e7da9fb
Compare
PHP unit test failures are not related — we will need to rebase after #45254 is fixed |
…. This prevents the popover from appearing above UI elements like the Patterns Explore Modal window.
Co-authored-by: Marco Ciampini <[email protected]>
Co-authored-by: Marco Ciampini <[email protected]>
…a new function on render.
e7da9fb
to
fd6a3ae
Compare
Fixes #44767.
What?
This prevents the popover from appearing above UI elements like the Patterns Explore Modal window.
Why?
When the AutocompleteUI component renders, you can open the explorer for patterns modal window while the AutocompleteUI is still rendered. I don't believe the z-index for CSS should be changed as the modal windows need to appear below WordPress admin elements, where as the popover will be ontop of those.
How?
Adds a handler that looks for when the user clicks outside of the popover and closes the popover.
Testing Instructions
/
to open the autocomplete popover for inserting a block.