Skip to content

Commit

Permalink
Hide menu when collapsedWidth is 0, close ant-design#8587
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Dec 15, 2017
1 parent 7521348 commit 754d330
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/layout/Sider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default class Sider extends React.Component<SiderProps, SliderState> {

static childContextTypes = {
siderCollapsed: PropTypes.bool,
collapsedWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};

static contextTypes = {
Expand Down Expand Up @@ -113,6 +114,7 @@ export default class Sider extends React.Component<SiderProps, SliderState> {
getChildContext() {
return {
siderCollapsed: this.state.collapsed,
collapsedWidth: this.props.collapsedWidth,
};
}

Expand Down Expand Up @@ -182,7 +184,7 @@ export default class Sider extends React.Component<SiderProps, SliderState> {
'defaultCollapsed', 'onCollapse', 'breakpoint']);
const siderWidth = this.state.collapsed ? collapsedWidth : width;
// special trigger when collapsedWidth == 0
const zeroWidthTrigger = collapsedWidth === 0 || collapsedWidth === '0' ? (
const zeroWidthTrigger = collapsedWidth === 0 || collapsedWidth === '0' || collapsedWidth === '0px' ? (
<span onClick={this.toggle} className={`${prefixCls}-zero-width-trigger`}>
<Icon type="bars" />
</span>
Expand Down Expand Up @@ -212,7 +214,7 @@ export default class Sider extends React.Component<SiderProps, SliderState> {
[`${prefixCls}-collapsed`]: !!this.state.collapsed,
[`${prefixCls}-has-trigger`]: !!trigger,
[`${prefixCls}-below`]: !!this.state.below,
[`${prefixCls}-zero-width`]: siderWidth === 0 || siderWidth === '0',
[`${prefixCls}-zero-width`]: siderWidth === 0 || siderWidth === '0' || siderWidth === '0px',
});
return (
<div className={siderCls} {...divProps} style={divStyle}>
Expand Down
10 changes: 10 additions & 0 deletions components/menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class Menu extends React.Component<MenuProps, MenuState> {
};
static contextTypes = {
siderCollapsed: PropTypes.bool,
collapsedWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};
switchModeFromInline: boolean;
inlineOpenKeys: string[] = [];
Expand Down Expand Up @@ -225,6 +226,15 @@ export default class Menu extends React.Component<MenuProps, MenuState> {
menuProps.openAnimation = menuOpenAnimation;
}

// https://github.com/ant-design/ant-design/issues/8587
const { collapsedWidth } = this.context;
if (
this.getInlineCollapsed() &&
(collapsedWidth === 0 || collapsedWidth === '0' || collapsedWidth === '0px')
) {
return null;
}

return <RcMenu {...this.props} {...menuProps} />;
}
}

0 comments on commit 754d330

Please sign in to comment.