Skip to content

Commit

Permalink
feat: expose mouse event to the onClose prop
Browse files Browse the repository at this point in the history
sometime clients need to access the even properties to do some logic based on the click, ex: stopPropagation
  • Loading branch information
Afzal committed Aug 14, 2024
1 parent 98ef0f8 commit 65d88d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/@next/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import React, { MouseEventHandler, useEffect, useRef, useState } from 'react';
import { ComponentAction } from '../../types/componentAction';
import { Button, PrimaryButton } from '../Button';
import { ButtonGroup } from '../ButtonGroup';
Expand Down Expand Up @@ -45,7 +45,7 @@ export type ModalProps = React.HTMLAttributes<HTMLDivElement> &
showHeaderBorder?: boolean;
/** Setting this to true will close modal when clicking outside of Modal body */
closeOnClickOutside?: boolean;
onClose?: () => void;
onClose?: MouseEventHandler<HTMLDivElement | HTMLButtonElement>;
onBack?: () => void;
zIndexOverride?: number;
/** This prop will add default padding to the header */
Expand Down Expand Up @@ -152,17 +152,17 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
children
);

const handleClickOutside = () => {
const handleClickOutside: MouseEventHandler<HTMLDivElement> = event => {
if (closeOnClickOutside) {
onClose?.();
onClose?.(event);
}
};

return (
<Portal>
<StyledModalWrapper
data-testid="modal-wrapper"
onClick={() => handleClickOutside()}
onClick={handleClickOutside}
zIndexOverride={zIndexOverride}
>
{leftComponent && (
Expand Down Expand Up @@ -202,7 +202,7 @@ export const Modal = React.forwardRef<HTMLDivElement, ModalProps>(
<StyledModalCloseButton
data-testid="modal-close-btn"
data-has-decription={!!headerDescription}
onClick={() => onClose?.()}
onClick={onClose}
>
<Icon name="ri-close" />
</StyledModalCloseButton>
Expand Down
4 changes: 2 additions & 2 deletions src/@next/Modal/ModalWithProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const ModalWithProvider = () => {
<Modal
{...modalProps}
isOpen={isOpen}
onClose={() => {
onClose={e => {
close();
onClose?.();
onClose?.(e);
}}
/>
);
Expand Down

0 comments on commit 65d88d7

Please sign in to comment.