]> git.immae.eu Git - github/fretlink/time-picker.git/blobdiff - src/Header.jsx
Merge branch 'master' into focus-on-open
[github/fretlink/time-picker.git] / src / Header.jsx
index f6dd24157ae34e04fb43d66ff8e34475d4ae48c0..1520d25e3008b371efc66bebfe620d2cf5df4034 100644 (file)
@@ -22,6 +22,7 @@ class Header extends Component {
     allowEmpty: PropTypes.bool,
     defaultOpenValue: PropTypes.object,
     currentSelectPanel: PropTypes.string,
+    focusOnOpen: PropTypes.bool,
     onKeyDown: PropTypes.func,
   };
 
@@ -34,6 +35,17 @@ 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();
+        this.refs.input.select();
+      });
+    }
+  }
+
   componentWillReceiveProps(nextProps) {
     const { value, format } = nextProps;
     this.setState({