From fb8b139a126ffa497431c14b24c1e45e0bac4d45 Mon Sep 17 00:00:00 2001 From: Francis Terrero Date: Mon, 6 Oct 2025 11:58:37 -0400 Subject: [PATCH 1/2] feat: update Modal component to include stopMouseDownPropagation prop and enhance tests --- package.json | 2 +- src/components/modal/Modal.tsx | 7 +++- src/components/modal/__test__/Modal.test.tsx | 36 +++++++++++++++++++ .../__snapshots__/Modal.test.tsx.snap | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7a412d7..a27dc39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@internxt/ui", - "version": "0.0.25", + "version": "0.0.26", "description": "Library of Internxt components", "repository": { "type": "git", diff --git a/src/components/modal/Modal.tsx b/src/components/modal/Modal.tsx index a0b4edb..f354e89 100644 --- a/src/components/modal/Modal.tsx +++ b/src/components/modal/Modal.tsx @@ -8,6 +8,7 @@ export interface ModalProps { className?: string; width?: string; preventClosing?: boolean; + stopMouseDownPropagation?: boolean; } /** @@ -38,6 +39,9 @@ export interface ModalProps { * @property {boolean} [preventClosing=false] * - Optional flag to prevent the modal from closing when clicking outside or pressing the 'Escape' key. * + * @property {boolean} [stopMouseDownPropagation=false] + * - Optional flag to stop event propagation on mousedown events. + * * @returns {JSX.Element | null} * - The rendered Modal component, or `null` if `isOpen` is `false`. * @@ -59,6 +63,7 @@ const Modal = ({ className, width, preventClosing = false, + stopMouseDownPropagation = false, }: ModalProps): JSX.Element | null => { const modalRef = useRef(null); const [showContent, setShowContent] = useState(isOpen); @@ -128,7 +133,7 @@ const Modal = ({ return ( <> {showContent && ( -
+
stopMouseDownPropagation && e.stopPropagation()} role='modal'>
{ expect(onClose1).not.toHaveBeenCalled(); expect(onClose2).toHaveBeenCalled(); }); + + it('should stop propagation when stopMouseDownPropagation is true', () => { + const parentHandler = vi.fn(); + const { container } = render( +
+ +
Modal Content
+
+
, + ); + + const modalWrapper = container.querySelector('[role="modal"]'); + expect(modalWrapper).toBeInTheDocument(); + + fireEvent.mouseDown(modalWrapper!); + + expect(parentHandler).not.toHaveBeenCalled(); + }); + + it('should not stop propagation when stopMouseDownPropagation is false', () => { + const parentHandler = vi.fn(); + const { container } = render( +
+ +
Modal Content
+
+
, + ); + + const modalWrapper = container.querySelector('[role="modal"]'); + expect(modalWrapper).toBeInTheDocument(); + + fireEvent.mouseDown(modalWrapper!); + + expect(parentHandler).toHaveBeenCalled(); + }); }); diff --git a/src/components/modal/__test__/__snapshots__/Modal.test.tsx.snap b/src/components/modal/__test__/__snapshots__/Modal.test.tsx.snap index 6a6c082..bad4e20 100644 --- a/src/components/modal/__test__/__snapshots__/Modal.test.tsx.snap +++ b/src/components/modal/__test__/__snapshots__/Modal.test.tsx.snap @@ -4,6 +4,7 @@ exports[`Modal Component > should match snapshot when isOpen is true 1`] = `