Skip to content

Commit

Permalink
fix(ComposedModal): align handleMouseDown between Modal, ComposedModal (
Browse files Browse the repository at this point in the history
#15934)

* fix(ComposedModal): align handleMouseDown between Modal, ComposedModal

* test(ComposedModal): update snaps
  • Loading branch information
tw15egan committed Apr 10, 2024
1 parent e1549c1 commit ad1362c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Expand Up @@ -1485,6 +1485,7 @@ Map {
"selectorsFloatingMenus": Object {
"args": Array [
Object {
"isRequired": true,
"type": "string",
},
],
Expand Down
21 changes: 15 additions & 6 deletions packages/react/src/components/ComposedModal/ComposedModal.tsx
Expand Up @@ -19,7 +19,10 @@ import mergeRefs from '../../tools/mergeRefs';
import cx from 'classnames';
import toggleClass from '../../tools/toggleClass';
import requiredIfGivenPropIsTruthy from '../../prop-types/requiredIfGivenPropIsTruthy';
import wrapFocus, { wrapFocusWithoutSentinels } from '../../internal/wrapFocus';
import wrapFocus, {
elementOrParentIsFloatingMenu,
wrapFocusWithoutSentinels,
} from '../../internal/wrapFocus';
import { usePrefix } from '../../internal/usePrefix';
import { keys, match } from '../../internal/keyboard';
import { useFeatureFlag } from '../FeatureFlags';
Expand Down Expand Up @@ -202,7 +205,7 @@ export interface ComposedModalProps extends HTMLAttributes<HTMLDivElement> {
selectorPrimaryFocus?: string;

/** Specify the CSS selectors that match the floating menus. */
selectorsFloatingMenus?: Array<string | null | undefined>;
selectorsFloatingMenus?: string[];

size?: 'xs' | 'sm' | 'md' | 'lg';

Expand Down Expand Up @@ -283,10 +286,16 @@ const ComposedModal = React.forwardRef<HTMLDivElement, ComposedModalProps>(

onKeyDown?.(event);
}
function handleMousedown(evt: MouseEvent) {

function handleMousedown(evt: React.MouseEvent<HTMLDivElement>) {
const target = evt.target as Node;
evt.stopPropagation();
const isInside = innerModal.current?.contains(evt.target as Node);
if (!isInside && !preventCloseOnClickOutside) {
if (
!preventCloseOnClickOutside &&
!elementOrParentIsFloatingMenu(target, selectorsFloatingMenus) &&
innerModal.current &&
!innerModal.current.contains(target)
) {
closeModal(evt);
}
}
Expand Down Expand Up @@ -525,7 +534,7 @@ ComposedModal.propTypes = {
/**
* Specify the CSS selectors that match the floating menus
*/
selectorsFloatingMenus: PropTypes.arrayOf(PropTypes.string),
selectorsFloatingMenus: PropTypes.arrayOf(PropTypes.string.isRequired),

/**
* Specify the size variant.
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/components/Modal/Modal.tsx
Expand Up @@ -315,10 +315,10 @@ const Modal = React.forwardRef(function Modal(
const target = evt.target as Node;
evt.stopPropagation();
if (
innerModal.current &&
!innerModal.current.contains(target) &&
!preventCloseOnClickOutside &&
!elementOrParentIsFloatingMenu(target, selectorsFloatingMenus) &&
!preventCloseOnClickOutside
innerModal.current &&
!innerModal.current.contains(target)
) {
onRequestClose(evt);
}
Expand Down

0 comments on commit ad1362c

Please sign in to comment.