-
Notifications
You must be signed in to change notification settings - Fork 38
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
expose show()
/close()
methods via Dialog.useInstance()
#1983
base: main
Are you sure you want to change the base?
Conversation
022f304
to
5021dba
Compare
5021dba
to
d8a858c
Compare
instance.show()
and instance.close()
methods to Dialog
show()
/close()
methods via Dialog.useInstance()
Co-authored-by: Rohan Kadkol <[email protected]>
Co-authored-by: Rohan Kadkol <[email protected]>
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'm going to hold off on merging this one for now.
I'm working on adding similar apis to Modal
, Popover
, Tooltip
, DropdownMenu
and InformationPanel
. All of them should probably release together.
I'm also experimenting with an invoker-like declarative API for creating tight associations between dialogs/popovers and their triggers. For example:
const dialog = Dialog.useInstance();
<Button invoketarget={dialog}>Open</Button>
<Dialog instance={dialog}>
<Button invoketarget={dialog}>Close</Button>
</Dialog>
If we want to release things faster without leaving PRs open for long times, maybe we should mark these new APIs as "alpha" or "unstable".
Changes
This adds two new API surfaces to
Dialog
:useInstance
hook containingshow()
/close()
methods for imperative manipulation of dialog.instance
prop which accepts an instance returned from the above hook.Together, this makes it easier to control the dialog without explicitly maintaining its state.
Supersedes #1976
Usage:
The implementation is quite simple:
useInstance
will create an instance ofInstance
, anduseSynchronizeInstance
will simply add methods to it. The instance stays referentially stable throughout its lifetime.Testing
Added unit test and e2e test, updated stories, updated website examples.
Docs
Added docs + jsdocs + changeset.