-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat: Add overlayAsync implementation #59
Conversation
🦋 Changeset detectedLatest commit: e91db62 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/src/event.test.tsx
Outdated
waitFor(() => { | ||
expect(dialogContentElement).not.toBeInTheDocument(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was odd that await
wasn't attached here.
I'll share my thoughts as I test it out. If I'm wrong, feel free to tell me. 🙇♂️
Test fails when await
is appended
I only added await
in the code you provided, so the test fails.
await waitFor(() => {
expect(dialogContentElement).not.toBeInTheDocument();
});
I think the reason the test passed without the await
is because the test inside the waitFor
works asynchronously, but the test function doesn't wait for it.
So if I don't add await
, I think I can write a test like this and it will pass.
waitFor(() => expect(dialogContentElement).toBeInTheDocument());
Why does it fail?
The next question is where the test fails when you add await
.
close
is not removed from the DOM
, so not.toBeInTheDocument()
seems appropriate with unmount
.
I can't think of a way to test the close
behavior right now. sorry. 😂
I'll have to think about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. It was my mistake to omit the "await" and the test would return a false positive.
Thank you for catching my mistake
The reason it fails is because "close" does not actually unmount the element, but rather changes the value of isOpen.
Therefore, I modified the code as follows:
const handleClick = async () => {
overlay.openAsync<boolean>(({ isOpen, close }) =>
// focus on isOpen
isOpen ? <button onClick={() => close(true)}>{dialogContent}</button> : null
);
};
...
await waitFor(() => {
expect(dialogContentElement).not.toBeInTheDocument();
});
This code allows the button to be unmounted from the screen based on the value of isOpen.
A commit that resolves the issue has been pushed to this PR.
Thank you for checking carefully. With your help I was able to find this problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! The code you provided looks good to me.
One concern I have is that we can’t resolve through overlay.close
. I plan to create a separate PR to add an option for this.
I am thinking of an API like overlay.close(overlayId, { resolve })
. If you have any opinions on this, please feel free to share.
Thanks again!
Description
This change implements the openAsync method for overly-kit's promise support discussed in #47.
Related Issue: Fixes #47
Changes
Motivation and Context
Although overlay-kit emphasizes support for promises in its documentation, there was a problem with boilerplate due to the lack of explicit support for promises.
To address this issue, we add openAsync explicit support for promises.
How Has This Been Tested?
I tested through test code that the parameters passed to openAsync's close method return resolved values, and that the close method properly closes the overlay on the screen.
Types of changes
Checklist
Further Comments
In order to adhere to the DRY principle and minimize modifications to existing code, openAsync was implemented in the form of wrapping open. Is this implementation acceptable?
The close method of openAsync is implemented to require parameters. The reason I implemented it this way is because if an optional parameter is allowed, type assertion through as is required internally, which makes it type-safe, or there is the inconvenience of the user having to infer undefind even though the confirmation value is actually passed. I also chose a type-safe implementation because we believed that the core of Promise use cases lies in using checked values. I'm curious about your opinion on this part.
Would it be a good idea to add docs for openAsync in that PR? If I had to add it, I would like to know which document it would be best to add it to. I am prepared when it comes to writing documents.