isDismissable
and other properties are not working correctly on modal box
#4620
JHunnicutt
started this conversation in
General
Replies: 1 comment 3 replies
-
function ModalTrigger({
label,
children,
isDismissable,
...props
}: TriggerDefinitions) {
let state = useOverlayTriggerState(props);
let { triggerProps, overlayProps } = useOverlayTrigger(
{ type: "dialog" },
state
);
console.log(state.isOpen);
return (
<>
<Button {...triggerProps}>{label}</Button>
{state.isOpen && (
<Modal {...props} state={state}>
{cloneElement(children(state.close), overlayProps)}
</Modal>
)}
</>
);
} You can fix this by updating this: interface ModalDefinitions {
state: OverlayTriggerState;
children: React.ReactElement | React.ReactElement[];
isDismissable?: boolean;
} and passing function ModalTrigger({
label,
children,
isDismissable,
...props
}: TriggerDefinitions) {
let state = useOverlayTriggerState(props);
let { triggerProps, overlayProps } = useOverlayTrigger(
{ type: "dialog" },
state
);
console.log(state.isOpen);
return (
<>
<Button {...triggerProps}>{label}</Button>
{state.isOpen && (
<Modal {...props} isDismissable state={state}>
{cloneElement(children(state.close), overlayProps)}
</Modal>
)}
</>
);
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on some modal implementation using
useModalOverlay
. After some time getting it to work in a TypeScript environment, I've noticed that there a couple of things that don't function like the examples. First and foremost, the propertyisDismissable
isn't enabling my modal to close when the user clicks outside of it. Also, theesc
key doesn't close the modal at all.The docs are very confusing on the subject, as it states, "you can set
isDismissable
on the Modal" but then shows an example with the property on the trigger. I put mine on the trigger, as I gave more weight to the coding example.I have a couple of CodeSandboxes with some examples. The first one is in TypeScript and close to what I've created thus far. I've just used the examples as shown from the docs as a starting point. The second is essentially the same thing but in vanilla JavaScript. Notice how
isDismissable
doesn't work in the TS example, but it does in JS? Clicking theesc
key doesn't close the modal in either example, sadly. Why might this be?useModalOverlay - TypeScript
useModalOverlay - JavaScript
Beta Was this translation helpful? Give feedback.
All reactions