Shopify / polaris

Shopify’s design system to help us work together to build a great experience for all of our merchants.
https://polaris.shopify.com
Other
5.71k stars 1.17k forks source link

Modal does not return focus to activator when activator is ref to focusable item itself #7638

Open danloomer opened 1 year ago

danloomer commented 1 year ago

Issue summary

When you pass a RefObject to the Modal component's activator prop and that RefObject points to the focusable activator itself (rather than a container) the focus will not be applied when the modal closes.

The root cause seems to be that the focusFirstFocusableNode utility we use to achieve the focus has an optional descedentsOnly argument which defaults to true.

Expected behavior

Focus should return to the activator even when the ref passed is to the focusable element itself.

Actual behavior

It does not focus the activator.

Specifications

  Binaries:
    Node: 16.18.0 - /usr/local/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/bin/watchman
  npmPackages:
    @shopify/polaris: 10.10.1 => 10.10.1 
    react: ^18.2.0 => 18.2.0 
    react-dom: ^18.2.0 => 18.2.0 
github-actions[bot] commented 1 year ago

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] commented 5 months ago

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.