-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add DialogContainer component to support controlled dialogs #1082
Conversation
Build successful! 🎉 |
@@ -37,7 +37,7 @@ const Context = React.createContext<ModalContext | null>(null); | |||
export function ModalProvider(props: ModalProviderProps) { | |||
let {children} = props; | |||
let parent = useContext(Context); | |||
let [modalCount, setModalCount] = useState(parent ? parent.modalCount : 0); | |||
let [modalCount, setModalCount] = useState(0); |
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.
This fixes the issue with aria-hidden
on an open dialog that came up before. I believe this logic was simply incorrect: each ModalProvider keeps track of the number of modals open in its subtree, but this seems to store a count of all open modals. 🤷
@@ -35,7 +36,16 @@ describe('DialogTrigger', function () { | |||
}); | |||
|
|||
afterEach(() => { | |||
jest.runAllTimers(); | |||
// Ensure we close any dialogs before unmounting to avoid warning. | |||
let dialog = document.querySelector('[role="dialog"]'); |
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.
could probably use screen.getByRole('dialog')
instead
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.
what is screen? Any benefits or about the same?
Build successful! 🎉 |
Closes #966. Closes #1039.
Based on learnings from #965, this implements a
DialogContainer
component that can be used in cases where there is no trigger element, or when the trigger may unmount while the dialog is open (e.g. a menu item). AuseDialogContainer
hook is also added to allow custom dialog components to dismiss the dialog programmatically without manually passing through anonDismiss
function.In addition, this adds a warning when a
DialogTrigger
detects that it is unmounted while a modal is open, suggesting the use ofDialogContainer
instead.See the docs and updates to the Table CRUD example for details on the API.