diff --git a/src/components/FooterToolbar/index.js b/src/components/FooterToolbar/index.js index d5ce75b8dc642c9628cb94736ca8c549967c54cc..d43f72fb45315521f9b5cd5a71589228f8d66de8 100644 --- a/src/components/FooterToolbar/index.js +++ b/src/components/FooterToolbar/index.js @@ -1,12 +1,44 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import classNames from 'classnames'; import styles from './index.less'; export default class FooterToolbar extends Component { + static contextTypes = { + isMobile: PropTypes.bool, + }; + + state = { + width: undefined, + }; + + componentDidMount() { + window.addEventListener('resize', this.resizeFooterToolbar); + this.resizeFooterToolbar(); + } + + componentWillUnmount() { + window.removeEventListener('resize', this.resizeFooterToolbar); + } + + resizeFooterToolbar = () => { + const sider = document.querySelector('.ant-layout-sider'); + if (sider == null) { + return; + } + const { isMobile } = this.context; + const width = isMobile ? null : `calc(100% - ${sider.style.width})`; + const { width: stateWidth } = this.state; + if (stateWidth !== width) { + this.setState({ width }); + } + }; + render() { const { children, className, extra, ...restProps } = this.props; + const { width } = this.state; return ( -
+
{extra}
{children}
diff --git a/src/routes/Forms/AdvancedForm.js b/src/routes/Forms/AdvancedForm.js index 6ab2bfb9a29c15f183b4ff2e7d7c899a592bcb2c..94bc3c54712d1254074e1ad71c85e0a4f342f097 100644 --- a/src/routes/Forms/AdvancedForm.js +++ b/src/routes/Forms/AdvancedForm.js @@ -58,29 +58,7 @@ const tableData = [ ]; class AdvancedForm extends PureComponent { - state = { - width: '100%', - }; - - componentDidMount() { - window.addEventListener('resize', this.resizeFooterToolbar); - } - - componentWillUnmount() { - window.removeEventListener('resize', this.resizeFooterToolbar); - } - - resizeFooterToolbar = () => { - const sider = document.querySelectorAll('.ant-layout-sider')[0]; - const width = `calc(100% - ${sider.style.width})`; - const { width: stateWidth } = this.state; - if (stateWidth !== width) { - this.setState({ width }); - } - }; - render() { - const { width: stateWidth } = this.state; const { form, dispatch, submitting } = this.props; const { getFieldDecorator, validateFieldsAndScroll, getFieldsError } = form; const validate = () => { @@ -289,7 +267,7 @@ class AdvancedForm extends PureComponent { initialValue: tableData, })()} - + {getErrorInfo()}