Skip to content

Commit

Permalink
fix(Drawer): use hideBackdrop prop and prevent backdrop slotProps w…
Browse files Browse the repository at this point in the history
…hen hidden (#3893)
  • Loading branch information
plagoa committed Dec 13, 2023
1 parent b47d19d commit 62c629a
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions packages/core/src/components/Drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const HvDrawer = (props: HvDrawerProps) => {
anchor = "right",
buttonTitle = "Close",
showBackdrop = true,
hideBackdrop,
disableBackdropClick = false,
...others
} = useDefaultProps("HvDrawer", props);
Expand All @@ -103,6 +104,8 @@ export const HvDrawer = (props: HvDrawerProps) => {
onClose?.(event, reason);
};

const shouldHideBackdrop = hideBackdrop ?? !showBackdrop;

return (
<MuiDrawer
className={cx(classes.root, className)}
Expand All @@ -114,23 +117,25 @@ export const HvDrawer = (props: HvDrawerProps) => {
root: classes.paper,
},
}}
hideBackdrop={!showBackdrop}
slotProps={{
backdrop: {
classes: {
root: cx(
css({
background: hexToRgbA(colors?.atmo4 || theme.colors.atmo4),
}),
classes.background
),
},
onClick: (event) => {
if (disableBackdropClick) return;
onClose?.(event, "backdropClick");
hideBackdrop={shouldHideBackdrop}
{...(!shouldHideBackdrop && {
slotProps: {
backdrop: {
classes: {
root: cx(
css({
background: hexToRgbA(colors?.atmo4 || theme.colors.atmo4),
}),
classes.background
),
},
onClick: (event) => {
if (disableBackdropClick) return;
onClose?.(event, "backdropClick");
},
},
},
}}
})}
onClose={handleOnClose}
{...others}
>
Expand Down

0 comments on commit 62c629a

Please sign in to comment.