-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix search type popover has 2 items highlighted #53330
Merged
cristipaval
merged 10 commits into
Expensify:main
from
bernhardoj:fix/50224-search-type-popover-has-2-items-highlighted
Dec 4, 2024
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc8a2db
update the focused index whilet the popover is hidden if the selected…
bernhardoj bf580a2
reset the focused index to the selected item if any when the popover …
bernhardoj 5bad35f
lint
bernhardoj c564f3c
add comment
bernhardoj 95803fa
update comment
bernhardoj dddbed1
Merge branch 'main' into fix/50224-search-type-popover-has-2-items-hi…
bernhardoj 539ca23
simplify code
bernhardoj 30ff2ca
lint
bernhardoj e5ba8d8
lint
bernhardoj 11ba377
move comment
bernhardoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
currentMenuItemsFocusedIndex
is changed due to the change incurrentMenuItems
which is due to the callsetCurrentMenuItems(menuItems)
that is done in the aboveuseLayoutEffect
. This is a known change and not a side effect and it should be done as soon as possible, i.e. callsetFocusedIndex
right aftersetCurrentMenuItems
.Note: Keep the isVisible condition but add a comment that we don't want the focus index to change if we dynamically change the items e.g.
If we have:
then the selected item is changed (externally), the result should be as follow:
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.
Added comment with the help from ChatGPT.
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.
Can you move the setFocusedIndex call as well
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.
Sorry, move to where? And why? I don't quite understand your first comment actually 😅
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.
Move it to the above useLayoutEffect
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.
Oh, I get what you're trying to say now. But if we do that, then we shouldn't add isVisible to the useLayoutEffect deps right?
Also, I don't think this would work. Why? When we call
setCurrentMenuItems(menuItems);
,currentMenuItemsFocusedIndex
is not updated yet, so callingsetFocusedIndex(currentMenuItemsFocusedIndex);
right after it won't work. It'll be updated correctly after the 2nd trigger ofuseLayoutEffect
.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.
Right. I don't think this is needed or wanted.
Remove the
currentMenuItemsFocusedIndex
const and just usemenuItems?.findIndex((option) => option.isSelected)
.This is one of the cases where a useEffect is not needed.
Bad:
Not as bad:
Good:
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.
In our case we are trying to move from Bad to Not as bad. value=menuItems, derivedValue=focusedIndex
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.
Got it now, updated