Skip to content
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

chore: Add warning if use inlineCollapsed under Sider #16826

Merged
merged 1 commit into from May 27, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion components/layout/__tests__/index.test.js
Expand Up @@ -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(() => ({
Expand All @@ -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.',
);
});
});
6 changes: 6 additions & 0 deletions components/menu/index.tsx
Expand Up @@ -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;
Expand Down