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

feat: Nest modal support #14320

Merged
merged 17 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const ComposedModal = React.forwardRef<HTMLDivElement, ComposedModalProps>(
const startSentinel = useRef<HTMLButtonElement>(null);
const endSentinel = useRef<HTMLButtonElement>(null);

// Kepp track of modal open/close state
// Keep track of modal open/close state
// and propagate it to the document.body
useEffect(() => {
if (open !== wasOpen) {
Expand All @@ -259,13 +259,15 @@ const ComposedModal = React.forwardRef<HTMLDivElement, ComposedModalProps>(
}, []); // eslint-disable-line react-hooks/exhaustive-deps

function handleKeyDown(evt: KeyboardEvent) {
evt.stopPropagation();
if (match(evt, keys.Escape)) {
closeModal(evt);
}

onKeyDown?.(evt);
}
function handleMousedown(evt: MouseEvent) {
evt.stopPropagation();
const isInside = innerModal.current?.contains(evt.target as Node);
if (!isInside && !preventCloseOnClickOutside) {
closeModal(evt);
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const Modal = React.forwardRef(function Modal(
}

function handleKeyDown(evt: React.KeyboardEvent<HTMLDivElement>) {
evt.stopPropagation();
if (open) {
if (match(evt, keys.Escape)) {
onRequestClose(evt);
Expand All @@ -295,6 +296,7 @@ const Modal = React.forwardRef(function Modal(

function handleMousedown(evt: React.MouseEvent<HTMLDivElement>) {
const target = evt.target as Node;
evt.stopPropagation();
if (
innerModal.current &&
!innerModal.current.contains(target) &&
Expand Down
Loading