diff options
Diffstat (limited to 'src/module/Header.jsx')
-rw-r--r-- | src/module/Header.jsx | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/module/Header.jsx b/src/module/Header.jsx index 962328c..ef88948 100644 --- a/src/module/Header.jsx +++ b/src/module/Header.jsx | |||
@@ -1,4 +1,5 @@ | |||
1 | import React, {PropTypes} from 'react'; | 1 | import React, {PropTypes} from 'react'; |
2 | import createSelection from '../util/selection'; | ||
2 | 3 | ||
3 | const Header = React.createClass({ | 4 | const Header = React.createClass({ |
4 | propTypes: { | 5 | propTypes: { |
@@ -16,6 +17,7 @@ const Header = React.createClass({ | |||
16 | onClear: PropTypes.func, | 17 | onClear: PropTypes.func, |
17 | onEsc: PropTypes.func, | 18 | onEsc: PropTypes.func, |
18 | allowEmpty: PropTypes.bool, | 19 | allowEmpty: PropTypes.bool, |
20 | currentSelectPanel: PropTypes.string, | ||
19 | }, | 21 | }, |
20 | 22 | ||
21 | getInitialState() { | 23 | getInitialState() { |
@@ -27,9 +29,7 @@ const Header = React.createClass({ | |||
27 | }, | 29 | }, |
28 | 30 | ||
29 | componentDidMount() { | 31 | componentDidMount() { |
30 | this.timer = setTimeout(() => { | 32 | this.timer = setTimeout(this.selectRange, 0); |
31 | this.refs.input.focus(); | ||
32 | }, 0); | ||
33 | }, | 33 | }, |
34 | 34 | ||
35 | componentWillReceiveProps(nextProps) { | 35 | componentWillReceiveProps(nextProps) { |
@@ -40,6 +40,10 @@ const Header = React.createClass({ | |||
40 | }); | 40 | }); |
41 | }, | 41 | }, |
42 | 42 | ||
43 | componentDidUpdate() { | ||
44 | this.timer = setTimeout(this.selectRange, 0); | ||
45 | }, | ||
46 | |||
43 | componentWillUnmount() { | 47 | componentWillUnmount() { |
44 | clearTimeout(this.timer); | 48 | clearTimeout(this.timer); |
45 | }, | 49 | }, |
@@ -139,6 +143,27 @@ const Header = React.createClass({ | |||
139 | placeholder={placeholder} onChange={this.onInputChange}/>); | 143 | placeholder={placeholder} onChange={this.onInputChange}/>); |
140 | }, | 144 | }, |
141 | 145 | ||
146 | selectRange() { | ||
147 | this.refs.input.focus(); | ||
148 | if (this.props.currentSelectPanel && this.refs.input.value) { | ||
149 | let selectionRangeStart = 0; | ||
150 | let selectionRangeEnd = 0; | ||
151 | if (this.props.currentSelectPanel === 'hour') { | ||
152 | selectionRangeStart = 0; | ||
153 | selectionRangeEnd = this.refs.input.value.indexOf(':'); | ||
154 | } else if (this.props.currentSelectPanel === 'minute') { | ||
155 | selectionRangeStart = this.refs.input.value.indexOf(':') + 1; | ||
156 | selectionRangeEnd = this.refs.input.value.lastIndexOf(':'); | ||
157 | } else if (this.props.currentSelectPanel === 'second') { | ||
158 | selectionRangeStart = this.refs.input.value.lastIndexOf(':') + 1; | ||
159 | selectionRangeEnd = this.refs.input.value.length; | ||
160 | } | ||
161 | if (selectionRangeEnd - selectionRangeStart === 2) { | ||
162 | createSelection(this.refs.input, selectionRangeStart, selectionRangeEnd); | ||
163 | } | ||
164 | } | ||
165 | }, | ||
166 | |||
142 | render() { | 167 | render() { |
143 | const { prefixCls } = this.props; | 168 | const { prefixCls } = this.props; |
144 | return ( | 169 | return ( |