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

imporve the user experience of the official site #4457

Merged
merged 3 commits into from Jan 8, 2017
Merged
Changes from 2 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
38 changes: 35 additions & 3 deletions site/theme/template/Layout/Header.jsx
Expand Up @@ -14,6 +14,8 @@ export default class Header extends React.Component {
}

state = {
inputValue: '',
menuVisible: false,
menuMode: 'horizontal',
};

Expand All @@ -22,7 +24,9 @@ export default class Header extends React.Component {
require('enquire.js')
.register('only screen and (min-width: 320px) and (max-width: 1024px)', {
match: () => {
this.setState({ menuMode: 'inline' });
this.setState({ menuMode: 'inline' }, () => {
this.context.router.listen(this.handleHideMenu);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果用户不断的 resize 浏览器,match 方法会反复执行的,这样你就监听同一个事件多次了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否有方式可以取消监听?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

componentDidMount 里面监听不可以么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 componentDidMount 中监听可以实现,只是纯粹的想了解一下是否有取消监听的方式。

});
},
unmatch: () => {
this.setState({ menuMode: 'horizontal' });
Expand All @@ -33,7 +37,30 @@ export default class Header extends React.Component {

handleSearch = (value) => {
const { intl, router } = this.context;
router.push({ pathname: utils.getLocalizedPathname(`${value}/`, intl.locale === 'zh-CN') });

this.setState({
inputValue: '',
}, () => {
router.push({ pathname: utils.getLocalizedPathname(`${value}/`, intl.locale === 'zh-CN') });
});
}

handleInputChange = (value) => {
this.setState({
inputValue: value,
});
}

handleShowMenu = () => {
this.setState({
menuVisible: true,
});
}

handleHideMenu = () => {
this.setState({
menuVisible: false,
});
}

handleSelectFilter = (value, option) => {
Expand All @@ -46,6 +73,7 @@ export default class Header extends React.Component {
}

render() {
const { inputValue, menuMode, menuVisible } = this.state;
const { location, picked, isFirstScreen } = this.props;
const components = picked.components;
const module = location.pathname.replace(/(^\/|\/$)/g, '').split('/').slice(0, -1).join('/');
Expand Down Expand Up @@ -76,7 +104,6 @@ export default class Header extends React.Component {
'home-nav-white': !isFirstScreen,
});

const menuMode = this.state.menuMode;
const menu = [
<Button className="lang" type="ghost" size="small" onClick={this.handleLangChange} key="lang">
<FormattedMessage id="app.header.lang" />
Expand Down Expand Up @@ -123,11 +150,13 @@ export default class Header extends React.Component {
placement="bottomRight"
content={menu}
trigger="click"
visible={menuVisible}
arrowPointAtCenter
>
<Icon
className="nav-phone-icon"
type="menu"
onClick={this.handleShowMenu}
/>
</Popover> : null}
<Row>
Expand All @@ -141,12 +170,15 @@ export default class Header extends React.Component {
<div id="search-box">
<Select
combobox
value={inputValue}
dropdownStyle={{ display: inputValue ? 'block' : 'none' }}
dropdownClassName="component-select"
placeholder={searchPlaceholder}
optionFilterProp="data-label"
optionLabelProp="data-label"
filterOption={this.handleSelectFilter}
onSelect={this.handleSearch}
onSearch={this.handleInputChange}
getPopupContainer={trigger => trigger.parentNode}
>
{options}
Expand Down