-import React, { PropTypes } from 'react';
+import React, { Component } from 'react';
+import PropTypes from 'prop-types';
import moment from 'moment';
-const Header = React.createClass({
- propTypes: {
+class Header extends Component {
+ static propTypes = {
format: PropTypes.string,
prefixCls: PropTypes.string,
disabledDate: PropTypes.func,
allowEmpty: PropTypes.bool,
defaultOpenValue: PropTypes.object,
currentSelectPanel: PropTypes.string,
- },
+ focusOnOpen: PropTypes.bool,
+ };
- getInitialState() {
- const { value, format } = this.props;
- return {
+ constructor(props) {
+ super(props);
+ const { value, format } = props;
+ this.state = {
str: value && value.format(format) || '',
invalid: false,
};
- },
+ }
+
+ 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;
str: value && value.format(format) || '',
invalid: false,
});
- },
+ }
- onInputChange(event) {
+ onInputChange = (event) => {
const str = event.target.value;
this.setState({
str,
this.setState({
invalid: false,
});
- },
+ }
- onKeyDown(e) {
+ onKeyDown = (e) => {
if (e.keyCode === 27) {
this.props.onEsc();
}
- },
+ }
- onClear() {
+ onClear = () => {
this.setState({ str: '' });
this.props.onClear();
- },
+ }
getClearButton() {
const { prefixCls, allowEmpty } = this.props;
title={this.props.clearText}
onMouseDown={this.onClear}
/>);
- },
+ }
getProtoValue() {
return this.props.value || this.props.defaultOpenValue;
- },
+ }
getInput() {
const { prefixCls, placeholder } = this.props;
onChange={this.onInputChange}
/>
);
- },
+ }
render() {
const { prefixCls } = this.props;
{this.getClearButton()}
</div>
);
- },
-});
+ }
+}
export default Header;