Skip to content

useSelect doesn't return focus to toggle button after selection with VoiceOver on iOSΒ #1664

@brbintenyears

Description

@brbintenyears

Steps to reproduce:

  1. On an iOS device, go to the example in the docs at https://www.downshift-js.com/use-select#basic-usage
  2. Enable VoiceOver.
  3. Toggle the select and make a selection

Expected result:
After a selection is made, the focus should return back to the toggle.

Actual result:
Focus lands on whatever happens to be underneath the selected item.

Here's a screen recording of the bug.

downshiftjs_useSelect_bug.MP4

I attempted to mitigate this in my implementation by setting a ref on the toggle button and then sending the focus back to the toggle after a selection is made with variations of the following, but no such luck. At first I thought it was a problem with my implementation, but when I checked the example in the docs I found the problem reproducible on there as well.

const toggleRef = useRef<HTMLDivElement>(null);
  
const { /* ... */ } =
  useSelect({
    // ...
    onSelectedItemChange: () => toggleRef?.current?.focus(),
  });
}

return (
    //...
    <div
      className="p-2 bg-white flex justify-between cursor-pointer"
      {...getToggleButtonProps({ ref: toggleRef })}
    >
        // ...
    </div>
    //...
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions