Skip to content

feat: support id prop #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2023
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: 3 additions & 0 deletions src/DrawerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface DrawerPanelEvents {
export interface DrawerPanelProps extends DrawerPanelEvents {
prefixCls: string;
className?: string;
id?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
containerRef?: React.Ref<HTMLDivElement>;
Expand All @@ -29,6 +30,7 @@ const DrawerPanel = (props: DrawerPanelProps) => {
style,
children,
containerRef,
id,
onMouseEnter,
onMouseOver,
onMouseLeave,
Expand All @@ -51,6 +53,7 @@ const DrawerPanel = (props: DrawerPanelProps) => {
return (
<>
<div
id={id}
className={classNames(`${prefixCls}-content`, className)}
style={{
...style,
Expand Down
6 changes: 5 additions & 1 deletion src/DrawerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import pickAttrs from 'rc-util/lib/pickAttrs';
import * as React from 'react';
import type { DrawerContextProps } from './context';
import DrawerContext from './context';
import DrawerPanel, { DrawerPanelEvents } from './DrawerPanel';
import type { DrawerPanelEvents } from './DrawerPanel';
import DrawerPanel from './DrawerPanel';
import { parseWidthHeight } from './util';

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

// Drawer
placement?: Placement;
id?: string;
className?: string;
style?: React.CSSProperties;
children?: React.ReactNode;
Expand Down Expand Up @@ -81,6 +83,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {

// Drawer
className,
id,
style,
motion,
width,
Expand Down Expand Up @@ -292,6 +295,7 @@ function DrawerPopup(props: DrawerPopupProps, ref: React.Ref<HTMLDivElement>) {
{...pickAttrs(props, { data: true })}
>
<DrawerPanel
id={id}
containerRef={motionRef}
prefixCls={prefixCls}
className={className}
Expand Down
11 changes: 11 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,15 @@ describe('rc-drawer-menu', () => {
fireEvent.mouseLeave(baseElement.querySelector('.rc-drawer-content'));
expect(leave).toHaveBeenCalled();
});

it('pass id & className props to Panel', () => {
const { unmount } = render(<Drawer className='customer-className' id="customer-id" open/>);
expect(
document.querySelector('.rc-drawer-content')
).toHaveClass('customer-className');
expect(
document.querySelector('.rc-drawer-content')
).toHaveAttribute('id', 'customer-id');
unmount();
});
});