melt-ui
melt-ui copied to clipboard
🌟Feature request: Expose `handleClose` & `activeTrigger` from `createDialog`
To improve extensibility, it would be nice to expose some functions/properties.
For example, the handleClose
function of createDialog
can be very useful when you want to manage the closing of a modal in a way that is not expected by melt-ui
, but while taking advantage of focus management during closure.
Same with the activeTrigger variable of createDialog
.
Additional context For example, I have a dialog with inputs. I want to have fine management of when I close the modal (when the user validates the input with Enter, and after having done some verification on the server, I close the dialog).
Today I cannot easily restore focus to the trigger that opened the dialog. Since I don't have access to activeTrigger
, nor handleClose
Describe alternatives you've considered
In the case of createDialog, we could have, as in other builders, helpers.
- helpers.handleOpen
- helpers.handleClose
And add activeTrigger
in the states.
Thank you for your library, it's very good quality work, and very pleasant to use
How do we want to approach this @TGlide?
handleClose
is simple to expose.
handleOpen
is a bit different since it's used as an event handler and sets the activeTrigger
to the event's currentTarget
.
I think it's a good idea to expose both, we just have to ensure that bit is documented.
Let's say we expose these two functions, what would the use-case then be to return the activeTrigger
as part of states
?
what would the use-case then be to return the activeTrigger as part of states
To set it when doing handleOpen, I assume.
Alternatively, we can use effects and trigger the open and close side-effects when doing so, and just expose activeTrigger
so that it can be modified. Or not expose it, since we have openFocus
and closeFocus
do we actually need to expose all these additional things? It seems from the example provided that instead of focusing the trigger in handleClose
, we should focus the trigger in effect(open)
when open is false
(and make sure to skip the first mount).