-
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
Web - Key Navigation -The search query is highlighted instead of the first result in the list #58057
Comments
Triggered auto assignment to @abekkala ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.When user search something in the searchRouter, the searchQuery gets highlighted, but the expected result is that the first item from the list should be highlighted. What is the root cause of that problem?In the SearchRouter component, when text is entered in the search box, the code calls updateAndScrollToFocusedIndex(0). This is setting focus to index 0, which corresponds to the search query item itself, not the first actual search result. The search results list includes both the search query (as a "find item") and the actual results, with the search query appearing first in the list. App/src/components/Search/SearchRouter/SearchRouter.tsx Lines 202 to 206 in 46ec589
What changes do you think we should make in order to solve the problem?We should update the onSearchQueryChange function in the SearchRouter component to focus on index 1 instead of index 0 when there's text in the input field. This will skip the search query item and directly focus on the first actual search result. if (updatedUserQuery || textInputValue.length > 0) {
listRef.current?.updateAndScrollToFocusedIndex(1);
} else {
listRef.current?.updateAndScrollToFocusedIndex(-1);
} What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?Test that when the search modal is opened and no text is entered, no item is highlighted What alternative solutions did you explore? (Optional)In case we want to highlight the searchQuery if there are not results in the suggested autocomplete list, then we can expose the App/src/components/SelectionList/BaseSelectionList.tsx Lines 785 to 788 in 46ec589
|
ProposalPlease re-state the problem that we are trying to solve in this issue.The search query is highlighted instead of the first result in the list What is the root cause of that problem?When we input a search value, regardless of whether the sessions have data or not, we still set the index to 0
Due to What changes do you think we should make in order to solve the problem?To resolve this issue, we simply compare
update to <SearchAutocompleteList
autocompleteQueryValue={autocompleteQueryValue || textInputValue}
searchQueryItem={searchQueryItem}
getAdditionalSections={getAdditionalSections}
onListItemPress={onListItemPress}
setTextQuery={setTextAndUpdateSelection}
updateAutocompleteSubstitutions={updateAutocompleteSubstitutions}
onHighlightFirstItem={() => listRef.current?.updateAndScrollToFocusedIndex(1)} // add this
ref={listRef}
/>
add: function SearchAutocompleteList(
{
autocompleteQueryValue,
searchQueryItem,
getAdditionalSections,
onListItemPress,
setTextQuery,
updateAutocompleteSubstitutions,
shouldSubscribeToArrowKeyEvents,
onHighlightFirstItem, // add this
}: SearchAutocompleteListProps,
ref: ForwardedRef<SelectionListHandle>,
) { 2 add function to compare `autocompleteQueryValue`` with the session item title. we able write it to utils. function checkTextMatch(sections, targetText = '') {
// Extract reference text safely and normalize case
const referenceText = sections?.[1]?.data?.[0]?.text?.toLowerCase() || '';
const normalizedTargetText = targetText.toLowerCase().trim();
// Reject single-letter targetText (avoids "t" matching "t's")
if (normalizedTargetText.length < 2) return false;
// Case 2: Ensure targetText is a valid word or valid full prefix (not a partial cut-off)
const regex = new RegExp(`\\b${normalizedTargetText}\\b`, 'i');
// Ensure targetText is not ending in a non-word character (e.g., ' @ #)
if (/[^a-zA-Z0-9]$/.test(normalizedTargetText)) return false;
return regex.test(referenceText);
}
useEffect(() => {
const isHighlightFirstItem = checkTextMatch(sections, autocompleteQueryValue);
if (isHighlightFirstItem) {
// ref.current?.updateAndScrollToFocusedIndex(1);
onHighlightFirstItem();
}
}, [autocompleteQueryValue, onHighlightFirstItem, ref, sections]); Test branchScreen.Recording.2025-03-10.at.23.19.00.mp4What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?we create unit test for Expected Matching Behavior
What alternative solutions did you explore? (Optional)Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.1.10-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/5651244&group_by=cases:section_id&group_order=asc&group_id=229066&group_by=cases:section_id&group_order=asc&group_id=229066
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team
Action Performed:
Preconditions: A personal account is created and the user is logged in
Expected Result:
The first result in the list should be highlighted
Actual Result:
The entered search query is highlighted instead of the first result in the list
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
Bug6762738_1741255211764.bandicam_2025-03-06_11-57-58-488.mp4
View all open jobs on GitHub
The text was updated successfully, but these errors were encountered: