Skip to content

Commit

Permalink
feat: app prop to disable drawer close on outside click
Browse files Browse the repository at this point in the history
affects: @medly-components/core
  • Loading branch information
gmukul01 committed Jul 24, 2024
1 parent 17f2c42 commit d041a13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import Header from './Header';
import { DrawerProps, DrawerStaticProps } from './types';

const Component: FC<DrawerProps> = memo(
forwardRef(({ id, onClose, open, width, children, withOverlay, position, ...props }, ref) => {
forwardRef(({ id, onClose, open, width, children, withOverlay, position, shouldCloseOnOutsideClick, ...props }, ref) => {
const isEscPressed = useKeyPress('Escape'),
[shouldRender, setRenderState] = useState(open),
[scrollState, dispatch] = useReducer(reducer, { scrolledToTop: true, scrolledToBottom: false, scrollPosition: 0 });

const handleBackgroundClick = useCallback(
(event: MouseEvent<HTMLDivElement>) => event.currentTarget === event.target && onClose && onClose(),
(event: MouseEvent<HTMLDivElement>) =>
event.currentTarget === event.target && shouldCloseOnOutsideClick && onClose && onClose(),
[onClose]
),
handleAnimationEnd = useCallback(() => !open && setRenderState(false), [open]);
Expand Down Expand Up @@ -52,7 +53,8 @@ Component.defaultProps = {
open: false,
position: 'right',
width: '40rem',
withOverlay: true
withOverlay: true,
shouldCloseOnOutsideClick: true
};
export const Drawer: FC<DrawerProps> & WithStyle & DrawerStaticProps = Object.assign(Component, {
Style: DrawerBackground,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/components/Drawer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface DrawerProps extends HTMLProps<HTMLDivElement> {
onClose: () => void;
width?: string;
withOverlay?: boolean;
shouldCloseOnOutsideClick?: boolean;
}

export interface DrawerStaticProps {
Expand Down

0 comments on commit d041a13

Please sign in to comment.