chore: Add warning if use inlineCollapsed under Sider (#16826)

This commit is contained in:
zombieJ 2019-05-27 20:53:43 +08:00 committed by GitHub
parent 9b05885363
commit 93887e1380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -138,7 +138,17 @@ describe('Layout', () => {
});
});
describe('Sider onBreakpoint', () => {
describe('Sider', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
afterEach(() => {
errorSpy.mockReset();
});
afterAll(() => {
errorSpy.mockRestore();
});
beforeAll(() => {
Object.defineProperty(window, 'matchMedia', {
value: jest.fn(() => ({
@ -159,4 +169,15 @@ describe('Sider onBreakpoint', () => {
);
expect(onBreakpoint).toHaveBeenCalledWith(true);
});
it('should warning if use `inlineCollapsed` with menu', () => {
mount(
<Sider collapsible>
<Menu mode="inline" inlineCollapsed />
</Sider>,
);
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Menu] `inlineCollapsed` not control Menu under Sider. Should set `collapsed` on Sider instead.',
);
});
});

View File

@ -142,6 +142,12 @@ class InternalMenu extends React.Component<InternalMenuProps, MenuState> {
'`inlineCollapsed` should only be used when `mode` is inline.',
);
warning(
!(props.siderCollapsed !== undefined && 'inlineCollapsed' in props),
'Menu',
'`inlineCollapsed` not control Menu under Sider. Should set `collapsed` on Sider instead.',
);
let openKeys;
if ('openKeys' in props) {
openKeys = props.openKeys;