Skip to content

Commit cee8298

Browse files
authored
fix: add drawer styles.content / classNames.content warning (ant-design#56898)
1 parent 19d7bfb commit cee8298

3 files changed

Lines changed: 63 additions & 26 deletions

File tree

components/drawer/Drawer.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,6 @@ const Drawer: React.FC<DrawerProps> & {
127127
? () => getPopupContainer(document.body)
128128
: customizeGetContainer;
129129

130-
// ========================== Warning ===========================
131-
if (process.env.NODE_ENV !== 'production') {
132-
const warning = devUseWarning('Drawer');
133-
[
134-
['headerStyle', 'styles.header'],
135-
['bodyStyle', 'styles.body'],
136-
['footerStyle', 'styles.footer'],
137-
['contentWrapperStyle', 'styles.wrapper'],
138-
['maskStyle', 'styles.mask'],
139-
['drawerStyle', 'styles.section'],
140-
['destroyInactivePanel', 'destroyOnHidden'],
141-
['width', 'size'],
142-
['height', 'size'],
143-
].forEach(([deprecatedName, newName]) => {
144-
warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
145-
});
146-
147-
if (getContainer !== undefined && props.style?.position === 'absolute') {
148-
warning(
149-
false,
150-
'breaking',
151-
'`style` is replaced by `rootStyle` in v5. Please check that `position: absolute` is necessary.',
152-
);
153-
}
154-
}
155-
156130
// ============================ Size ============================
157131
const drawerSize = React.useMemo<string | number | undefined>(() => {
158132
if (typeof size === 'number') {
@@ -231,6 +205,38 @@ const Drawer: React.FC<DrawerProps> & {
231205
props: mergedProps,
232206
});
233207

208+
// ========================== Warning ===========================
209+
if (process.env.NODE_ENV !== 'production') {
210+
const warning = devUseWarning('Drawer');
211+
[
212+
['headerStyle', 'styles.header'],
213+
['bodyStyle', 'styles.body'],
214+
['footerStyle', 'styles.footer'],
215+
['contentWrapperStyle', 'styles.wrapper'],
216+
['maskStyle', 'styles.mask'],
217+
['drawerStyle', 'styles.section'],
218+
['destroyInactivePanel', 'destroyOnHidden'],
219+
['width', 'size'],
220+
['height', 'size'],
221+
].forEach(([deprecatedName, newName]) => {
222+
warning.deprecated(!(deprecatedName in props), deprecatedName, newName);
223+
});
224+
225+
if (getContainer !== undefined && props.style?.position === 'absolute') {
226+
warning(
227+
false,
228+
'breaking',
229+
'`style` is replaced by `rootStyle` in v5. Please check that `position: absolute` is necessary.',
230+
);
231+
}
232+
233+
warning.deprecated(
234+
!(mergedClassNames?.content || mergedStyles?.content),
235+
'classNames.content and styles.content',
236+
'classNames.section and styles.section',
237+
);
238+
}
239+
234240
const drawerClassName = clsx(
235241
{
236242
'no-mask': !mergedMask,

components/drawer/DrawerPanel.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export type DrawerSemanticClassNames = {
2222
wrapper?: string;
2323
dragger?: string;
2424
close?: string;
25+
/**
26+
* @deprecated please use `classNames.section` instead.
27+
*/
28+
content?: string;
2529
};
2630

2731
export type DrawerSemanticStyles = {
@@ -36,6 +40,10 @@ export type DrawerSemanticStyles = {
3640
wrapper?: React.CSSProperties;
3741
dragger?: React.CSSProperties;
3842
close?: React.CSSProperties;
43+
/**
44+
* @deprecated please use `styles.section` instead.
45+
*/
46+
content?: React.CSSProperties;
3947
};
4048

4149
export type DrawerClassNamesType = SemanticClassNamesType<DrawerProps, DrawerSemanticClassNames>;

components/drawer/__tests__/semantic.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React from 'react';
2+
import { warning } from '@rc-component/util';
23

34
import Drawer from '..';
45
import type { DrawerProps } from '..';
56
import { render } from '../../../tests/utils';
67

8+
const { resetWarned } = warning;
9+
710
describe('Drawer.Semantic', () => {
811
it('should apply custom classnames & styles to Drawer', () => {
912
const customClassNames: DrawerProps['classNames'] = {
@@ -217,4 +220,24 @@ describe('Drawer.Semantic', () => {
217220
expect(footerElement).toHaveStyle({ color: 'rgb(255, 255, 0)' });
218221
expect(closeElement).toHaveStyle({ color: 'rgb(90, 0, 0)' });
219222
});
223+
224+
it('warning with both deprecated classNames.content and styles.content props', () => {
225+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
226+
resetWarned();
227+
228+
render(
229+
<Drawer
230+
open
231+
classNames={{ content: 'custom-content' }}
232+
styles={{ content: { color: 'red' } }}
233+
>
234+
Here is content of Drawer
235+
</Drawer>,
236+
);
237+
expect(errorSpy).toHaveBeenCalledWith(
238+
'Warning: [antd: Drawer] `classNames.content and styles.content` is deprecated. Please use `classNames.section and styles.section` instead.',
239+
);
240+
241+
errorSpy.mockRestore();
242+
});
220243
});

0 commit comments

Comments
 (0)