Add close through a child function to dialogs#234
Conversation
…en used with a fresh install
move isDismissable to by default be on the context
Codecov Report
@@ Coverage Diff @@
## master #234 +/- ##
========================================
Coverage ? 71.2%
========================================
Files ? 206
Lines ? 3966
Branches ? 844
========================================
Hits ? 2824
Misses ? 570
Partials ? 572
|
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
| return ( | ||
| <Modal isOpen={isOpen} onClose={onClose}> | ||
| {content} | ||
| {typeof content === 'function' ? content(onClose) : content} |
There was a problem hiding this comment.
I'm not a fan of asking the people who create modals to write (onClose) => {<content><Button onPress={close}>Close</Button></content>}. It feels like we're asking them to write jsx that isn't just elements.
The first idea I thought of was a modal context to pass the onClose to button children which is also problematic, but it doesn't make the end user jump through any weird hoops.
I'm concerned that this will be a support issue of us having to train everyone to write things this way.
There was a problem hiding this comment.
This is a pretty common React pattern called 'Function as children' so it shouldn't be hard to understand.
This should also be documentable via our prop tables.
There isn't really a great way to do this via context without creating <DialogButton or something equivalent that can pick up a different context than the slots and knows which of the three (four) possible buttons it is.
We went through many options before arriving at this one. I think Devon might have it written down.
| expect(onCancelSpy).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('renders alert dialog with onConfirm / onCancel', function () { |
There was a problem hiding this comment.
this has the same test description as the previous test, renders alert dialog with onConfirm / onCancel.
Also, why aren't we checking what onConfirmSpy was called with in the previous test and onCancelSpy in this test so we do see that things are different?
|
Build successful! 🎉 |
LFDanLu
left a comment
There was a problem hiding this comment.
Just a single question, otherwise just waiting for the removal of the dupe tests that Kyle noted
…rum-v3 into function-as-a-child-dialog-triggers
|
Build successful! 🎉 |
|
Build successful! 🎉 |
…rum-v3 into function-as-a-child-dialog-triggers
Popover, tray, tooltip, etc should all still be dismissible by outside interaction click
|
Build successful! 🎉 |
…rum-v3 into function-as-a-child-dialog-triggers
|
Build successful! 🎉 |
| function Test({defaultOpen, onOpenChange}) { | ||
| return ( | ||
| <Provider theme={theme}> | ||
| <DialogTrigger type="popover" defaultOpen={defaultOpen} onOpenChange={onOpenChange}> |
There was a problem hiding this comment.
Shouldn't this example have isDismissable on it?
There was a problem hiding this comment.
Oh ya lemme add isDismissable=false here
|
Build successful! 🎉 |
| return ( | ||
| <Tray isOpen={isOpen} onClose={onClose}> | ||
| {content} | ||
| {typeof content === 'function' ? content(onClose) : content} |
There was a problem hiding this comment.
hmm... thought tray's couldn't have the buttons? I'm fine to just have it all done the same though, seems useful
|
Build successful! 🎉 |
devongovett
left a comment
There was a problem hiding this comment.
Can we handle this automatically for AlertDialog via context so you don't need to wrap it in a close function yourself?
| isDismissable?: boolean | ||
| } | ||
|
|
||
| export interface SpectrumDialogTriggerBase { |
There was a problem hiding this comment.
Move this into react-spectrum. It isn't a public component.
| isOpen?: boolean | ||
| isOpen?: boolean, | ||
| // Whether to close overlay if underlay is clicked | ||
| closeOnInteractOutside?: boolean |
There was a problem hiding this comment.
Can we call this isDismissible and default it to false for consistency?
|
Build successful! 🎉 |
|
Build successful! 🎉 |
Closes https://jira.corp.adobe.com/browse/RSP-1533 and https://jira.corp.adobe.com/browse/RSP-1548. Additionally changes the logic for isDismissable modal dialogs so that they can be closed by clicking outside the dialog. Non-dismissable modal dialogs cannot be closed by clicking outside the dialog. Popovers and tray should still always be closable via outside click.
✅ Pull Request Checklist:
📝 Test Instructions:
Test that the dialog/dialogTrigger stories are all closable via escape, cancel/confirm buttons. Confirm that isDismissable modal dialogs, popover, and tray dialogs can be closed by clicking outside of the dialog. Confirm that normal modal dialogs cannot.
🧢 Your Team: