Browse Source

docs: Add more desc & warning (#39201)

pull/39213/head
二货爱吃白萝卜 2 years ago
committed by GitHub
parent
commit
4d33b7443b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      components/drawer/__tests__/Drawer.test.tsx
  2. 4
      components/drawer/demo/render-in-current.md
  3. 8
      components/drawer/index.tsx

35
components/drawer/__tests__/Drawer.test.tsx

@ -6,6 +6,7 @@ import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { fireEvent, render } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
import { resetWarned } from '../../_util/warning';
const DrawerTest: React.FC<DrawerProps> = ({ getContainer }) => (
<div>
@ -208,4 +209,38 @@ describe('Drawer', () => {
zIndex: 903,
});
});
describe('style migrate', () => {
it('not warning with getContainer', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
resetWarned();
render(<Drawer getContainer={() => document.body} />);
expect(errorSpy).not.toHaveBeenCalled();
errorSpy.mockRestore();
});
it('not warning with getContainer false', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
resetWarned();
render(<Drawer getContainer={false} />);
expect(errorSpy).not.toHaveBeenCalled();
errorSpy.mockRestore();
});
it('warning with getContainer & style', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
resetWarned();
render(<Drawer getContainer={false} style={{ position: 'absolute' }} />);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Drawer] `style` is move to `rootStyle` in v5. Please confirm `position: absolute` is necessary.',
);
errorSpy.mockRestore();
});
});
});

4
components/drawer/demo/render-in-current.md

@ -2,10 +2,14 @@
渲染在当前 dom 里。自定义容器,查看 `getContainer`
注意:在 v5 中 `style``className` 迁移至 Drawer 面板上与 Modal 保持一致,原 `style``className` 替换为 `rootStyle``rootClassName`
## en-US
Render in current dom. custom container, check `getContainer`.
Note: `style` and `className` is move to Drawer panel in v5 which is align with Modal component. Origin `style` and `className` is replaced by `rootStyle` and `rootClassName`.
```css
.site-drawer-render-in-current-wrapper {
position: relative;

8
components/drawer/index.tsx

@ -93,6 +93,14 @@ function Drawer(props: DrawerProps) {
`\`${deprecatedName}\` is deprecated, please use \`${newName}\` instead.`,
);
});
if (getContainer !== undefined && props.style?.position === 'absolute') {
warning(
false,
'Drawer',
'`style` is move to `rootStyle` in v5. Please confirm `position: absolute` is necessary.',
);
}
}
// ============================ Size ============================

Loading…
Cancel
Save