diff options
author | MG12 <wuzhao.mail@gmail.com> | 2015-12-14 00:50:41 +0800 |
---|---|---|
committer | MG12 <wuzhao.mail@gmail.com> | 2015-12-14 00:50:41 +0800 |
commit | 71bd9bc11f2ca6068f7977ff3511b2798f73d0c6 (patch) | |
tree | e24404e929db29204fa008546377351d314f9480 | |
parent | 0e62bf0b7bdc260e882fd185492939cbaed04d56 (diff) | |
download | time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.gz time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.tar.zst time-picker-71bd9bc11f2ca6068f7977ff3511b2798f73d0c6.zip |
update disabled options
-rw-r--r-- | examples/disabled.js | 34 | ||||
-rw-r--r-- | examples/hidden.js | 6 | ||||
-rw-r--r-- | src/TimePicker.jsx | 12 | ||||
-rw-r--r-- | src/module/Combobox.jsx | 22 | ||||
-rw-r--r-- | src/module/Header.jsx | 15 | ||||
-rw-r--r-- | src/module/Panel.jsx | 19 | ||||
-rw-r--r-- | tests/Header.spec.jsx | 70 | ||||
-rw-r--r-- | tests/Select.spec.jsx | 71 |
8 files changed, 174 insertions, 75 deletions
diff --git a/examples/disabled.js b/examples/disabled.js index 24d0068..633b8db 100644 --- a/examples/disabled.js +++ b/examples/disabled.js | |||
@@ -20,17 +20,47 @@ const formatter = new DateTimeFormat(str); | |||
20 | const now = new GregorianCalendar(zhCn); | 20 | const now = new GregorianCalendar(zhCn); |
21 | now.setTime(Date.now()); | 21 | now.setTime(Date.now()); |
22 | 22 | ||
23 | function generateOptions(length, excludedOptions) { | ||
24 | const arr = []; | ||
25 | for (let value = 0; value < length; value++) { | ||
26 | if (excludedOptions.indexOf(value) < 0) { | ||
27 | arr.push(value); | ||
28 | } | ||
29 | } | ||
30 | return arr; | ||
31 | } | ||
32 | |||
23 | function onChange(value) { | 33 | function onChange(value) { |
24 | console.log(value && formatter.format(value)); | 34 | console.log(value && formatter.format(value)); |
25 | } | 35 | } |
26 | 36 | ||
37 | function disabledHours() { | ||
38 | return [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]; | ||
39 | } | ||
40 | |||
41 | function disabledMinutes(h) { | ||
42 | switch (h) { | ||
43 | case 9: | ||
44 | return generateOptions(60, [30]); | ||
45 | case 21: | ||
46 | return generateOptions(60, [0]); | ||
47 | default: | ||
48 | return generateOptions(60, [0, 30]); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | function disabledSeconds(h, m) { | ||
53 | return [h + m % 60]; | ||
54 | } | ||
55 | |||
27 | ReactDom.render( | 56 | ReactDom.render( |
28 | <TimePicker formatter={formatter} locale={TimePickerLocale} | 57 | <TimePicker formatter={formatter} locale={TimePickerLocale} |
29 | showSecond={showSecond} | 58 | showSecond={showSecond} |
30 | defaultValue={now} | 59 | defaultValue={now} |
31 | className="xxx" | 60 | className="xxx" |
32 | onChange={onChange} | 61 | onChange={onChange} |
33 | disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} | 62 | disabledHours={disabledHours} |
34 | disabledMinutes={[0, 2, 4, 6, 8]} />, | 63 | disabledMinutes={disabledMinutes} |
64 | disabledSeconds={disabledSeconds} />, | ||
35 | document.getElementById('__react-content') | 65 | document.getElementById('__react-content') |
36 | ); | 66 | ); |
diff --git a/examples/hidden.js b/examples/hidden.js index 1084236..da366cc 100644 --- a/examples/hidden.js +++ b/examples/hidden.js | |||
@@ -30,8 +30,8 @@ ReactDom.render( | |||
30 | defaultValue={now} | 30 | defaultValue={now} |
31 | className="xxx" | 31 | className="xxx" |
32 | onChange={onChange} | 32 | onChange={onChange} |
33 | disabledHours={[0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} | 33 | disabledHours={() => [0, 1, 2, 3, 4, 5, 6, 7, 8, 22, 23]} |
34 | disabledMinutes={[0, 2, 4, 6, 8]} | 34 | disabledMinutes={() => [0, 2, 4, 6, 8]} |
35 | hideDisabledOptions={true} />, | 35 | hideDisabledOptions />, |
36 | document.getElementById('__react-content') | 36 | document.getElementById('__react-content') |
37 | ); | 37 | ); |
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index fb855e2..ad4e834 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx | |||
@@ -34,9 +34,9 @@ const Picker = React.createClass({ | |||
34 | style: PropTypes.object, | 34 | style: PropTypes.object, |
35 | className: PropTypes.string, | 35 | className: PropTypes.string, |
36 | showSecond: PropTypes.bool, | 36 | showSecond: PropTypes.bool, |
37 | disabledHours: PropTypes.array, | 37 | disabledHours: PropTypes.func, |
38 | disabledMinutes: PropTypes.array, | 38 | disabledMinutes: PropTypes.func, |
39 | disabledSeconds: PropTypes.array, | 39 | disabledSeconds: PropTypes.func, |
40 | hideDisabledOptions: PropTypes.bool, | 40 | hideDisabledOptions: PropTypes.bool, |
41 | onChange: PropTypes.func, | 41 | onChange: PropTypes.func, |
42 | onOpen: PropTypes.func, | 42 | onOpen: PropTypes.func, |
@@ -55,9 +55,9 @@ const Picker = React.createClass({ | |||
55 | allowEmpty: true, | 55 | allowEmpty: true, |
56 | showHour: true, | 56 | showHour: true, |
57 | showSecond: true, | 57 | showSecond: true, |
58 | disabledHours: null, | 58 | disabledHours: noop, |
59 | disabledMinutes: null, | 59 | disabledMinutes: noop, |
60 | disabledSeconds: null, | 60 | disabledSeconds: noop, |
61 | hideDisabledOptions: false, | 61 | hideDisabledOptions: false, |
62 | placement: 'bottomLeft', | 62 | placement: 'bottomLeft', |
63 | onChange: noop, | 63 | onChange: noop, |
diff --git a/src/module/Combobox.jsx b/src/module/Combobox.jsx index 1e172a7..7374b39 100644 --- a/src/module/Combobox.jsx +++ b/src/module/Combobox.jsx | |||
@@ -31,9 +31,9 @@ const Combobox = React.createClass({ | |||
31 | hourOptions: PropTypes.array, | 31 | hourOptions: PropTypes.array, |
32 | minuteOptions: PropTypes.array, | 32 | minuteOptions: PropTypes.array, |
33 | secondOptions: PropTypes.array, | 33 | secondOptions: PropTypes.array, |
34 | disabledHours: PropTypes.array, | 34 | disabledHours: PropTypes.func, |
35 | disabledMinutes: PropTypes.array, | 35 | disabledMinutes: PropTypes.func, |
36 | disabledSeconds: PropTypes.array, | 36 | disabledSeconds: PropTypes.func, |
37 | onCurrentSelectPanelChange: PropTypes.func, | 37 | onCurrentSelectPanelChange: PropTypes.func, |
38 | }, | 38 | }, |
39 | 39 | ||
@@ -64,10 +64,12 @@ const Combobox = React.createClass({ | |||
64 | if (!showHour) { | 64 | if (!showHour) { |
65 | return null; | 65 | return null; |
66 | } | 66 | } |
67 | const disabledOptions = disabledHours(); | ||
68 | |||
67 | return ( | 69 | return ( |
68 | <Select | 70 | <Select |
69 | prefixCls={prefixCls} | 71 | prefixCls={prefixCls} |
70 | options={hourOptions.map(option => formatOption(option, disabledHours))} | 72 | options={hourOptions.map(option => formatOption(option, disabledOptions))} |
71 | selectedIndex={hourOptions.indexOf(hour)} | 73 | selectedIndex={hourOptions.indexOf(hour)} |
72 | type="hour" | 74 | type="hour" |
73 | onSelect={this.onItemChange} | 75 | onSelect={this.onItemChange} |
@@ -77,11 +79,13 @@ const Combobox = React.createClass({ | |||
77 | }, | 79 | }, |
78 | 80 | ||
79 | getMinuteSelect(minute) { | 81 | getMinuteSelect(minute) { |
80 | const { prefixCls, minuteOptions, disabledMinutes } = this.props; | 82 | const { prefixCls, minuteOptions, disabledMinutes, value } = this.props; |
83 | const disabledOptions = disabledMinutes(value.getHourOfDay()); | ||
84 | |||
81 | return ( | 85 | return ( |
82 | <Select | 86 | <Select |
83 | prefixCls={prefixCls} | 87 | prefixCls={prefixCls} |
84 | options={minuteOptions.map(option => formatOption(option, disabledMinutes))} | 88 | options={minuteOptions.map(option => formatOption(option, disabledOptions))} |
85 | selectedIndex={minuteOptions.indexOf(minute)} | 89 | selectedIndex={minuteOptions.indexOf(minute)} |
86 | type="minute" | 90 | type="minute" |
87 | onSelect={this.onItemChange} | 91 | onSelect={this.onItemChange} |
@@ -91,14 +95,16 @@ const Combobox = React.createClass({ | |||
91 | }, | 95 | }, |
92 | 96 | ||
93 | getSecondSelect(second) { | 97 | getSecondSelect(second) { |
94 | const { prefixCls, secondOptions, disabledSeconds, showSecond } = this.props; | 98 | const { prefixCls, secondOptions, disabledSeconds, showSecond, value } = this.props; |
95 | if (!showSecond) { | 99 | if (!showSecond) { |
96 | return null; | 100 | return null; |
97 | } | 101 | } |
102 | const disabledOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); | ||
103 | |||
98 | return ( | 104 | return ( |
99 | <Select | 105 | <Select |
100 | prefixCls={prefixCls} | 106 | prefixCls={prefixCls} |
101 | options={secondOptions.map(option => formatOption(option, disabledSeconds))} | 107 | options={secondOptions.map(option => formatOption(option, disabledOptions))} |
102 | selectedIndex={secondOptions.indexOf(second)} | 108 | selectedIndex={secondOptions.indexOf(second)} |
103 | type="second" | 109 | type="second" |
104 | onSelect={this.onItemChange} | 110 | onSelect={this.onItemChange} |
diff --git a/src/module/Header.jsx b/src/module/Header.jsx index fec02af..9a048dc 100644 --- a/src/module/Header.jsx +++ b/src/module/Header.jsx | |||
@@ -13,9 +13,9 @@ const Header = React.createClass({ | |||
13 | hourOptions: PropTypes.array, | 13 | hourOptions: PropTypes.array, |
14 | minuteOptions: PropTypes.array, | 14 | minuteOptions: PropTypes.array, |
15 | secondOptions: PropTypes.array, | 15 | secondOptions: PropTypes.array, |
16 | disabledHours: PropTypes.array, | 16 | disabledHours: PropTypes.func, |
17 | disabledMinutes: PropTypes.array, | 17 | disabledMinutes: PropTypes.func, |
18 | disabledSeconds: PropTypes.array, | 18 | disabledSeconds: PropTypes.func, |
19 | onChange: PropTypes.func, | 19 | onChange: PropTypes.func, |
20 | onClear: PropTypes.func, | 20 | onClear: PropTypes.func, |
21 | onEsc: PropTypes.func, | 21 | onEsc: PropTypes.func, |
@@ -87,10 +87,13 @@ const Header = React.createClass({ | |||
87 | } | 87 | } |
88 | 88 | ||
89 | // if time value is disabled, response warning. | 89 | // if time value is disabled, response warning. |
90 | const disabledHourOptions = disabledHours(); | ||
91 | const disabledMinuteOptions = disabledMinutes(value.getHourOfDay()); | ||
92 | const disabledSecondOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); | ||
90 | if ( | 93 | if ( |
91 | (disabledHours && disabledHours.indexOf(value.getHourOfDay()) >= 0) || | 94 | (disabledHourOptions && disabledHourOptions.indexOf(value.getHourOfDay()) >= 0) || |
92 | (disabledMinutes && disabledMinutes.indexOf(value.getMinutes()) >= 0) || | 95 | (disabledMinuteOptions && disabledMinuteOptions.indexOf(value.getMinutes()) >= 0) || |
93 | (disabledSeconds && disabledSeconds.indexOf(value.getSeconds()) >= 0) | 96 | (disabledSecondOptions && disabledSecondOptions.indexOf(value.getSeconds()) >= 0) |
94 | ) { | 97 | ) { |
95 | this.setState({ | 98 | this.setState({ |
96 | invalid: true, | 99 | invalid: true, |
diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index 12d23f7..94d3842 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx | |||
@@ -24,9 +24,9 @@ const Panel = React.createClass({ | |||
24 | placeholder: PropTypes.string, | 24 | placeholder: PropTypes.string, |
25 | gregorianCalendarLocale: PropTypes.object, | 25 | gregorianCalendarLocale: PropTypes.object, |
26 | formatter: PropTypes.object, | 26 | formatter: PropTypes.object, |
27 | disabledHours: PropTypes.array, | 27 | disabledHours: PropTypes.func, |
28 | disabledMinutes: PropTypes.array, | 28 | disabledMinutes: PropTypes.func, |
29 | disabledSeconds: PropTypes.array, | 29 | disabledSeconds: PropTypes.func, |
30 | hideDisabledOptions: PropTypes.bool, | 30 | hideDisabledOptions: PropTypes.bool, |
31 | onChange: PropTypes.func, | 31 | onChange: PropTypes.func, |
32 | onEsc: PropTypes.func, | 32 | onEsc: PropTypes.func, |
@@ -40,10 +40,6 @@ const Panel = React.createClass({ | |||
40 | 40 | ||
41 | getDefaultProps() { | 41 | getDefaultProps() { |
42 | return { | 42 | return { |
43 | disabledHours: null, | ||
44 | disabledMinutes: null, | ||
45 | disabledSeconds: null, | ||
46 | hideDisabledOptions: false, | ||
47 | onChange: noop, | 43 | onChange: noop, |
48 | onClear: noop, | 44 | onClear: noop, |
49 | }; | 45 | }; |
@@ -81,9 +77,12 @@ const Panel = React.createClass({ | |||
81 | render() { | 77 | render() { |
82 | const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; | 78 | const { locale, prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; |
83 | const value = this.state.value; | 79 | const value = this.state.value; |
84 | const hourOptions = generateOptions(24, disabledHours, hideDisabledOptions); | 80 | const disabledHourOptions = disabledHours(); |
85 | const minuteOptions = generateOptions(60, disabledMinutes, hideDisabledOptions); | 81 | const disabledMinuteOptions = disabledMinutes(value.getHourOfDay()); |
86 | const secondOptions = generateOptions(60, disabledSeconds, hideDisabledOptions); | 82 | const disabledSecondOptions = disabledSeconds(value.getHourOfDay(), value.getMinutes()); |
83 | const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); | ||
84 | const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); | ||
85 | const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); | ||
87 | 86 | ||
88 | return ( | 87 | return ( |
89 | <div className={`${prefixCls}-inner`}> | 88 | <div className={`${prefixCls}-inner`}> |
diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx index 18d61c5..e992279 100644 --- a/tests/Header.spec.jsx +++ b/tests/Header.spec.jsx | |||
@@ -123,7 +123,12 @@ describe('Header', () => { | |||
123 | 123 | ||
124 | it('carry disabled correctly', (done) => { | 124 | it('carry disabled correctly', (done) => { |
125 | const picker = renderPicker({ | 125 | const picker = renderPicker({ |
126 | disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] | 126 | disabledMinutes(h) { |
127 | return [h]; | ||
128 | }, | ||
129 | disabledSeconds(h, m) { | ||
130 | return [h + m % 60]; | ||
131 | }, | ||
127 | }); | 132 | }); |
128 | expect(picker.state.open).not.to.be.ok(); | 133 | expect(picker.state.open).not.to.be.ok(); |
129 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 134 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; |
@@ -138,22 +143,39 @@ describe('Header', () => { | |||
138 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 143 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); |
139 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 144 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); |
140 | 145 | ||
141 | ReactDOM.findDOMNode(header).value = '12:15:78'; | 146 | ReactDOM.findDOMNode(header).value = '10:09:78'; |
142 | Simulate.change(header); | 147 | Simulate.change(header); |
143 | setTimeout(next, 100); | 148 | setTimeout(next, 100); |
144 | }, (next) => { | 149 | }, (next) => { |
145 | expect(picker.state.open).to.be(true); | 150 | expect(picker.state.open).to.be(true); |
146 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 151 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); |
147 | expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); | 152 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); |
148 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 153 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); |
149 | 154 | ||
150 | ReactDOM.findDOMNode(header).value = '12:10:78'; | 155 | ReactDOM.findDOMNode(header).value = '10:10:78'; |
156 | Simulate.change(header); | ||
157 | setTimeout(next, 100); | ||
158 | }, (next) => { | ||
159 | expect(picker.state.open).to.be(true); | ||
160 | expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); | ||
161 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | ||
162 | |||
163 | ReactDOM.findDOMNode(header).value = '10:09:19'; | ||
164 | Simulate.change(header); | ||
165 | setTimeout(next, 100); | ||
166 | }, (next) => { | ||
167 | expect(picker.state.open).to.be(true); | ||
168 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | ||
169 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); | ||
170 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | ||
171 | |||
172 | ReactDOM.findDOMNode(header).value = '10:09:20'; | ||
151 | Simulate.change(header); | 173 | Simulate.change(header); |
152 | setTimeout(next, 100); | 174 | setTimeout(next, 100); |
153 | }, (next) => { | 175 | }, (next) => { |
154 | expect(picker.state.open).to.be(true); | 176 | expect(picker.state.open).to.be(true); |
155 | expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); | 177 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); |
156 | expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); | 178 | expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); |
157 | 179 | ||
158 | next(); | 180 | next(); |
159 | }], () => { | 181 | }], () => { |
@@ -163,8 +185,13 @@ describe('Header', () => { | |||
163 | 185 | ||
164 | it('carry hidden correctly', (done) => { | 186 | it('carry hidden correctly', (done) => { |
165 | const picker = renderPicker({ | 187 | const picker = renderPicker({ |
166 | disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22], | 188 | disabledMinutes(h) { |
167 | hideDisabledOptions: true | 189 | return [h]; |
190 | }, | ||
191 | disabledSeconds(h, m) { | ||
192 | return [h + m % 60]; | ||
193 | }, | ||
194 | hideDisabledOptions: true, | ||
168 | }); | 195 | }); |
169 | expect(picker.state.open).not.to.be.ok(); | 196 | expect(picker.state.open).not.to.be.ok(); |
170 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 197 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; |
@@ -179,22 +206,39 @@ describe('Header', () => { | |||
179 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 206 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); |
180 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 207 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); |
181 | 208 | ||
182 | ReactDOM.findDOMNode(header).value = '12:15:78'; | 209 | ReactDOM.findDOMNode(header).value = '10:09:78'; |
183 | Simulate.change(header); | 210 | Simulate.change(header); |
184 | setTimeout(next, 100); | 211 | setTimeout(next, 100); |
185 | }, (next) => { | 212 | }, (next) => { |
186 | expect(picker.state.open).to.be(true); | 213 | expect(picker.state.open).to.be(true); |
187 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | 214 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); |
188 | expect(ReactDOM.findDOMNode(header).value).to.be('12:15:78'); | 215 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:78'); |
189 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 216 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); |
190 | 217 | ||
191 | ReactDOM.findDOMNode(header).value = '12:10:78'; | 218 | ReactDOM.findDOMNode(header).value = '10:10:78'; |
219 | Simulate.change(header); | ||
220 | setTimeout(next, 100); | ||
221 | }, (next) => { | ||
222 | expect(picker.state.open).to.be(true); | ||
223 | expect(ReactDOM.findDOMNode(header).value).to.be('10:11:18'); | ||
224 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | ||
225 | |||
226 | ReactDOM.findDOMNode(header).value = '10:09:19'; | ||
227 | Simulate.change(header); | ||
228 | setTimeout(next, 100); | ||
229 | }, (next) => { | ||
230 | expect(picker.state.open).to.be(true); | ||
231 | expect(ReactDOM.findDOMNode(header).className).to.contain('rc-time-picker-panel-input-invalid'); | ||
232 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:19'); | ||
233 | expect(ReactDOM.findDOMNode(input).value).to.be('10:11:18'); | ||
234 | |||
235 | ReactDOM.findDOMNode(header).value = '10:09:20'; | ||
192 | Simulate.change(header); | 236 | Simulate.change(header); |
193 | setTimeout(next, 100); | 237 | setTimeout(next, 100); |
194 | }, (next) => { | 238 | }, (next) => { |
195 | expect(picker.state.open).to.be(true); | 239 | expect(picker.state.open).to.be(true); |
196 | expect(ReactDOM.findDOMNode(header).value).to.be('12:11:18'); | 240 | expect(ReactDOM.findDOMNode(header).value).to.be('10:09:20'); |
197 | expect(ReactDOM.findDOMNode(input).value).to.be('12:11:18'); | 241 | expect(ReactDOM.findDOMNode(input).value).to.be('10:09:20'); |
198 | 242 | ||
199 | next(); | 243 | next(); |
200 | }], () => { | 244 | }], () => { |
diff --git a/tests/Select.spec.jsx b/tests/Select.spec.jsx index 6dd7796..f7717c7 100644 --- a/tests/Select.spec.jsx +++ b/tests/Select.spec.jsx | |||
@@ -29,7 +29,7 @@ describe('Select', () => { | |||
29 | formatter={formatter} | 29 | formatter={formatter} |
30 | locale={TimePickerLocale} | 30 | locale={TimePickerLocale} |
31 | showSecond={showSecond} | 31 | showSecond={showSecond} |
32 | defaultValue={formatTime('01:02:03', formatter)} | 32 | defaultValue={formatTime('01:02:04', formatter)} |
33 | {...props} | 33 | {...props} |
34 | />, container); | 34 | />, container); |
35 | } | 35 | } |
@@ -90,8 +90,8 @@ describe('Select', () => { | |||
90 | expect(picker.state.open).to.be(true); | 90 | expect(picker.state.open).to.be(true); |
91 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 91 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; |
92 | expect(header).to.be.ok(); | 92 | expect(header).to.be.ok(); |
93 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 93 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
94 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 94 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
95 | 95 | ||
96 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 96 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; |
97 | const option = selector.getElementsByTagName('li')[19]; | 97 | const option = selector.getElementsByTagName('li')[19]; |
@@ -100,8 +100,8 @@ describe('Select', () => { | |||
100 | }, (next) => { | 100 | }, (next) => { |
101 | expect(change).to.be.ok(); | 101 | expect(change).to.be.ok(); |
102 | expect(change.getHourOfDay()).to.be(19); | 102 | expect(change.getHourOfDay()).to.be(19); |
103 | expect(ReactDOM.findDOMNode(header).value).to.be('19:02:03'); | 103 | expect(ReactDOM.findDOMNode(header).value).to.be('19:02:04'); |
104 | expect(ReactDOM.findDOMNode(input).value).to.be('19:02:03'); | 104 | expect(ReactDOM.findDOMNode(input).value).to.be('19:02:04'); |
105 | expect(picker.state.open).to.be.ok(); | 105 | expect(picker.state.open).to.be.ok(); |
106 | 106 | ||
107 | next(); | 107 | next(); |
@@ -129,8 +129,8 @@ describe('Select', () => { | |||
129 | expect(picker.state.open).to.be(true); | 129 | expect(picker.state.open).to.be(true); |
130 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 130 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; |
131 | expect(header).to.be.ok(); | 131 | expect(header).to.be.ok(); |
132 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 132 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
133 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 133 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
134 | 134 | ||
135 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 135 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; |
136 | const option = selector.getElementsByTagName('li')[19]; | 136 | const option = selector.getElementsByTagName('li')[19]; |
@@ -139,8 +139,8 @@ describe('Select', () => { | |||
139 | }, (next) => { | 139 | }, (next) => { |
140 | expect(change).to.be.ok(); | 140 | expect(change).to.be.ok(); |
141 | expect(change.getMinutes()).to.be(19); | 141 | expect(change.getMinutes()).to.be(19); |
142 | expect(ReactDOM.findDOMNode(header).value).to.be('01:19:03'); | 142 | expect(ReactDOM.findDOMNode(header).value).to.be('01:19:04'); |
143 | expect(ReactDOM.findDOMNode(input).value).to.be('01:19:03'); | 143 | expect(ReactDOM.findDOMNode(input).value).to.be('01:19:04'); |
144 | expect(picker.state.open).to.be.ok(); | 144 | expect(picker.state.open).to.be.ok(); |
145 | 145 | ||
146 | next(); | 146 | next(); |
@@ -168,8 +168,8 @@ describe('Select', () => { | |||
168 | expect(picker.state.open).to.be(true); | 168 | expect(picker.state.open).to.be(true); |
169 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 169 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; |
170 | expect(header).to.be.ok(); | 170 | expect(header).to.be.ok(); |
171 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 171 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
172 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 172 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
173 | 173 | ||
174 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; | 174 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; |
175 | const option = selector.getElementsByTagName('li')[19]; | 175 | const option = selector.getElementsByTagName('li')[19]; |
@@ -194,7 +194,12 @@ describe('Select', () => { | |||
194 | onChange(v) { | 194 | onChange(v) { |
195 | change = v; | 195 | change = v; |
196 | }, | 196 | }, |
197 | disabledMinutes: [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22] | 197 | disabledMinutes(h) { |
198 | return [h]; | ||
199 | }, | ||
200 | disabledSeconds(h, m) { | ||
201 | return [h + m % 60]; | ||
202 | }, | ||
198 | }); | 203 | }); |
199 | expect(picker.state.open).not.to.be.ok(); | 204 | expect(picker.state.open).not.to.be.ok(); |
200 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 205 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; |
@@ -208,17 +213,27 @@ describe('Select', () => { | |||
208 | expect(picker.state.open).to.be(true); | 213 | expect(picker.state.open).to.be(true); |
209 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 214 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; |
210 | expect(header).to.be.ok(); | 215 | expect(header).to.be.ok(); |
211 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 216 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
212 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 217 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
213 | 218 | ||
214 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 219 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; |
215 | const option = selector.getElementsByTagName('li')[6]; | 220 | const option = selector.getElementsByTagName('li')[1]; |
216 | Simulate.click(option); | 221 | Simulate.click(option); |
217 | setTimeout(next, 100); | 222 | setTimeout(next, 100); |
218 | }, (next) => { | 223 | }, (next) => { |
219 | expect(change).not.to.be.ok(); | 224 | expect(change).not.to.be.ok(); |
220 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 225 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
221 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 226 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
227 | expect(picker.state.open).to.be.ok(); | ||
228 | |||
229 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[2]; | ||
230 | const option = selector.getElementsByTagName('li')[3]; | ||
231 | Simulate.click(option); | ||
232 | setTimeout(next, 100); | ||
233 | }, (next) => { | ||
234 | expect(change).not.to.be.ok(); | ||
235 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); | ||
236 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); | ||
222 | expect(picker.state.open).to.be.ok(); | 237 | expect(picker.state.open).to.be.ok(); |
223 | 238 | ||
224 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; | 239 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[1]; |
@@ -228,8 +243,8 @@ describe('Select', () => { | |||
228 | }, (next) => { | 243 | }, (next) => { |
229 | expect(change).to.be.ok(); | 244 | expect(change).to.be.ok(); |
230 | expect(change.getMinutes()).to.be(7); | 245 | expect(change.getMinutes()).to.be(7); |
231 | expect(ReactDOM.findDOMNode(header).value).to.be('01:07:03'); | 246 | expect(ReactDOM.findDOMNode(header).value).to.be('01:07:04'); |
232 | expect(ReactDOM.findDOMNode(input).value).to.be('01:07:03'); | 247 | expect(ReactDOM.findDOMNode(input).value).to.be('01:07:04'); |
233 | expect(picker.state.open).to.be.ok(); | 248 | expect(picker.state.open).to.be.ok(); |
234 | 249 | ||
235 | next(); | 250 | next(); |
@@ -244,8 +259,10 @@ describe('Select', () => { | |||
244 | onChange(v) { | 259 | onChange(v) { |
245 | change = v; | 260 | change = v; |
246 | }, | 261 | }, |
247 | disabledHours: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], | 262 | disabledHours() { |
248 | hideDisabledOptions: true | 263 | return [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]; |
264 | }, | ||
265 | hideDisabledOptions: true, | ||
249 | }); | 266 | }); |
250 | expect(picker.state.open).not.to.be.ok(); | 267 | expect(picker.state.open).not.to.be.ok(); |
251 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; | 268 | const input = TestUtils.scryRenderedDOMComponentsWithClass(picker, 'rc-time-picker-input')[0]; |
@@ -259,8 +276,8 @@ describe('Select', () => { | |||
259 | expect(picker.state.open).to.be(true); | 276 | expect(picker.state.open).to.be(true); |
260 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; | 277 | header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-input')[0]; |
261 | expect(header).to.be.ok(); | 278 | expect(header).to.be.ok(); |
262 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:03'); | 279 | expect(ReactDOM.findDOMNode(header).value).to.be('01:02:04'); |
263 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:03'); | 280 | expect(ReactDOM.findDOMNode(input).value).to.be('01:02:04'); |
264 | 281 | ||
265 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 282 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; |
266 | const option = selector.getElementsByTagName('li')[3]; | 283 | const option = selector.getElementsByTagName('li')[3]; |
@@ -269,8 +286,8 @@ describe('Select', () => { | |||
269 | }, (next) => { | 286 | }, (next) => { |
270 | expect(change).to.be.ok(); | 287 | expect(change).to.be.ok(); |
271 | expect(change.getHourOfDay()).to.be(6); | 288 | expect(change.getHourOfDay()).to.be(6); |
272 | expect(ReactDOM.findDOMNode(header).value).to.be('06:02:03'); | 289 | expect(ReactDOM.findDOMNode(header).value).to.be('06:02:04'); |
273 | expect(ReactDOM.findDOMNode(input).value).to.be('06:02:03'); | 290 | expect(ReactDOM.findDOMNode(input).value).to.be('06:02:04'); |
274 | expect(picker.state.open).to.be.ok(); | 291 | expect(picker.state.open).to.be.ok(); |
275 | 292 | ||
276 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; | 293 | const selector = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance, 'rc-time-picker-panel-select')[0]; |
@@ -280,8 +297,8 @@ describe('Select', () => { | |||
280 | }, (next) => { | 297 | }, (next) => { |
281 | expect(change).to.be.ok(); | 298 | expect(change).to.be.ok(); |
282 | expect(change.getHourOfDay()).to.be(8); | 299 | expect(change.getHourOfDay()).to.be(8); |
283 | expect(ReactDOM.findDOMNode(header).value).to.be('08:02:03'); | 300 | expect(ReactDOM.findDOMNode(header).value).to.be('08:02:04'); |
284 | expect(ReactDOM.findDOMNode(input).value).to.be('08:02:03'); | 301 | expect(ReactDOM.findDOMNode(input).value).to.be('08:02:04'); |
285 | expect(picker.state.open).to.be.ok(); | 302 | expect(picker.state.open).to.be.ok(); |
286 | 303 | ||
287 | next(); | 304 | next(); |