From bc99a9fec1d3591d4df737989c43a6f2dd2ca128 Mon Sep 17 00:00:00 2001 From: David Menendez Date: Fri, 21 Jun 2024 14:17:47 -0500 Subject: [PATCH 1/4] fix: switch onmousedown to onclick handler in modal components --- packages/react/src/components/ComposedModal/ComposedModal.tsx | 4 ++-- packages/react/src/components/Modal/Modal.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/ComposedModal/ComposedModal.tsx b/packages/react/src/components/ComposedModal/ComposedModal.tsx index c7b3558efd0a..60be221216ce 100644 --- a/packages/react/src/components/ComposedModal/ComposedModal.tsx +++ b/packages/react/src/components/ComposedModal/ComposedModal.tsx @@ -287,7 +287,7 @@ const ComposedModal = React.forwardRef( onKeyDown?.(event); } - function handleMousedown(evt: React.MouseEvent) { + function handleClick(evt: React.MouseEvent) { const target = evt.target as Node; evt.stopPropagation(); if ( @@ -421,7 +421,7 @@ const ComposedModal = React.forwardRef( ref={ref} aria-hidden={!open} onBlur={!focusTrapWithoutSentinels ? handleBlur : () => {}} - onMouseDown={handleMousedown} + onClick={handleClick} onKeyDown={handleKeyDown} className={modalClass}>
) { + function handleOnclick(evt: React.MouseEvent) { const target = evt.target as Node; evt.stopPropagation(); if ( @@ -584,7 +584,7 @@ const Modal = React.forwardRef(function Modal(
{}} className={modalClasses} role="presentation" From dff0e54137a871f67b5daf196319b7bf2497f0e3 Mon Sep 17 00:00:00 2001 From: David Menendez Date: Tue, 25 Jun 2024 08:57:00 -0500 Subject: [PATCH 2/4] fix: include user onclick --- .../react/src/components/ComposedModal/ComposedModal.tsx | 5 +++-- packages/react/src/components/Modal/Modal.tsx | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/ComposedModal/ComposedModal.tsx b/packages/react/src/components/ComposedModal/ComposedModal.tsx index 60be221216ce..f3776e88fff6 100644 --- a/packages/react/src/components/ComposedModal/ComposedModal.tsx +++ b/packages/react/src/components/ComposedModal/ComposedModal.tsx @@ -26,6 +26,7 @@ import wrapFocus, { import { usePrefix } from '../../internal/usePrefix'; import { keys, match } from '../../internal/keyboard'; import { useFeatureFlag } from '../FeatureFlags'; +import { composeEventHandlers } from '../../tools/events'; export interface ModalBodyProps extends HTMLAttributes { /** Specify the content to be placed in the ModalBody. */ @@ -287,7 +288,7 @@ const ComposedModal = React.forwardRef( onKeyDown?.(event); } - function handleClick(evt: React.MouseEvent) { + function handleOnClick(evt: React.MouseEvent) { const target = evt.target as Node; evt.stopPropagation(); if ( @@ -421,7 +422,7 @@ const ComposedModal = React.forwardRef( ref={ref} aria-hidden={!open} onBlur={!focusTrapWithoutSentinels ? handleBlur : () => {}} - onClick={handleClick} + onClick={composeEventHandlers([rest?.onClick, handleOnClick])} onKeyDown={handleKeyDown} className={modalClass}>
) { + function handleOnClick(evt: React.MouseEvent) { const target = evt.target as Node; evt.stopPropagation(); if ( @@ -584,7 +585,7 @@ const Modal = React.forwardRef(function Modal(
{}} className={modalClasses} role="presentation" From 5dbff02eb27239a7e5ed93f3e82d0571b7a94c87 Mon Sep 17 00:00:00 2001 From: David Menendez Date: Tue, 25 Jun 2024 14:11:20 -0500 Subject: [PATCH 3/4] fix: added test --- .../react/src/components/Modal/Modal-test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/react/src/components/Modal/Modal-test.js b/packages/react/src/components/Modal/Modal-test.js index 7e0f65d859c1..a713fc1dd768 100644 --- a/packages/react/src/components/Modal/Modal-test.js +++ b/packages/react/src/components/Modal/Modal-test.js @@ -512,6 +512,22 @@ describe('events', () => { expect(onRequestClose).toHaveBeenCalled(); }); + it('should handle onClick events', async () => { + const onClick = jest.fn(); + render( + +

+ Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. +

+
+ ); + const modal = screen.getByRole('dialog'); + await userEvent.click(modal); + expect(onClick).toHaveBeenCalled(); + }); + it('should handle submit keyDown events with shouldSubmitOnEnter enabled', async () => { const onRequestSubmit = jest.fn(); render( From d2b3268bcb685030004ef1e62f707b4d8a96b711 Mon Sep 17 00:00:00 2001 From: David Menendez Date: Tue, 25 Jun 2024 14:14:03 -0500 Subject: [PATCH 4/4] fix: include test --- .../ComposedModal/ComposedModal-test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/react/src/components/ComposedModal/ComposedModal-test.js b/packages/react/src/components/ComposedModal/ComposedModal-test.js index 3db0bff2a4b9..ec93a9137786 100644 --- a/packages/react/src/components/ComposedModal/ComposedModal-test.js +++ b/packages/react/src/components/ComposedModal/ComposedModal-test.js @@ -249,4 +249,20 @@ describe('ComposedModal', () => { expect(container.firstChild).toHaveClass(`${prefix}--modal--slug`); }); }); + + it('should handle onClick events', async () => { + const onClick = jest.fn(); + render( + +

+ Custom domains direct requests for your apps in this Cloud Foundry + organization to a URL that you own. A custom domain can be a shared + domain, a shared subdomain, or a shared domain and host. +

+
+ ); + const modal = screen.getByRole('dialog'); + await userEvent.click(modal); + expect(onClick).toHaveBeenCalled(); + }); });