API reference
Hide results
Narrow the close reason to safely distinguish submitted data from cancellation.
Every show<T>() resolves to HideReturn<T>:
type HideReturn<T> =
| {
reason:
| MagicModalHideReason.BACKDROP_PRESS
| MagicModalHideReason.SWIPE_COMPLETE
| MagicModalHideReason.BACK_BUTTON_PRESS
| MagicModalHideReason.GLOBAL_HIDE_ALL;
}
| {
reason: MagicModalHideReason.INTENTIONAL_HIDE;
data: T;
};Check the reason before reading data:
const result = await magicModal.show<FormValues>(FormModal, {
accessibilityLabel: "Edit profile",
});
if (result.reason === MagicModalHideReason.INTENTIONAL_HIDE) {
await save(result.data);
}MagicModalHideReason
| Value | Trigger |
|---|---|
INTENTIONAL_HIDE | useMagicModal().hide(data) or magicModal.hide(data, options) |
BACKDROP_PRESS | The user presses the backdrop and the default handler closes |
BACK_BUTTON_PRESS | Android back, web Escape, or native accessibility escape closes |
SWIPE_COMPLETE | A dismiss gesture clears the velocity threshold |
GLOBAL_HIDE_ALL | magicModal.hideAll() clears the stack |
Cancellation results intentionally contain no data. This forces callers to handle dismissal
instead of treating it like a submitted value.
BACK_BUTTON_PRESS keeps its original enum name for compatibility. It is the shared system-dismiss
path across web and native runtimes.