polaris icon indicating copy to clipboard operation
polaris copied to clipboard

AutoComplete component does not permit programatic focus override via wrapped Listbox

Open maxariss opened this issue 3 years ago • 1 comments

Issue summary

There is a disconnect between a user's selected option index within an <AutoComplete />'s <ListBox /> and the matched value input within <ComboBox />. Essentially, if you have an ordered array of default options passed to the <AutoComplete /> (ie. Size, Color, Material, Style) and you manually type out one of those options into the <ComboBox />'s text input (ie. Color), the focus state should (at least be able to) shift to the matching option.

Expected behaviour

The <ListBox />'s focused option should ideally shift to the matched value from the <ComboBox /> input. If we decide this shouldn't be the default, we should at least be able to programatically shift the focus of the <ListBox /> options. I could see us doing this a few ways:

a. automatically shift focus to the matched input between <ComboBox /> and <ListBox /> b. add a some flavour of a focusedOption or focusedIndex prop to <AutoComplete /> c. add a listBox prop to <AutoComplete /> allowing the user to override the default implementation (like we do with textField)

Actual behaviour

If you have an <Autocomplete /> with the default options of Size, Color, Material, Style, and you type out Material in the text field, and then hit the ENTER key, even though the Material field is visibly selected / given a highlighted style, it's in fact the Size option that get's submitted, because no change in focus gets accounted for when the <ComboBox /> text input matches a <ListBox /> option.

Steps to reproduce the problem

  1. In Shopify admin, open up a product page with variants
  2. Click on Add another option, and type out Material (this input is case-sensitive)
  3. See that Material becomes visually selected in the <ListBox />
  4. Hit ENTER on your keyboard
  5. Notice that Size get's selected (the first <ListBox /> option with focus) instead of Material

Screenshot

autocomplete focus issue

Specifications

  • Are you using the React components? (Y/N): Yes
  • Polaris version number: Latest
  • Browser: Chrome
  • Device: M1
  • Operating System: OSX

maxariss avatar Feb 10 '23 22:02 maxariss

Hi! We noticed there hasn’t been activity on this issue in a while. After 30 days, it will close automatically.

If it’s still relevant, or you have updates, comment and let us know. And don’t worry, you can always re-open later if needed.

github-actions[bot] avatar Aug 13 '23 03:08 github-actions[bot]