Skip to content

Commit 96b6aa8

Browse files
authored
feat: support id prop (#421)
* featL support id prop * test: add test * fix: pass id to panel
1 parent f2d8b7c commit 96b6aa8

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

src/DrawerPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface DrawerPanelEvents {
1717
export interface DrawerPanelProps extends DrawerPanelEvents {
1818
prefixCls: string;
1919
className?: string;
20+
id?: string;
2021
style?: React.CSSProperties;
2122
children?: React.ReactNode;
2223
containerRef?: React.Ref<HTMLDivElement>;
@@ -29,6 +30,7 @@ const DrawerPanel = (props: DrawerPanelProps) => {
2930
style,
3031
children,
3132
containerRef,
33+
id,
3234
onMouseEnter,
3335
onMouseOver,
3436
onMouseLeave,
@@ -51,6 +53,7 @@ const DrawerPanel = (props: DrawerPanelProps) => {
5153
return (
5254
<>
5355
<div
56+
id={id}
5457
className={classNames(`${prefixCls}-content`, className)}
5558
style={{
5659
...style,

src/DrawerPopup.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import pickAttrs from 'rc-util/lib/pickAttrs';
66
import * as React from 'react';
77
import type { DrawerContextProps } from './context';
88
import DrawerContext from './context';
9-
import DrawerPanel, { DrawerPanelEvents } from './DrawerPanel';
9+
import type { DrawerPanelEvents } from './DrawerPanel';
10+
import DrawerPanel from './DrawerPanel';
1011
import { parseWidthHeight } from './util';
1112

1213
const sentinelStyle: React.CSSProperties = {
@@ -39,6 +40,7 @@ export interface DrawerPopupProps extends DrawerPanelEvents {
3940

4041
// Drawer
4142
placement?: Placement;
43+
id?: string;
4244
className?: string;
4345
style?: React.CSSProperties;
4446
children?: React.ReactNode;
@@ -81,6 +83,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
8183

8284
// Drawer
8385
className,
86+
id,
8487
style,
8588
motion,
8689
width,
@@ -292,6 +295,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
292295
{...pickAttrs(props, { data: true })}
293296
>
294297
<DrawerPanel
298+
id={id}
295299
containerRef={motionRef}
296300
prefixCls={prefixCls}
297301
className={className}

tests/index.spec.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,15 @@ describe('rc-drawer-menu', () => {
384384
fireEvent.mouseLeave(baseElement.querySelector('.rc-drawer-content'));
385385
expect(leave).toHaveBeenCalled();
386386
});
387+
388+
it('pass id & className props to Panel', () => {
389+
const { unmount } = render(<Drawer className='customer-className' id="customer-id" open/>);
390+
expect(
391+
document.querySelector('.rc-drawer-content')
392+
).toHaveClass('customer-className');
393+
expect(
394+
document.querySelector('.rc-drawer-content')
395+
).toHaveAttribute('id', 'customer-id');
396+
unmount();
397+
});
387398
});

0 commit comments

Comments
 (0)