Commit 18c1ac60 authored by Mike's avatar Mike Committed by ι™ˆεΈ…

fix: unresponsive collapse btn on mobile (#3504)

parent 0b3ec67a
...@@ -9,6 +9,8 @@ import { getDefaultCollapsedSubMenus } from './SiderMenuUtils'; ...@@ -9,6 +9,8 @@ import { getDefaultCollapsedSubMenus } from './SiderMenuUtils';
const BaseMenu = React.lazy(() => import('./BaseMenu')); const BaseMenu = React.lazy(() => import('./BaseMenu'));
const { Sider } = Layout; const { Sider } = Layout;
let firstMount = true;
export default class SiderMenu extends PureComponent { export default class SiderMenu extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -17,6 +19,10 @@ export default class SiderMenu extends PureComponent { ...@@ -17,6 +19,10 @@ export default class SiderMenu extends PureComponent {
}; };
} }
componentDidMount() {
firstMount = false;
}
static getDerivedStateFromProps(props, state) { static getDerivedStateFromProps(props, state) {
const { pathname, flatMenuKeysLen } = state; const { pathname, flatMenuKeysLen } = state;
if ( if (
...@@ -50,7 +56,7 @@ export default class SiderMenu extends PureComponent { ...@@ -50,7 +56,7 @@ export default class SiderMenu extends PureComponent {
}; };
render() { render() {
const { logo, collapsed, onCollapse, fixSiderbar, theme } = this.props; const { logo, collapsed, onCollapse, fixSiderbar, theme, isMobile } = this.props;
const { openKeys } = this.state; const { openKeys } = this.state;
const defaultProps = collapsed ? {} : { openKeys }; const defaultProps = collapsed ? {} : { openKeys };
...@@ -64,7 +70,11 @@ export default class SiderMenu extends PureComponent { ...@@ -64,7 +70,11 @@ export default class SiderMenu extends PureComponent {
collapsible collapsible
collapsed={collapsed} collapsed={collapsed}
breakpoint="lg" breakpoint="lg"
onCollapse={onCollapse} onCollapse={(collapse) => {
if (firstMount || !isMobile) {
onCollapse(collapse);
}
}}
width={256} width={256}
theme={theme} theme={theme}
className={siderClassName} className={siderClassName}
......
...@@ -75,15 +75,6 @@ class BasicLayout extends React.Component { ...@@ -75,15 +75,6 @@ class BasicLayout extends React.Component {
}); });
} }
componentDidUpdate(preProps) {
// After changing to phone mode,
// if collapsed is true, you need to click twice to display
const { collapsed, isMobile } = this.props;
if (isMobile && !preProps.isMobile && !collapsed) {
this.handleMenuCollapse(false);
}
}
getContext() { getContext() {
const { location, breadcrumbNameMap } = this.props; const { location, breadcrumbNameMap } = this.props;
return { return {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment