Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ storybook

# dumi
.dumi/tmp
.dumi/tmp-production
.dumi/tmp-production
pnpm-lock.yaml
33 changes: 19 additions & 14 deletions src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface DrawerPopupProps

// styles
styles?: DrawerStyles;
drawerRender?: (node: React.ReactNode) => React.ReactNode;
}

function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
Expand Down Expand Up @@ -121,6 +122,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
onKeyUp,

styles,
drawerRender,
} = props;

// ================================ Refs ================================
Expand Down Expand Up @@ -291,6 +293,22 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
leavedClassName={`${prefixCls}-content-wrapper-hidden`}
>
{({ className: motionClassName, style: motionStyle }, motionRef) => {
const content = (
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={classNames(className, drawerClassNames?.content)}
style={{
...style,
...styles?.content,
}}
{...pickAttrs(props, { aria: true })}
{...eventHandlers}
>
{children}
</DrawerPanel>
);
return (
<div
className={classNames(
Expand All @@ -305,20 +323,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
}}
{...pickAttrs(props, { data: true })}
>
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={classNames(className, drawerClassNames?.content)}
style={{
...style,
...styles?.content,
}}
{...pickAttrs(props, { aria: true })}
{...eventHandlers}
>
{children}
</DrawerPanel>
{drawerRender ? drawerRender(content) : content}
</div>
);
}}
Expand Down
7 changes: 7 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,11 @@ describe('rc-drawer-menu', () => {
);
unmount();
});
it('should support drawerRender', () => {
const { unmount } = render(
<Drawer drawerRender={dom => <div id="test">{dom}</div>} open />,
);
expect(document.querySelector('#test')).toBeTruthy();
unmount();
});
});