hourOptions: PropTypes.array,
minuteOptions: PropTypes.array,
secondOptions: PropTypes.array,
+ onCurrentSelectPanelChange: PropTypes.func,
},
onItemChange(type, itemValue) {
onChange(value);
},
+ onEnterSelectPanel(range) {
+ this.props.onCurrentSelectPanelChange(range);
+ },
+
getHourSelect(hour) {
const { prefixCls, hourOptions, showHour } = this.props;
if (!showHour) {
selectedIndex={hourOptions.indexOf(hour)}
type="hour"
onSelect={this.onItemChange}
+ onMouseEnter={this.onEnterSelectPanel.bind(this, 'hour')}
/>
);
},
selectedIndex={minuteOptions.indexOf(minute)}
type="minute"
onSelect={this.onItemChange}
+ onMouseEnter={this.onEnterSelectPanel.bind(this, 'minute')}
/>
);
},
- getSectionSelect(second) {
+ getSecondSelect(second) {
const { prefixCls, secondOptions, showSecond } = this.props;
if (!showSecond) {
return null;
selectedIndex={secondOptions.indexOf(second)}
type="second"
onSelect={this.onItemChange}
+ onMouseEnter={this.onEnterSelectPanel.bind(this, 'second')}
/>
);
},
<div className={`${prefixCls}-combobox`}>
{this.getHourSelect(value.getHourOfDay())}
{this.getMinuteSelect(value.getMinutes())}
- {this.getSectionSelect(value.getSeconds())}
+ {this.getSecondSelect(value.getSeconds())}
</div>
);
},
import React, {PropTypes} from 'react';
+import createSelection from '../util/selection';
const Header = React.createClass({
propTypes: {
onClear: PropTypes.func,
onEsc: PropTypes.func,
allowEmpty: PropTypes.bool,
+ currentSelectPanel: PropTypes.string,
},
getInitialState() {
},
componentDidMount() {
- this.timer = setTimeout(() => {
- this.refs.input.focus();
- }, 0);
+ this.timer = setTimeout(this.selectRange, 0);
},
componentWillReceiveProps(nextProps) {
});
},
+ componentDidUpdate() {
+ this.timer = setTimeout(this.selectRange, 0);
+ },
+
componentWillUnmount() {
clearTimeout(this.timer);
},
placeholder={placeholder} onChange={this.onInputChange}/>);
},
+ selectRange() {
+ this.refs.input.focus();
+ if (this.props.currentSelectPanel && this.refs.input.value) {
+ let selectionRangeStart = 0;
+ let selectionRangeEnd = 0;
+ if (this.props.currentSelectPanel === 'hour') {
+ selectionRangeStart = 0;
+ selectionRangeEnd = this.refs.input.value.indexOf(':');
+ } else if (this.props.currentSelectPanel === 'minute') {
+ selectionRangeStart = this.refs.input.value.indexOf(':') + 1;
+ selectionRangeEnd = this.refs.input.value.lastIndexOf(':');
+ } else if (this.props.currentSelectPanel === 'second') {
+ selectionRangeStart = this.refs.input.value.lastIndexOf(':') + 1;
+ selectionRangeEnd = this.refs.input.value.length;
+ }
+ if (selectionRangeEnd - selectionRangeStart === 2) {
+ createSelection(this.refs.input, selectionRangeStart, selectionRangeEnd);
+ }
+ }
+ },
+
render() {
const { prefixCls } = this.props;
return (
getInitialState() {
return {
value: this.props.value,
+ selectionRange: [],
};
},
this.props.onClear();
},
+ onCurrentSelectPanelChange(currentSelectPanel) {
+ this.setState({ currentSelectPanel });
+ },
+
render() {
const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props;
const value = this.state.value;
gregorianCalendarLocale={gregorianCalendarLocale}
locale={locale}
value={value}
+ currentSelectPanel={this.state.currentSelectPanel}
onEsc={this.props.onEsc}
formatter={formatter}
placeholder={placeholder}
hourOptions={hourOptions}
minuteOptions={minuteOptions}
secondOptions={secondOptions}
+ onCurrentSelectPanelChange={this.onCurrentSelectPanelChange}
/>
</div>
);
selectedIndex: PropTypes.number,
type: PropTypes.string,
onSelect: PropTypes.func,
+ onMouseEnter: PropTypes.func,
},
componentDidMount() {
const { prefixCls } = this.props;
return (
- <div className={`${prefixCls}-select`}>
+ <div className={`${prefixCls}-select`}
+ onMouseEnter={this.props.onMouseEnter}>
<ul ref="list">{this.getOptions()}</ul>
</div>
);
--- /dev/null
+export default function createSelection(field, start, end) {
+ if (field.createTextRange) {
+ const selRange = field.createTextRange();
+ selRange.collapse(true);
+ selRange.moveStart('character', start);
+ selRange.moveEnd('character', end);
+ selRange.select();
+ field.focus();
+ } else if (field.setSelectionRange) {
+ field.focus();
+ field.setSelectionRange(start, end);
+ } else if (typeof field.selectionStart !== 'undefined') {
+ field.selectionStart = start;
+ field.selectionEnd = end;
+ field.focus();
+ }
+}