Visitar URL original
USWDS - Combo box search results by kodyjackson · Pull Request #6074 · uswds/uswds · GitHub
Skip to content

USWDS - Combo box search results - #6074

Closed
kodyjackson wants to merge 6 commits into
uswds:developfrom
kodyjackson:kj-combo-box-search-results
Closed

kodyjackson wants to merge 6 commits into
uswds:developfrom
kodyjackson:kj-combo-box-search-results

Conversation

@kodyjackson

@kodyjackson kodyjackson commented Sep 20, 2024 •

Copy link
Copy Markdown
Contributor

Summary

Implement First Letter Navigation for Combo Box Filtering

Breaking change

No breaking change

Related issue

Closes #5647

Problem statement

Users interacting with the combo box for selecting states or countries expect intuitive behavior where typing the first letter of an option narrows down the results to only those that begin with that letter. Currently, the combo box shows all results containing the typed letter, leading to confusion, as options like "Connecticut" appear when users type "T." This does not align with user expectations and can hinder the overall usability of the component.

Solution

The solution implements first letter navigation in the combo box's filtering logic. By modifying the generateDynamicRegExp function, we ensure that only the options starting with the typed letter are displayed, providing a more accurate and user-friendly experience.

Major changes

  1. Modification of generateDynamicRegExp Function:

    • Updated the regex generation to anchor matches to the start of the string, ensuring that only options beginning with the input character(s) are returned.
    • Adjusted the logic to prioritize first-letter matches over partial matches.
  2. Testing Enhancements:

    • Added new test cases to validate the updated behavior, ensuring that typing a letter displays only options starting with that letter.
    • Ensured backward compatibility by retaining existing functionalities while focusing on first-letter navigation.

@mejiaj mejiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kodyjackson thanks for creating this. Left a question on time picker and can you double-check tests and prettier:check passes?

@@ -1,7 +1,35 @@
const assert = require("assert");
const { generateDynamicRegExp } = require("../../../usa-combo-box/src/index");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kodyjackson the component still relies on combo box. Is there a particular reason why we removed this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time-picker relied on an earlier version of generateDynamicRegExp, which matched strings by checking if any character from the list was present. The updated version, however, creates a regular expression that matches the starting characters of the list elements with the search query.

@jaclinec

Copy link
Copy Markdown

Considering findings and recommendations from the combo box landscape analysis 🔒 done earlier this year and conversations in CS UX sync from last April, it looks like we decided to try implementing a combo box solution similar to Elastic UI's where first letter navigation is prioritized, but that it also returns results with characters contained in the search terms. Kind of a "best of both worlds."

Elastic UI example:
Image

@mejiaj

mejiaj commented Oct 30, 2024

Copy link
Copy Markdown
Contributor

Closing in favor of #6122.

@mejiaj mejiaj closed this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combo box search results do not match user expectations

3 participants