Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dialog,popover): restore focus when open set to false #1110

Merged

Conversation

anatolzak
Copy link
Contributor

closes #1109

We now restore focus to the trigger (or using the closeFocus prop) in an effect that runs when open is false. In order to not focus the trigger on initial mount when open is false, I added a parameter skipFirstRun to the effect function that optionally skips the first run of the effect.

I also added regression tests for the dialog and popover.

Also, in the menu builder, we are already doing what I implemented with the dialog and popover, which removes the need in the menu builder to manually focus the trigger in multiple places. And I cleaned up the effect in the menu component.

Dialog Before

Screen.Recording.2024-03-20.at.1.58.50.PM.mov

Dialog After

Screen.Recording.2024-03-20.at.1.59.18.PM.mov

Popover Before

Screen.Recording.2024-03-20.at.1.41.15.PM.mov

Popover After

Screen.Recording.2024-03-20.at.1.42.38.PM.mov

Copy link

changeset-bot bot commented Mar 20, 2024

🦋 Changeset detected

Latest commit: d58ea38

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@melt-ui/svelte Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@huntabyte huntabyte left a comment

Choose a reason for hiding this comment

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

Minor thing! Thanks man!

src/lib/internal/helpers/store/effect.ts Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Mar 21, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
melt-ui ✅ Ready (View Log) Visit Preview d58ea38

@anatolzak
Copy link
Contributor Author

@huntabyte I added an options parameter to effect as you requested!

Copy link
Member

@huntabyte huntabyte left a comment

Choose a reason for hiding this comment

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

Thank you!

@huntabyte huntabyte changed the title Fix(dialog, popover) restore focus when manually setting open to false fix(dialog,popover): restore focus when open set to false Mar 28, 2024
@huntabyte huntabyte merged commit 6de1c7f into melt-ui:develop Mar 28, 2024
6 checks passed
@github-actions github-actions bot mentioned this pull request Mar 28, 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.

[Dialog, Popover] manually setting open to false does not restore focus to trigger
2 participants