From a14bb37ae55582dbb578ae8b3fdb4911b64a7c02 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 10 Feb 2017 11:46:57 +0800 Subject: [PATCH] site: can search with google now, close: #4814 --- site/theme/template/Layout/Header.jsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/site/theme/template/Layout/Header.jsx b/site/theme/template/Layout/Header.jsx index 5f5e0b3635..f4ed2d5710 100644 --- a/site/theme/template/Layout/Header.jsx +++ b/site/theme/template/Layout/Header.jsx @@ -7,6 +7,8 @@ import * as utils from '../utils'; import { version as antdVersion } from '../../../../package.json'; const Option = Select.Option; +const searchEngine = 'Google'; +const searchLink = 'https://www.google.com/#q=site:ant.design+'; export default class Header extends React.Component { static contextTypes = { @@ -37,8 +39,12 @@ export default class Header extends React.Component { } handleSearch = (value) => { - const { intl, router } = this.context; + if (value === searchEngine) { + window.location.href = `${searchLink}${this.state.inputValue}`; + return; + } + const { intl, router } = this.context; this.setState({ inputValue: '', }, () => { @@ -65,7 +71,9 @@ export default class Header extends React.Component { } handleSelectFilter = (value, option) => { - return option.props['data-label'].indexOf(value.toLowerCase()) > -1; + const optionValue = option.props['data-label']; + return optionValue === searchEngine || + optionValue.indexOf(value.toLowerCase()) > -1; } handleLangChange = () => { @@ -199,13 +207,13 @@ export default class Header extends React.Component { 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}