aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
author偏右 <afc163@gmail.com>2017-10-22 16:24:17 +0800
committerGitHub <noreply@github.com>2017-10-22 16:24:17 +0800
commit78598cc9f8608fc8bb1830d3384c8e7fd032eb3f (patch)
treed015484db93d83f9ea17fbe6b5602cd9936d37c8
parentbcb307b79a2481bad496085b75b701bf864adc6d (diff)
parentb6767d8a08ccfc52836e09e3a0886a5cf225b93f (diff)
downloadtime-picker-78598cc9f8608fc8bb1830d3384c8e7fd032eb3f.tar.gz
time-picker-78598cc9f8608fc8bb1830d3384c8e7fd032eb3f.tar.zst
time-picker-78598cc9f8608fc8bb1830d3384c8e7fd032eb3f.zip
Merge branch 'master' into focus-on-open
-rw-r--r--src/Header.jsx6
-rw-r--r--src/Panel.jsx5
-rw-r--r--src/Select.jsx8
-rw-r--r--src/TimePicker.jsx12
-rw-r--r--tests/TimePicker.spec.jsx36
5 files changed, 62 insertions, 5 deletions
diff --git a/src/Header.jsx b/src/Header.jsx
index 6bed557..1520d25 100644
--- a/src/Header.jsx
+++ b/src/Header.jsx
@@ -23,6 +23,7 @@ class Header extends Component {
23 defaultOpenValue: PropTypes.object, 23 defaultOpenValue: PropTypes.object,
24 currentSelectPanel: PropTypes.string, 24 currentSelectPanel: PropTypes.string,
25 focusOnOpen: PropTypes.bool, 25 focusOnOpen: PropTypes.bool,
26 onKeyDown: PropTypes.func,
26 }; 27 };
27 28
28 constructor(props) { 29 constructor(props) {
@@ -134,9 +135,12 @@ class Header extends Component {
134 } 135 }
135 136
136 onKeyDown = (e) => { 137 onKeyDown = (e) => {
138 const { onEsc, onKeyDown } = this.props;
137 if (e.keyCode === 27) { 139 if (e.keyCode === 27) {
138 this.props.onEsc(); 140 onEsc();
139 } 141 }
142
143 onKeyDown(e);
140 } 144 }
141 145
142 onClear = () => { 146 onClear = () => {
diff --git a/src/Panel.jsx b/src/Panel.jsx
index deeba52..957c021 100644
--- a/src/Panel.jsx
+++ b/src/Panel.jsx
@@ -41,6 +41,7 @@ class Panel extends Component {
41 use12Hours: PropTypes.bool, 41 use12Hours: PropTypes.bool,
42 addon: PropTypes.func, 42 addon: PropTypes.func,
43 focusOnOpen: PropTypes.bool, 43 focusOnOpen: PropTypes.bool,
44 onKeyDown: PropTypes.func,
44 }; 45 };
45 46
46 static defaultProps = { 47 static defaultProps = {
@@ -53,6 +54,7 @@ class Panel extends Component {
53 defaultOpenValue: moment(), 54 defaultOpenValue: moment(),
54 use12Hours: false, 55 use12Hours: false,
55 addon: noop, 56 addon: noop,
57 onKeyDown: noop,
56 }; 58 };
57 59
58 constructor(props) { 60 constructor(props) {
@@ -90,7 +92,7 @@ class Panel extends Component {
90 const { 92 const {
91 prefixCls, className, placeholder, disabledHours, disabledMinutes, 93 prefixCls, className, placeholder, disabledHours, disabledMinutes,
92 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, 94 disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond,
93 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, focusOnOpen, 95 format, defaultOpenValue, clearText, onEsc, addon, use12Hours, onClear, focusOnOpen, onKeyDown,
94 } = this.props; 96 } = this.props;
95 const { 97 const {
96 value, currentSelectPanel, 98 value, currentSelectPanel,
@@ -124,6 +126,7 @@ class Panel extends Component {
124 onClear={onClear} 126 onClear={onClear}
125 allowEmpty={allowEmpty} 127 allowEmpty={allowEmpty}
126 focusOnOpen={focusOnOpen} 128 focusOnOpen={focusOnOpen}
129 onKeyDown={onKeyDown}
127 /> 130 />
128 <Combobox 131 <Combobox
129 prefixCls={prefixCls} 132 prefixCls={prefixCls}
diff --git a/src/Select.jsx b/src/Select.jsx
index 49fed5b..a51ffd2 100644
--- a/src/Select.jsx
+++ b/src/Select.jsx
@@ -79,7 +79,7 @@ class Select extends Component {
79 scrollToSelected(duration) { 79 scrollToSelected(duration) {
80 // move to selected item 80 // move to selected item
81 const select = ReactDom.findDOMNode(this); 81 const select = ReactDom.findDOMNode(this);
82 const list = ReactDom.findDOMNode(this.refs.list); 82 const list = ReactDom.findDOMNode(this.list);
83 if (!list) { 83 if (!list) {
84 return; 84 return;
85 } 85 }
@@ -101,6 +101,10 @@ class Select extends Component {
101 this.setState({ active: false }); 101 this.setState({ active: false });
102 } 102 }
103 103
104 saveList = (node) => {
105 this.list = node;
106 }
107
104 render() { 108 render() {
105 if (this.props.options.length === 0) { 109 if (this.props.options.length === 0) {
106 return null; 110 return null;
@@ -118,7 +122,7 @@ class Select extends Component {
118 onMouseEnter={this.handleMouseEnter} 122 onMouseEnter={this.handleMouseEnter}
119 onMouseLeave={this.handleMouseLeave} 123 onMouseLeave={this.handleMouseLeave}
120 > 124 >
121 <ul ref="list">{this.getOptions()}</ul> 125 <ul ref={this.saveList}>{this.getOptions()}</ul>
122 </div> 126 </div>
123 ); 127 );
124 } 128 }
diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx
index e017527..70327d7 100644
--- a/src/TimePicker.jsx
+++ b/src/TimePicker.jsx
@@ -42,11 +42,14 @@ 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,
48 use12Hours: PropTypes.bool, 50 use12Hours: PropTypes.bool,
49 focusOnOpen: PropTypes.bool, 51 focusOnOpen: PropTypes.bool,
52 onKeyDown: PropTypes.func,
50 }; 53 };
51 54
52 static defaultProps = { 55 static defaultProps = {
@@ -70,9 +73,12 @@ export default class Picker extends Component {
70 onChange: noop, 73 onChange: noop,
71 onOpen: noop, 74 onOpen: noop,
72 onClose: noop, 75 onClose: noop,
76 onFocus: noop,
77 onBlur: noop,
73 addon: noop, 78 addon: noop,
74 use12Hours: false, 79 use12Hours: false,
75 focusOnOpen: false, 80 focusOnOpen: false,
81 onKeyDown: noop,
76 }; 82 };
77 83
78 constructor(props) { 84 constructor(props) {
@@ -159,7 +165,7 @@ export default class Picker extends Component {
159 prefixCls, placeholder, disabledHours, 165 prefixCls, placeholder, disabledHours,
160 disabledMinutes, disabledSeconds, hideDisabledOptions, 166 disabledMinutes, disabledSeconds, hideDisabledOptions,
161 allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText, 167 allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText,
162 addon, use12Hours, focusOnOpen, 168 addon, use12Hours, focusOnOpen, onKeyDown,
163 } = this.props; 169 } = this.props;
164 return ( 170 return (
165 <Panel 171 <Panel
@@ -184,6 +190,7 @@ export default class Picker extends Component {
184 use12Hours={use12Hours} 190 use12Hours={use12Hours}
185 addon={addon} 191 addon={addon}
186 focusOnOpen={focusOnOpen} 192 focusOnOpen={focusOnOpen}
193 onKeyDown={onKeyDown}
187 /> 194 />
188 ); 195 );
189 } 196 }
@@ -234,6 +241,7 @@ export default class Picker extends Component {
234 const { 241 const {
235 prefixCls, placeholder, placement, align, 242 prefixCls, placeholder, placement, align,
236 disabled, transitionName, style, className, getPopupContainer, name, autoComplete, 243 disabled, transitionName, style, className, getPopupContainer, name, autoComplete,
244 onFocus, onBlur,
237 } = this.props; 245 } = this.props;
238 const { open, value } = this.state; 246 const { open, value } = this.state;
239 const popupClassName = this.getPopupClassName(); 247 const popupClassName = this.getPopupClassName();
@@ -263,6 +271,8 @@ export default class Picker extends Component {
263 onKeyDown={this.onKeyDown} 271 onKeyDown={this.onKeyDown}
264 disabled={disabled} value={value && value.format(this.getFormat()) || ''} 272 disabled={disabled} value={value && value.format(this.getFormat()) || ''}
265 autoComplete={autoComplete} 273 autoComplete={autoComplete}
274 onFocus={onFocus}
275 onBlur={onBlur}
266 /> 276 />
267 <span className={`${prefixCls}-icon`}/> 277 <span className={`${prefixCls}-icon`}/>
268 </span> 278 </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});