diff --git a/docs/src/modules/components/AppSearch.js b/docs/src/modules/components/AppSearch.js index f9f14a6fd9a844..15f2e2a2db7737 100644 --- a/docs/src/modules/components/AppSearch.js +++ b/docs/src/modules/components/AppSearch.js @@ -1,6 +1,8 @@ import React from 'react'; +import keycode from 'keycode'; import compose from 'recompose/compose'; import pure from 'recompose/pure'; +import EventListener from 'react-event-listener'; import PropTypes from 'prop-types'; import withWidth, { isWidthUp } from 'material-ui/utils/withWidth'; import SearchIcon from 'material-ui-icons/Search'; @@ -114,24 +116,47 @@ const styles = theme => ({ }, }); -function AppSearch(props) { - const { classes, width } = props; +class AppSearch extends React.Component { + handleKeyDown = event => { + if ( + ['/', 's'].indexOf(keycode(event)) !== -1 && + document.activeElement.nodeName.toLowerCase() === 'body' && + document.activeElement !== this.input + ) { + event.preventDefault(); + this.input.focus(); + } + }; - if (!isWidthUp('sm', width)) { - removeDocsearch(); - return null; - } + input = null; + + render() { + const { classes, width } = this.props; - initDocsearch(); + if (!isWidthUp('sm', width)) { + removeDocsearch(); + return null; + } + + initDocsearch(); - return ( -
-
- -
- -
- ); + return ( + +
+
+ +
+ { + this.input = node; + }} + className={classes.input} + /> +
+
+ ); + } } AppSearch.propTypes = {