fix: prevent redirect on dropdown item clicks#627
Conversation
DropdownItem is an anchor element with href="#". In the VLE in Storm, if the DropdownItem is clicked tries to redirect to a different page and causes the Locator component to get frozen. By preventing the default redirect behavior we can avoid this bug.
|
Current unit coverage is 89.67687788501888% |
There was a problem hiding this comment.
Pull request overview
Fixes a UI bug where clicking a DropdownItem (rendered as an <a href="#">) can trigger an unintended navigation/redirect in the Storm VLE, freezing the Locator component.
Changes:
- Prevent default anchor navigation on
DropdownItemclick by callinge.preventDefault(). - Update
test-sitelockfile to reference@yext/search-ui-reactversion2.0.4. - Minor formatting/whitespace adjustments in the test-site
LocationsPage.
Reviewed changes
Copilot reviewed 1 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/components/Dropdown/DropdownItem.tsx |
Prevents default anchor click behavior to avoid redirect/navigation side effects. |
test-site/package-lock.json |
Updates the linked workspace package version to 2.0.4. |
test-site/src/pages/LocationsPage.tsx |
Minor formatting-only changes. |
Files not reviewed (1)
- test-site/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Just to confirm, does this change any actual behavior with regular experiences? |
I've changed the approach since this comment, but feel it's still worth answering. The following changes apply at large:
I also updated the test-site LocationsPage to make the dropdown background red so that it's easier to see if the focusing & hovering behavior diverges. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 7 changed files in this pull request and generated 2 comments.
Files not reviewed (1)
- test-site/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Upon further consideration, I removed change (3) from my previous comment to avoid changing existing behavior. Hovering will always apply |
k-gerner
left a comment
There was a problem hiding this comment.
Based off of the snapshot diffs, it looks like the "selected" item is not showing as having a grey background
Ah whoops, I was viewing in "Onion Skin" mode and got them flipped |


The DropdownItem component currently uses an anchor element with href="#". In the VLE in Storm, if the DropdownItem is clicked, the page tries to call another endpoint, causing the Locator component to get frozen (relevant slack thread).
This change converts the DropdownItem component from an
aelement to abuttonelement. This is in line with best practices, asashould only be used for navigation to a real URL rather than triggering JS.This PR also aligns handling for focusing and for hovering over dropdown results. Note that focusing happens by toggling different results with arrow keys, whereas hovering happens by moving the mouse on top of results. We want styling changes to be the same for focusing and hovering.
https://yext.atlassian.net/browse/WAT-5384
Before:https://jam.dev/c/51ec9a97-bf37-485f-a6a1-14b8c98e7a76 (note that CSS is not changing properly when focusing on different results)
After:https://jam.dev/c/92938750-9cb1-46d0-9b60-f12d9c9984e6