Skip to content

Commit

Permalink
WEB-2113 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Ladaria committed Dec 20, 2024
1 parent 8c12f8c commit 7a0f8b3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ const DrawerLayout = React.forwardRef<DrawerPropsRef, DrawerLayoutProps>(
useRestoreFocus();
const {isMobile, isTablet} = useScreenSize();
const [isOpen, setIsOpen] = React.useState(false);
const widthStyle = isMobile ? 'auto' : width || (isTablet ? WIDTH_TABLET : WIDTH_DESKTOP);

const open = React.useCallback((node: HTMLDivElement) => {
if (node) {
// small delay to allow the Portal to be mounted
setTimeout(() => setIsOpen(true), 50);
setTimeout(() => {
setIsOpen(true);
}, 50);
}
}, []);

Expand Down Expand Up @@ -103,20 +106,18 @@ const DrawerLayout = React.forwardRef<DrawerPropsRef, DrawerLayoutProps>(
<FocusTrap>
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
<div
data-testid="drawerOverlay"
onClick={onDismiss ? dismiss : undefined}
className={classnames(
styles.overlay,
isOpen ? styles.overlayOpen : styles.overlayClosed
)}
{...getPrefixedDataAttributes({}, 'DrawerOverlay')}
/>
<div
data-testid="drawerLayout"
ref={open}
style={{
width: isMobile ? 'unset' : width || (isTablet ? WIDTH_TABLET : WIDTH_DESKTOP),
}}
style={{width: widthStyle}}
className={classnames(styles.container, isOpen ? styles.open : styles.closed)}
{...getPrefixedDataAttributes({}, 'DrawerLayout')}
>
{children}
</div>
Expand All @@ -137,14 +138,17 @@ type DrawerProps = {
title?: string;
subtitle?: string;
description?: string;
/**
* this handler is mandatory. You should unmount the Drawer component on close.
*/
onClose: () => void;
/**
* set this handler to enable dismiss:
* - touching "X"
* - touching overlay
* - pressing ESC
*/
onDismiss?: () => void;
onClose: () => void;
children?: React.ReactNode;
/**
* width is ignored in mobile viewport
Expand Down

0 comments on commit 7a0f8b3

Please sign in to comment.