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

fix(ComposedModal): align handleMouseDown between Modal, ComposedModal #15934

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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