Skip to content
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

Merged
merged 3 commits into from
Sep 29, 2020

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented Sep 22, 2020

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). A useDialogContainer hook is also added to allow custom dialog components to dismiss the dialog programmatically without manually passing through an onDismiss function.

In addition, this adds a warning when a DialogTrigger detects that it is unmounted while a modal is open, suggesting the use of DialogContainer instead.

See the docs and updates to the Table CRUD example for details on the API.

@adobe-bot
Copy link

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);
Copy link
Member Author

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"]');
Copy link
Member

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

Copy link
Member

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?

@adobe-bot
Copy link

Build successful! 🎉

@dannify dannify merged commit 3385b6d into main Sep 29, 2020
@dannify dannify deleted the dialogcontainer branch September 29, 2020 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better support for controlled DialogTrigger Support DialogTriggers from menus
4 participants