Browse Source

Merge pull request #15396 from SoraYama/sorayama

fix(Layout): disable `hasSider` when specifically declared
pull/15421/head
偏右 6 years ago
committed by GitHub
parent
commit
4f0e6e6523
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      components/layout/__tests__/index.test.js
  2. 3
      components/layout/layout.tsx

9
components/layout/__tests__/index.test.js

@ -95,6 +95,15 @@ describe('Layout', () => {
wrapper.setProps({ collapsed: true });
expect(wrapper.instance().state.collapsed).toBe(true);
});
it('should not add ant-layout-has-sider when `hasSider` is `false`', () => {
const wrapper = mount(
<Layout hasSider={false}>
<Sider>Sider</Sider>
</Layout>,
);
expect(wrapper.find('.ant-layout').hasClass('ant-layout-has-sider')).toBe(false);
});
});
describe('Sider onBreakpoint', () => {

3
components/layout/layout.tsx

@ -77,7 +77,8 @@ class BasicLayout extends React.Component<BasicPropsWithTagName, BasicLayoutStat
render() {
const { prefixCls, className, children, hasSider, tagName, ...others } = this.props;
const classString = classNames(className, prefixCls, {
[`${prefixCls}-has-sider`]: hasSider || this.state.siders.length > 0,
[`${prefixCls}-has-sider`]:
typeof hasSider === 'boolean' ? hasSider : this.state.siders.length > 0,
});
return React.createElement(tagName, { className: classString, ...others }, children);
}

Loading…
Cancel
Save