]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Header.jsx
add focusOnOpen option (#61)
[github/fretlink/time-picker.git] / src / Header.jsx
index 91e8549e14664555290a905a8b0102cddd27f808..9e80a9ccd18e738161a44838767e166c35717352 100644 (file)
@@ -22,6 +22,7 @@ class Header extends Component {
     allowEmpty: PropTypes.bool,
     defaultOpenValue: PropTypes.object,
     currentSelectPanel: PropTypes.string,
+    focusOnOpen: PropTypes.bool,
   };
 
   constructor(props) {
@@ -33,6 +34,14 @@ class Header extends Component {
     };
   }
 
+  componentDidMount() {
+    if (this.props.focusOnOpen) {
+      // Wait one frame for the panel to be positioned before focusing
+      const requestAnimationFrame = (window.requestAnimationFrame || window.setTimeout);
+      requestAnimationFrame(() => this.refs.input.focus());
+    }
+  }
+
   componentWillReceiveProps(nextProps) {
     const { value, format } = nextProps;
     this.setState({