propTypes: {
formatter: PropTypes.object,
prefixCls: PropTypes.string,
- gregorianTimePickerLocale: PropTypes.object,
+ gregorianCalendarLocale: PropTypes.object,
locale: PropTypes.object,
disabledDate: PropTypes.func,
placeholder: PropTypes.string,
secondOptions: PropTypes.array,
onChange: PropTypes.func,
onClear: PropTypes.func,
- showClear: PropTypes.bool,
+ onEsc: PropTypes.func,
+ allowEmpty: PropTypes.bool,
},
getInitialState() {
};
},
+ componentDidMount() {
+ this.timer = setTimeout(() => {
+ this.refs.input.focus();
+ }, 0);
+ },
+
componentWillReceiveProps(nextProps) {
const value = nextProps.value;
this.setState({
});
},
+ componentWillUnmount() {
+ clearTimeout(this.timer);
+ },
+
onInputChange(event) {
const str = event.target.value;
this.setState({
str,
});
let value = null;
- const {formatter, gregorianTimePickerLocale, hourOptions, minuteOptions, secondOptions, onChange} = this.props;
+ const {formatter, gregorianCalendarLocale, hourOptions, minuteOptions, secondOptions, onChange, allowEmpty} = this.props;
if (str) {
const originalValue = this.props.value;
try {
value = formatter.parse(str, {
- locale: gregorianTimePickerLocale,
+ locale: gregorianCalendarLocale,
obeyCount: true,
});
} catch (ex) {
});
return;
}
- } else {
+ } else if (allowEmpty) {
onChange(null);
+ } else {
+ this.setState({
+ invalid: true,
+ });
+ return;
}
this.setState({
});
},
+ onKeyDown(e) {
+ if (e.keyCode === 27) {
+ this.props.onEsc();
+ }
+ },
+
onClear() {
this.setState({str: ''});
this.props.onClear();
},
getClearButton() {
- const { locale, prefixCls, showClear } = this.props;
- if (!showClear) {
+ const { locale, prefixCls, allowEmpty } = this.props;
+ if (!allowEmpty) {
return null;
}
- return <a className={`${prefixCls}-clear-btn`} role="button" title={locale.clear} onMouseDown={this.onClear} />;
+ return <a className={`${prefixCls}-clear-btn`} role="button" title={locale.clear} onMouseDown={this.onClear}/>;
},
getInput() {
const { prefixCls, placeholder } = this.props;
const { invalid, str } = this.state;
const invalidClass = invalid ? `${prefixCls}-input-invalid` : '';
- return <input className={`${prefixCls}-input ${invalidClass}`} value={str} placeholder={placeholder} onChange={this.onInputChange} />;
+ return (<input className={`${prefixCls}-input ${invalidClass}`}
+ ref="input"
+ onKeyDown={this.onKeyDown}
+ value={str}
+ placeholder={placeholder} onChange={this.onInputChange}/>);
},
render() {