aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
author偏右 <afc163@gmail.com>2017-10-22 16:38:04 +0800
committerGitHub <noreply@github.com>2017-10-22 16:38:04 +0800
commitf0ac29c61df164ab3e867ef86137faa13d85a87f (patch)
tree6b1baa2373001870fa00310da36d46b21e8a43c8
parentcc2dca8a2bb0bf3b820903043be2586fb413c458 (diff)
parent8a116e355bfabda48537be06d21cf01fdceaa8b7 (diff)
downloadtime-picker-f0ac29c61df164ab3e867ef86137faa13d85a87f.tar.gz
time-picker-f0ac29c61df164ab3e867ef86137faa13d85a87f.tar.zst
time-picker-f0ac29c61df164ab3e867ef86137faa13d85a87f.zip
Merge branch 'master' into picker-step
-rw-r--r--README.md1
-rw-r--r--assets/index/Select.less4
-rw-r--r--examples/open.js7
-rw-r--r--src/Header.jsx12
-rw-r--r--src/Panel.jsx6
-rw-r--r--src/TimePicker.jsx5
-rw-r--r--tests/Header.spec.jsx28
7 files changed, 57 insertions, 6 deletions
diff --git a/README.md b/README.md
index 26e05fc..27a1aae 100644
--- a/README.md
+++ b/README.md
@@ -80,6 +80,7 @@ API
80| hourStep | Number | 1 | interval between hours in picker | 80| hourStep | Number | 1 | interval between hours in picker |
81| minuteStep | Number | 1 | interval between minutes in picker | 81| minuteStep | Number | 1 | interval between minutes in picker |
82| secondStep | Number | 1 | interval between seconds in picker | 82| secondStep | Number | 1 | interval between seconds in picker |
83| focusOnOpen | Boolean | false | automatically focus the input when the picker opens |
83 84
84## Test Case 85## Test Case
85 86
diff --git a/assets/index/Select.less b/assets/index/Select.less
index 8bec4a0..ecef8a8 100644
--- a/assets/index/Select.less
+++ b/assets/index/Select.less
@@ -6,7 +6,8 @@
6 margin-left: -1px; 6 margin-left: -1px;
7 box-sizing: border-box; 7 box-sizing: border-box;
8 width: 56px; 8 width: 56px;
9 overflow: hidden; 9 max-height: 144px;
10 overflow-y: auto;
10 position: relative; // Fix chrome weird render bug 11 position: relative; // Fix chrome weird render bug
11 12
12 &-active { 13 &-active {
@@ -28,7 +29,6 @@
28 margin: 0; 29 margin: 0;
29 padding: 0; 30 padding: 0;
30 width: 100%; 31 width: 100%;
31 max-height: 144px;
32 } 32 }
33 33
34 li { 34 li {
diff --git a/examples/open.js b/examples/open.js
index 8e4f5de..12d8a8d 100644
--- a/examples/open.js
+++ b/examples/open.js
@@ -22,7 +22,12 @@ class App extends React.Component {
22 return ( 22 return (
23 <div> 23 <div>
24 <button onClick={this.toggleOpen}>Toggle open</button> 24 <button onClick={this.toggleOpen}>Toggle open</button>
25 <TimePicker open={this.state.open} onOpen={this.setOpen} onClose={this.setOpen} /> 25 <TimePicker
26 open={this.state.open}
27 onOpen={this.setOpen}
28 onClose={this.setOpen}
29 focusOnOpen
30 />
26 </div> 31 </div>
27 ); 32 );
28 } 33 }
diff --git a/src/Header.jsx b/src/Header.jsx
index f6dd241..1520d25 100644
--- a/src/Header.jsx
+++ b/src/Header.jsx
@@ -22,6 +22,7 @@ class Header extends Component {
22 allowEmpty: PropTypes.bool, 22 allowEmpty: PropTypes.bool,
23 defaultOpenValue: PropTypes.object, 23 defaultOpenValue: PropTypes.object,
24 currentSelectPanel: PropTypes.string, 24 currentSelectPanel: PropTypes.string,
25 focusOnOpen: PropTypes.bool,
25 onKeyDown: PropTypes.func, 26 onKeyDown: PropTypes.func,
26 }; 27 };
27 28
@@ -34,6 +35,17 @@ class Header extends Component {
34 }; 35 };
35 } 36 }
36 37
38 componentDidMount() {
39 if (this.props.focusOnOpen) {
40 // Wait one frame for the panel to be positioned before focusing
41 const requestAnimationFrame = (window.requestAnimationFrame || window.setTimeout);
42 requestAnimationFrame(() => {
43 this.refs.input.focus();
44 this.refs.input.select();
45 });
46 }
47 }
48
37 componentWillReceiveProps(nextProps) { 49 componentWillReceiveProps(nextProps) {
38 const { value, format } = nextProps; 50 const { value, format } = nextProps;
39 this.setState({ 51 this.setState({
diff --git a/src/Panel.jsx b/src/Panel.jsx
index 4e09b57..a1b7c77 100644
--- a/src/Panel.jsx
+++ b/src/Panel.jsx
@@ -43,6 +43,7 @@ class Panel extends Component {
43 minuteStep: PropTypes.number, 43 minuteStep: PropTypes.number,
44 secondStep: PropTypes.number, 44 secondStep: PropTypes.number,
45 addon: PropTypes.func, 45 addon: PropTypes.func,
46 focusOnOpen: PropTypes.bool,
46 onKeyDown: PropTypes.func, 47 onKeyDown: PropTypes.func,
47 }; 48 };
48 49
@@ -94,8 +95,8 @@ class Panel extends Component {
94 const { 95 const {
95 prefixCls, className, placeholder, disabledHours, disabledMinutes, 96 prefixCls, className, placeholder, disabledHours, disabledMinutes,
96 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, 97 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
97 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, onKeyDown, 98 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear,
98 hourStep, minuteStep, secondStep, 99 focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
99 } = this.props; 100 } = this.props;
100 const { 101 const {
101 value, currentSelectPanel, 102 value, currentSelectPanel,
@@ -134,6 +135,7 @@ class Panel extends Component {
134 onChange={this.onChange} 135 onChange={this.onChange}
135 onClear={onClear} 136 onClear={onClear}
136 allowEmpty={allowEmpty} 137 allowEmpty={allowEmpty}
138 focusOnOpen={focusOnOpen}
137 onKeyDown={onKeyDown} 139 onKeyDown={onKeyDown}
138 /> 140 />
139 <Combobox 141 <Combobox
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index 5f2239a..c7ff80a 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -51,6 +51,7 @@ export default class Picker extends Component {
51 hourStep: PropTypes.number, 51 hourStep: PropTypes.number,
52 minuteStep: PropTypes.number, 52 minuteStep: PropTypes.number,
53 secondStep: PropTypes.number, 53 secondStep: PropTypes.number,
54 focusOnOpen: PropTypes.bool,
54 onKeyDown: PropTypes.func, 55 onKeyDown: PropTypes.func,
55 }; 56 };
56 57
@@ -79,6 +80,7 @@ export default class Picker extends Component {
79 onBlur: noop, 80 onBlur: noop,
80 addon: noop, 81 addon: noop,
81 use12Hours: false, 82 use12Hours: false,
83 focusOnOpen: false,
82 onKeyDown: noop, 84 onKeyDown: noop,
83 }; 85 };
84 86
@@ -166,7 +168,7 @@ export default class Picker extends Component {
166 prefixCls, placeholder, disabledHours, 168 prefixCls, placeholder, disabledHours,
167 disabledMinutes, disabledSeconds, hideDisabledOptions, 169 disabledMinutes, disabledSeconds, hideDisabledOptions,
168 allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText, 170 allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
169 addon, use12Hours, onKeyDown, hourStep, minuteStep, secondStep, 171 addon, use12Hours, focusOnOpen, onKeyDown, hourStep, minuteStep, secondStep,
170 } = this.props; 172 } = this.props;
171 return ( 173 return (
172 <Panel 174 <Panel
@@ -193,6 +195,7 @@ export default class Picker extends Component {
193 minuteStep={minuteStep} 195 minuteStep={minuteStep}
194 secondStep={secondStep} 196 secondStep={secondStep}
195 addon={addon} 197 addon={addon}
198 focusOnOpen={focusOnOpen}
196 onKeyDown={onKeyDown} 199 onKeyDown={onKeyDown}
197 /> 200 />
198 ); 201 );
diff --git a/tests/Header.spec.jsx b/tests/Header.spec.jsx
index 5ab0ba0..4b27abb 100644
--- a/tests/Header.spec.jsx
+++ b/tests/Header.spec.jsx
@@ -368,5 +368,33 @@ describe('Header', () => {
368 done(); 368 done();
369 }); 369 });
370 }); 370 });
371
372 it('focus on open', (done) => {
373 const picker = renderPicker({
374 focusOnOpen: true,
375 });
376 expect(picker.state.open).not.to.be.ok();
377 const input = TestUtils.scryRenderedDOMComponentsWithClass(picker,
378 'rc-time-picker-input')[0];
379 let header;
380 async.series([(next) => {
381 expect(picker.state.open).to.be(false);
382
383 Simulate.click(input);
384 setTimeout(next, 100);
385 }, (next) => {
386 // this touches the focusOnOpen code, but we cannot verify the input is in focus
387 expect(picker.state.open).to.be(true);
388 header = TestUtils.scryRenderedDOMComponentsWithClass(picker.panelInstance,
389 'rc-time-picker-panel-input')[0];
390 expect(header).to.be.ok();
391 expect((header).value).to.be('01:02:03');
392 expect((input).value).to.be('01:02:03');
393
394 next();
395 }], () => {
396 done();
397 });
398 });
371 }); 399 });
372}); 400});