Skip to content

Commit

Permalink
fix: Drawer default props
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 24, 2022
1 parent 571a092 commit ece6667
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,26 @@ export type Placement = 'left' | 'top' | 'right' | 'bottom';
export interface DrawerProps
extends Omit<DrawerPopupProps, 'prefixCls' | 'inline' | 'scrollLocker'> {
prefixCls?: string;

open?: boolean;
onClose?: (e: React.MouseEvent | React.KeyboardEvent) => void;
destroyOnClose?: boolean;
getContainer?: PortalProps['getContainer'];
}

// Default Value.
// Since spread with default value will make this all over components.
// Let's maintain this in one place.
const defaultProps = {
open: false,
prefixCls: 'rc-drawer',
placement: 'right' as Placement,
autoFocus: true,
keyboard: true,
width: 378,
mask: true,
maskClosable: true,
};

const Drawer: React.FC<DrawerProps> = drawerProps => {
const props = {
...defaultProps,
...drawerProps,
};
const Drawer: React.FC<DrawerProps> = props => {
const {
open,
open = false,
prefixCls = 'rc-drawer',
placement = 'right' as Placement,
autoFocus = true,
keyboard = true,
width = 378,
mask = true,
maskClosable = true,
getContainer,
forceRender,
prefixCls,
afterOpenChange,
destroyOnClose,
mask,
} = props;

const [animatedVisible, setAnimatedVisible] = React.useState(false);
Expand All @@ -65,9 +51,17 @@ const Drawer: React.FC<DrawerProps> = drawerProps => {
return null;
}

const sharedDrawerProps = {
const drawerPopupProps = {
...props,
open,
prefixCls,
placement,
autoFocus,
keyboard,
width,
mask,
maskClosable,
inline: getContainer === false,
afterOpenChange: internalAfterOpenChange,
};

Expand All @@ -78,7 +72,7 @@ const Drawer: React.FC<DrawerProps> = drawerProps => {
getContainer={getContainer}
autoLock={mask && (open || animatedVisible)}
>
<DrawerPopup {...sharedDrawerProps} inline={getContainer === false} />
<DrawerPopup {...drawerPopupProps} />
</Portal>
);
};
Expand Down

0 comments on commit ece6667

Please sign in to comment.