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.78k stars 1.17k forks source link

Popover does not refocus onto activator after close #12249

Closed kellydanma closed 2 months ago

kellydanma commented 3 months ago

Summary

According to our docs:

When the popover is closed, focus returns to the element that launched it

I tried testing this out and it is not the case when the popover closes... unless I'm misinterpreting the docs somewhere? I'm not sure if this is working as intended or is a bug, to be honest. Happy to log an issue if it's undesired behaviour, and work on it too 🙏

13-31-vm9av-v8il0

Expected behavior

I was expecting focus to return to the button "More actions" once the popover closed.

Actual behavior

Instead, focus is lost and restarts at the beginning of the page.

Steps to reproduce

🔗 See sandbox

Are you using React components?

Yes

Polaris version number

latest

Browser

Chrome

Device

MacOS

kellydanma commented 3 months ago

From Slack discussion with @AndrewMusgrave:

Ohhhhhh! I took a look at the example, Polaris will only manage focus when they close the popover. If we close it ourselves (e.g. action list action), that'll be on us to manage focus

https://github.com/Shopify/polaris/blob/d87e976c36230b4e9256bc23fd542cffd1b62ccf/polaris-react/src/components/Popover/Popover.tsx#L153