aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
author偏右 <afc163@gmail.com>2017-10-22 16:20:47 +0800
committerGitHub <noreply@github.com>2017-10-22 16:20:47 +0800
commit6022baedfba9ec831d9fddaf7979771a71ca7fb8 (patch)
tree243b0a85cc29e79fb30c4d7cba51b0d09ec99125
parent35d5ed7815f4707c79565a45261ffadc21d604be (diff)
parente30387aba831b80ed9bcceafe1e2b66d69ee59cc (diff)
downloadtime-picker-6022baedfba9ec831d9fddaf7979771a71ca7fb8.tar.gz
time-picker-6022baedfba9ec831d9fddaf7979771a71ca7fb8.tar.zst
time-picker-6022baedfba9ec831d9fddaf7979771a71ca7fb8.zip
Merge pull request #68 from csenk/focus-blur
add focus/blur support.
-rw-r--r--src/TimePicker.jsx7
-rw-r--r--tests/TimePicker.spec.jsx36
2 files changed, 43 insertions, 0 deletions
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index 2c6a1f1..6e16457 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -42,6 +42,8 @@ export default class Picker extends Component {
42 onChange: PropTypes.func, 42 onChange: PropTypes.func,
43 onOpen: PropTypes.func, 43 onOpen: PropTypes.func,
44 onClose: PropTypes.func, 44 onClose: PropTypes.func,
45 onFocus: PropTypes.func,
46 onBlur: PropTypes.func,
45 addon: PropTypes.func, 47 addon: PropTypes.func,
46 name: PropTypes.string, 48 name: PropTypes.string,
47 autoComplete: PropTypes.string, 49 autoComplete: PropTypes.string,
@@ -69,6 +71,8 @@ export default class Picker extends Component {
69 onChange: noop, 71 onChange: noop,
70 onOpen: noop, 72 onOpen: noop,
71 onClose: noop, 73 onClose: noop,
74 onFocus: noop,
75 onBlur: noop,
72 addon: noop, 76 addon: noop,
73 use12Hours: false, 77 use12Hours: false,
74 }; 78 };
@@ -231,6 +235,7 @@ export default class Picker extends Component {
231 const { 235 const {
232 prefixCls, placeholder, placement, align, 236 prefixCls, placeholder, placement, align,
233 disabled, transitionName, style, className, getPopupContainer, name, autoComplete, 237 disabled, transitionName, style, className, getPopupContainer, name, autoComplete,
238 onFocus, onBlur,
234 } = this.props; 239 } = this.props;
235 const { open, value } = this.state; 240 const { open, value } = this.state;
236 const popupClassName = this.getPopupClassName(); 241 const popupClassName = this.getPopupClassName();
@@ -260,6 +265,8 @@ export default class Picker extends Component {
260 onKeyDown={this.onKeyDown} 265 onKeyDown={this.onKeyDown}
261 disabled={disabled} value={value && value.format(this.getFormat()) || ''} 266 disabled={disabled} value={value && value.format(this.getFormat()) || ''}
262 autoComplete={autoComplete} 267 autoComplete={autoComplete}
268 onFocus={onFocus}
269 onBlur={onBlur}
263 /> 270 />
264 <span className={`${prefixCls}-icon`}/> 271 <span className={`${prefixCls}-icon`}/>
265 </span> 272 </span>
diff --git a/tests/TimePicker.spec.jsx b/tests/TimePicker.spec.jsx
index 0dd6c10..d698e48 100644
--- a/tests/TimePicker.spec.jsx
+++ b/tests/TimePicker.spec.jsx
@@ -208,4 +208,40 @@ describe('TimePicker', () => {
208 }); 208 });
209 }); 209 });
210 }); 210 });
211
212 describe('other operations', () => {
213 it('focus/blur correctly', (done) => {
214 let focus = false;
215 let blur = false;
216
217 const picker = renderPicker({
218 onFocus: () => {
219 focus = true;
220 },
221 onBlur: () => {
222 blur = true;
223 },
224 });
225 expect(picker.state.open).not.to.be.ok();
226 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
227 'rc-time-picker-input')[0];
228
229 async.series([(next) => {
230 Simulate.focus(input);
231 setTimeout(next, 100);
232 }, (next) => {
233 expect(picker.state.open).to.be(false);
234
235 Simulate.blur(input);
236 setTimeout(next, 100);
237 }, (next) => {
238 expect(focus).to.be(true);
239 expect(blur).to.be(true);
240
241 next();
242 }], () => {
243 done();
244 });
245 });
246 });
211}); 247});