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

Keep the modal state unchanged during the close animation #100

Merged
merged 3 commits into from
May 29, 2024

Conversation

DuncanMackintosh
Copy link
Contributor

I couldn't get Storybook 6 to run when I first cloned the repo, and it seemed easier to upgrade to the latest version than struggle to work out what was going wrong. Obviously if you've got a reason for keeping it at the previous reason (or just don't like the way I refactored the stories) then feel free to cherry-pick out only the bugfix commit.

The actual bug fix is fairly simple, just adding an 'open' flag to the state object and setting that to false rather than nulling the whole state when closing the dialog.

Update dependencies, convert config to new formats, convert stories to CSF.

Also added a story for "close on parent unmount".
Using "state == null" to indicate "not open" means that during the fade-out
transition the options all revert to defaults, so you see a brief flash of the
default title/content.

Switched to using an explicit 'open' flag within state, so the options are
preserved during the close transition. State will still be null before the first
dialog is opened, but otherwise will retain the last options used.
@jonatanklosko
Copy link
Owner

jonatanklosko commented May 29, 2024

Thanks for the PR! Let's have options as a separate state:

// Note that we don't reset options on close, so that we render
// the same modal during close animation
const [options, setOptions] = useState({});

It was like this initially, and I am pretty sure exactly for this reason, but I forgot about it during refactoring.

The other state is grouped, such that we can set it to null and no longer keep references to unnecessary data (mostly resolve/reject though).

@DuncanMackintosh
Copy link
Contributor Author

That makes a lot of sense. Do you want me to update my PR or have you already started on fixing it yourself?

@jonatanklosko
Copy link
Owner

@DuncanMackintosh please go ahead and update the PR :)

Clear the state immediately to avoid dangling references to resolve/reject, but
keep the options separate (and untouched) so the dialog appearance stays the
same during the close animation.
@jonatanklosko jonatanklosko changed the title Fix for #99, also upgrading Storybook Keep the modal state unchanged during the close animation May 29, 2024
@jonatanklosko jonatanklosko merged commit 926809a into jonatanklosko:master May 29, 2024
1 of 2 checks passed
@jonatanklosko
Copy link
Owner

Thanks!

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.

2 participants