UNPKG

32.3 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
6
7var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
8
9var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
10
11var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
12
13var _inherits2 = require('babel-runtime/helpers/inherits');
14
15var _inherits3 = _interopRequireDefault(_inherits2);
16
17var _extends2 = require('babel-runtime/helpers/extends');
18
19var _extends3 = _interopRequireDefault(_extends2);
20
21var _class, _temp;
22
23var _react = require('react');
24
25var _react2 = _interopRequireDefault(_react);
26
27var _propTypes = require('prop-types');
28
29var _propTypes2 = _interopRequireDefault(_propTypes);
30
31var _reactLifecyclesCompat = require('react-lifecycles-compat');
32
33var _lodash = require('lodash.clonedeep');
34
35var _lodash2 = _interopRequireDefault(_lodash);
36
37var _classnames = require('classnames');
38
39var _classnames2 = _interopRequireDefault(_classnames);
40
41var _menu = require('../menu');
42
43var _menu2 = _interopRequireDefault(_menu);
44
45var _util = require('../util');
46
47var _menu3 = require('./menu');
48
49var _menu4 = _interopRequireDefault(_menu3);
50
51var _item = require('./item');
52
53var _item2 = _interopRequireDefault(_item);
54
55var _utils = require('./utils');
56
57function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58
59var bindCtx = _util.func.bindCtx;
60var pickOthers = _util.obj.pickOthers;
61var addClass = _util.dom.addClass,
62 removeClass = _util.dom.removeClass,
63 setStyle = _util.dom.setStyle,
64 getStyle = _util.dom.getStyle;
65
66// 数据打平
67
68var flatDataSource = function flatDataSource(data) {
69 var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
70 var v2n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
71 var p2n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
72
73 data.forEach(function (item, index) {
74 var value = item.value,
75 children = item.children;
76
77 var pos = prefix + '-' + index;
78 var newValue = String(value);
79
80 item.value = newValue;
81
82 v2n[newValue] = p2n[pos] = (0, _extends3.default)({}, item, {
83 pos: pos,
84 _source: item
85 });
86
87 if (children && children.length) {
88 flatDataSource(children, pos, v2n, p2n);
89 }
90 });
91
92 return { v2n: v2n, p2n: p2n };
93};
94
95function preHandleData(data, immutable) {
96 var _data = immutable ? (0, _lodash2.default)(data) : data;
97
98 try {
99 return flatDataSource(_data);
100 } catch (err) {
101 if ((err.message || '').match('Cannot assign to read only property')) {
102 // eslint-disable-next-line no-console
103 console.error(err.message, 'try to set immutable to true to allow immutable dataSource');
104 }
105 throw err;
106 }
107}
108
109var getExpandedValue = function getExpandedValue(v, _v2n, _p2n) {
110 if (!v || !_v2n[v]) {
111 return [];
112 }
113
114 var pos = _v2n[v].pos;
115 if (pos.split('-').length === 2) {
116 return [];
117 }
118
119 var expandedMap = {};
120 Object.keys(_p2n).forEach(function (p) {
121 if ((0, _utils.isDescendantOrSelf)(p, pos) && p !== pos) {
122 expandedMap[_p2n[p].value] = p;
123 }
124 });
125
126 return Object.keys(expandedMap).sort(function (prev, next) {
127 return expandedMap[prev].split('-').length - expandedMap[next].split('-').length;
128 });
129};
130
131var normalizeValue = function normalizeValue(value) {
132 if (value) {
133 if (Array.isArray(value)) {
134 return value;
135 }
136
137 return [value];
138 }
139
140 return [];
141};
142
143/**
144 * Cascader
145 */
146var Cascader = (_temp = _class = function (_Component) {
147 (0, _inherits3.default)(Cascader, _Component);
148
149 function Cascader(props, context) {
150 (0, _classCallCheck3.default)(this, Cascader);
151
152 var _this = (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props, context));
153
154 var defaultValue = props.defaultValue,
155 value = props.value,
156 defaultExpandedValue = props.defaultExpandedValue,
157 expandedValue = props.expandedValue,
158 dataSource = props.dataSource,
159 multiple = props.multiple,
160 checkStrictly = props.checkStrictly,
161 canOnlyCheckLeaf = props.canOnlyCheckLeaf,
162 loadData = props.loadData,
163 immutable = props.immutable;
164
165 var _preHandleData = preHandleData(dataSource, immutable),
166 v2n = _preHandleData.v2n,
167 p2n = _preHandleData.p2n;
168
169 var normalizedValue = normalizeValue(typeof value === 'undefined' ? defaultValue : value);
170
171 if (!loadData) {
172 normalizedValue = normalizedValue.filter(function (v) {
173 return v2n[v];
174 });
175 }
176
177 var realExpandedValue = typeof expandedValue === 'undefined' ? typeof defaultExpandedValue === 'undefined' ? getExpandedValue(normalizedValue[0], v2n, p2n) : normalizeValue(defaultExpandedValue) : normalizeValue(expandedValue);
178 var st = {
179 value: normalizedValue,
180 expandedValue: realExpandedValue
181 };
182 if (multiple && !checkStrictly && !canOnlyCheckLeaf) {
183 st.value = (0, _utils.getAllCheckedValues)(st.value, v2n, p2n);
184 }
185
186 _this.lastExpandedValue = [].concat(st.expandedValue);
187 _this.state = (0, _extends3.default)({}, st, {
188 _v2n: v2n,
189 _p2n: p2n
190 });
191
192 bindCtx(_this, ['handleMouseLeave', 'handleFocus', 'handleFold', 'getCascaderNode', 'onBlur']);
193 return _this;
194 }
195
196 Cascader.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
197 var _preHandleData2 = preHandleData(props.dataSource, props.immutable),
198 v2n = _preHandleData2.v2n,
199 p2n = _preHandleData2.p2n;
200
201 var states = {};
202
203 if ('value' in props) {
204 states.value = normalizeValue(props.value);
205 if (!props.loadData) {
206 states.value = states.value.filter(function (v) {
207 return v2n[v];
208 });
209 }
210
211 var multiple = props.multiple,
212 checkStrictly = props.checkStrictly,
213 canOnlyCheckLeaf = props.canOnlyCheckLeaf;
214
215 if (multiple && !checkStrictly && !canOnlyCheckLeaf) {
216 states.value = (0, _utils.getAllCheckedValues)(states.value, v2n, p2n);
217 }
218
219 if (!state.expandedValue.length && !('expandedValue' in props)) {
220 states.expandedValue = getExpandedValue(states.value[0], v2n, p2n);
221 }
222 }
223
224 if ('expandedValue' in props) {
225 states.expandedValue = normalizeValue(props.expandedValue);
226 }
227
228 return (0, _extends3.default)({}, states, {
229 _v2n: v2n,
230 _p2n: p2n
231 });
232 };
233
234 Cascader.prototype.componentDidMount = function componentDidMount() {
235 this.setCascaderInnerWidth();
236 };
237
238 Cascader.prototype.componentDidUpdate = function componentDidUpdate() {
239 this.setCascaderInnerWidth();
240 };
241
242 Cascader.prototype.getCascaderNode = function getCascaderNode(ref) {
243 this.cascader = ref;
244 if (this.cascader) {
245 this.cascaderInner = this.cascader.querySelector('.' + this.props.prefix + 'cascader-inner');
246 }
247 };
248
249 Cascader.prototype.setCascaderInnerWidth = function setCascaderInnerWidth() {
250 if (!this.cascaderInner) {
251 return;
252 }
253 var menus = [].slice.call(this.cascaderInner.querySelectorAll('.' + this.props.prefix + 'cascader-menu-wrapper'));
254 if (menus.length === 0) {
255 return;
256 }
257
258 var menusWidth = Math.ceil(menus.reduce(function (ret, menu) {
259 return ret + Math.ceil(menu.getBoundingClientRect().width);
260 }, 0));
261
262 if (getStyle(this.cascaderInner, 'width') !== menusWidth) {
263 setStyle(this.cascaderInner, 'width', menusWidth);
264 }
265
266 if (getStyle(this.cascader, 'display') === 'inline-block') {
267 var hasRightBorderClass = this.props.prefix + 'has-right-border';
268 menus.forEach(function (menu) {
269 return removeClass(menu, hasRightBorderClass);
270 });
271 if (this.cascader.clientWidth > menusWidth) {
272 addClass(menus[menus.length - 1], hasRightBorderClass);
273 }
274 }
275 };
276
277 /*eslint-enable*/
278
279
280 Cascader.prototype.flatValue = function flatValue(value) {
281 return (0, _utils.filterChildValue)(value, this.state._v2n, this.state._p2n);
282 };
283
284 Cascader.prototype.getValue = function getValue(pos) {
285 return this.state._p2n[pos] ? this.state._p2n[pos].value : null;
286 };
287
288 Cascader.prototype.getPos = function getPos(value) {
289 return this.state._v2n[value] ? this.state._v2n[value].pos : null;
290 };
291
292 Cascader.prototype.getData = function getData(value) {
293 var _this2 = this;
294
295 return value.map(function (v) {
296 return _this2.state._v2n[v];
297 });
298 };
299
300 Cascader.prototype.processValue = function processValue(value, v, checked) {
301 var index = value.indexOf(v);
302 if (checked && index === -1) {
303 value.push(v);
304 } else if (!checked && index > -1) {
305 value.splice(index, 1);
306 }
307 };
308
309 Cascader.prototype.handleSelect = function handleSelect(v, canExpand) {
310 var _this3 = this;
311
312 if (!(this.props.canOnlySelectLeaf && canExpand)) {
313 var data = this.state._v2n[v];
314 var nums = data.pos.split('-');
315 var selectedPath = nums.slice(1).reduce(function (ret, num, index) {
316 var p = nums.slice(0, index + 2).join('-');
317 ret.push(_this3.state._p2n[p]);
318 return ret;
319 }, []);
320
321 if (this.state.value[0] !== v) {
322 if (!('value' in this.props)) {
323 this.setState({
324 value: [v]
325 });
326 }
327
328 if ('onChange' in this.props) {
329 this.props.onChange(v, data, {
330 selectedPath: selectedPath
331 });
332 }
333 }
334
335 if ('onSelect' in this.props) {
336 this.props.onSelect(v, data, {
337 selectedPath: selectedPath
338 });
339 }
340 }
341
342 if (canExpand) {
343 if (!this.props.canOnlySelectLeaf) {
344 this.lastExpandedValue = this.state.expandedValue.slice(0, -1);
345 }
346 } else {
347 this.lastExpandedValue = [].concat(this.state.expandedValue);
348 }
349 };
350 /*eslint-disable max-statements*/
351
352
353 Cascader.prototype.handleCheck = function handleCheck(v, checked) {
354 var _this4 = this;
355
356 var _props = this.props,
357 checkStrictly = _props.checkStrictly,
358 canOnlyCheckLeaf = _props.canOnlyCheckLeaf;
359
360 var value = [].concat(this.state.value);
361
362 if (checkStrictly || canOnlyCheckLeaf) {
363 this.processValue(value, v, checked);
364 } else {
365 var pos = this.getPos(v);
366
367 var ps = Object.keys(this.state._p2n);
368
369 (0, _utils.forEachEnableNode)(this.state._v2n[v], function (node) {
370 if (node.checkable === false) return;
371 _this4.processValue(value, node.value, checked);
372 });
373
374 var currentPos = pos;
375 var nums = pos.split('-');
376 for (var i = nums.length; i > 2; i--) {
377 var parentCheck = true;
378
379 var parentPos = nums.slice(0, i - 1).join('-');
380 if (this.state._p2n[parentPos].disabled || this.state._p2n[parentPos].checkboxDisabled || this.state._p2n[parentPos].checkable === false) {
381 currentPos = parentPos;
382 continue;
383 }
384
385 var parentValue = this.state._p2n[parentPos].value;
386 var parentChecked = value.indexOf(parentValue) > -1;
387 if (!checked && !parentChecked) {
388 break;
389 }
390
391 for (var j = 0; j < ps.length; j++) {
392 var p = ps[j];
393 var pnode = this.state._p2n[p];
394 if ((0, _utils.isSiblingOrSelf)(currentPos, p) && !pnode.disabled && !pnode.checkboxDisabled) {
395 var k = pnode.value;
396 // eslint-disable-next-line max-depth
397 if (pnode.checkable === false) {
398 // eslint-disable-next-line max-depth
399 if (!pnode.children || pnode.children.length === 0) {
400 continue;
401 }
402 // eslint-disable-next-line max-depth
403 for (var m = 0; m < pnode.children.length; m++) {
404 // eslint-disable-next-line max-depth
405 if (!pnode.children.every(function (child) {
406 return (0, _utils.isNodeChecked)(child, value);
407 })) {
408 parentCheck = false;
409 break;
410 }
411 }
412 } else if (value.indexOf(k) === -1) {
413 parentCheck = false;
414 }
415
416 if (!parentCheck) break;
417 }
418 }
419
420 this.processValue(value, parentValue, parentCheck);
421
422 currentPos = parentPos;
423 }
424 }
425
426 if (!('value' in this.props)) {
427 this.setState({
428 value: value
429 });
430 }
431
432 if ('onChange' in this.props) {
433 if (checkStrictly || canOnlyCheckLeaf) {
434 var data = this.getData(value);
435 this.props.onChange(value, data, {
436 checked: checked,
437 currentData: this.state._v2n[v],
438 checkedData: data
439 });
440 } else {
441 var flatValue = this.flatValue(value);
442 var flatData = this.getData(flatValue);
443 var checkedData = this.getData(value);
444 var indeterminateValue = this.getIndeterminate(value);
445 var indeterminateData = this.getData(indeterminateValue);
446 this.props.onChange(flatValue, flatData, {
447 checked: checked,
448 currentData: this.state._v2n[v],
449 checkedData: checkedData,
450 indeterminateData: indeterminateData
451 });
452 }
453 }
454
455 this.lastExpandedValue = [].concat(this.state.expandedValue);
456 };
457
458 Cascader.prototype.handleExpand = function handleExpand(value, level, canExpand, focusedFirstChild) {
459 var _this5 = this;
460
461 var expandedValue = this.state.expandedValue;
462
463
464 if (canExpand || expandedValue.length > level) {
465 if (canExpand) {
466 expandedValue.splice(level, expandedValue.length - level, value);
467 } else {
468 expandedValue.splice(level);
469 }
470
471 var callback = function callback() {
472 _this5.setExpandValue(expandedValue);
473
474 if (focusedFirstChild) {
475 var endExpandedValue = expandedValue[expandedValue.length - 1];
476 _this5.setState({
477 focusedValue: _this5.state._v2n[endExpandedValue].children[0].value
478 });
479 }
480 };
481
482 var loadData = this.props.loadData;
483
484 if (canExpand && loadData) {
485 var data = this.state._v2n[value];
486 return loadData(data, data._source).then(callback);
487 } else {
488 return callback();
489 }
490 }
491 };
492
493 Cascader.prototype.handleMouseLeave = function handleMouseLeave() {
494 this.setExpandValue([].concat(this.lastExpandedValue));
495 };
496
497 Cascader.prototype.setExpandValue = function setExpandValue(expandedValue) {
498 if (!('expandedValue' in this.props)) {
499 this.setState({
500 expandedValue: expandedValue
501 });
502 }
503
504 if ('onExpand' in this.props) {
505 this.props.onExpand(expandedValue);
506 }
507 };
508
509 Cascader.prototype.getFirstFocusKeyByDataSource = function getFirstFocusKeyByDataSource(dataSource) {
510 if (!dataSource || dataSource.length === 0) {
511 return '';
512 }
513
514 for (var i = 0; i < dataSource.length; i++) {
515 if (dataSource[i] && !dataSource[i].disabled) {
516 return dataSource[i].value;
517 }
518 }
519
520 return '';
521 };
522
523 Cascader.prototype.getFirstFocusKeyByFilteredPaths = function getFirstFocusKeyByFilteredPaths(filteredPaths) {
524 if (!filteredPaths || filteredPaths.length === 0) {
525 return '';
526 }
527
528 for (var i = 0; i < filteredPaths.length; i++) {
529 var path = filteredPaths[i];
530 if (!path.some(function (item) {
531 return item.disabled;
532 })) {
533 var lastItem = path[path.length - 1];
534 return lastItem.value;
535 }
536 }
537
538 return '';
539 };
540
541 Cascader.prototype.getFirstFocusKey = function getFirstFocusKey() {
542 var _props2 = this.props,
543 dataSource = _props2.dataSource,
544 searchValue = _props2.searchValue,
545 filteredPaths = _props2.filteredPaths;
546
547
548 return !searchValue ? this.getFirstFocusKeyByDataSource(dataSource) : this.getFirstFocusKeyByFilteredPaths(filteredPaths);
549 };
550
551 Cascader.prototype.setFocusValue = function setFocusValue() {
552 this.setState({
553 focusedValue: this.getFirstFocusKey()
554 });
555 };
556
557 Cascader.prototype.handleFocus = function handleFocus(focusedValue) {
558 this.setState({
559 focusedValue: focusedValue
560 });
561 };
562
563 Cascader.prototype.handleFold = function handleFold() {
564 var expandedValue = this.state.expandedValue;
565
566 if (expandedValue.length > 0) {
567 this.setExpandValue(expandedValue.slice(0, -1));
568 }
569
570 this.setState({
571 focusedValue: expandedValue[expandedValue.length - 1]
572 });
573 };
574
575 Cascader.prototype.getIndeterminate = function getIndeterminate(value) {
576 var _this6 = this;
577
578 var indeterminateValues = [];
579
580 var poss = (0, _utils.filterChildValue)(value.filter(function (v) {
581 return !!_this6.state._v2n[v];
582 }).filter(function (v) {
583 return !_this6.state._v2n[v].disabled && !_this6.state._v2n[v].checkboxDisabled && _this6.state._v2n[v].checkable !== false;
584 }), this.state._v2n, this.state._p2n).map(function (v) {
585 return _this6.state._v2n[v].pos;
586 });
587 poss.forEach(function (pos) {
588 var nums = pos.split('-');
589 for (var i = nums.length; i > 2; i--) {
590 var parentPos = nums.slice(0, i - 1).join('-');
591 var parent = _this6.state._p2n[parentPos];
592 if (parent.disabled || parent.checkboxDisabled) break;
593 var parentValue = parent.value;
594 if (indeterminateValues.indexOf(parentValue) === -1) {
595 indeterminateValues.push(parentValue);
596 }
597 }
598 });
599
600 return indeterminateValues;
601 };
602
603 Cascader.prototype.onBlur = function onBlur(e) {
604 this.setState({
605 focusedValue: undefined
606 });
607
608 this.props.onBlur && this.props.onBlur(e);
609 };
610
611 Cascader.prototype.renderMenu = function renderMenu(data, level) {
612 var _this7 = this;
613
614 var _props3 = this.props,
615 prefix = _props3.prefix,
616 multiple = _props3.multiple,
617 useVirtual = _props3.useVirtual,
618 checkStrictly = _props3.checkStrictly,
619 expandTriggerType = _props3.expandTriggerType,
620 loadData = _props3.loadData,
621 canOnlyCheckLeaf = _props3.canOnlyCheckLeaf,
622 listClassName = _props3.listClassName,
623 listStyle = _props3.listStyle,
624 itemRender = _props3.itemRender;
625 var _state = this.state,
626 value = _state.value,
627 expandedValue = _state.expandedValue,
628 focusedValue = _state.focusedValue;
629
630
631 return _react2.default.createElement(
632 _menu4.default,
633 {
634 key: level,
635 prefix: prefix,
636 useVirtual: useVirtual,
637 className: listClassName,
638 style: listStyle,
639 ref: this.saveMenuRef,
640 focusedKey: focusedValue,
641 onItemFocus: this.handleFocus,
642 onBlur: this.onBlur
643 },
644 data.map(function (item) {
645 var disabled = !!item.disabled;
646 var canExpand = !!item.children && !!item.children.length || !!loadData && !item.isLeaf;
647 var expanded = expandedValue[level] === item.value;
648 var props = {
649 prefix: prefix,
650 disabled: disabled,
651 canExpand: canExpand,
652 expanded: expanded,
653 expandTriggerType: expandTriggerType,
654 onExpand: _this7.handleExpand.bind(_this7, item.value, level, canExpand),
655 onFold: _this7.handleFold
656 };
657
658 if ('title' in item) {
659 props.title = item.title;
660 }
661
662 if (multiple) {
663 props.checkable = !(canOnlyCheckLeaf && canExpand);
664 props.checked = value.indexOf(item.value) > -1 || !!item.checked;
665 props.indeterminate = (checkStrictly || canOnlyCheckLeaf ? false : _this7.indeterminate.indexOf(item.value) > -1) || !!item.indeterminate;
666 props.checkboxDisabled = !!item.checkboxDisabled;
667 props.onCheck = _this7.handleCheck.bind(_this7, item.value);
668 } else {
669 props.selected = value[0] === item.value;
670 props.onSelect = _this7.handleSelect.bind(_this7, item.value, canExpand);
671 }
672
673 var itemContent = itemRender(item, props);
674 if (itemContent === null) {
675 return null;
676 }
677 return _react2.default.createElement(
678 _item2.default,
679 (0, _extends3.default)({ key: item.value }, props),
680 itemContent
681 );
682 }).filter(function (v) {
683 return v;
684 })
685 );
686 };
687
688 Cascader.prototype.renderMenus = function renderMenus() {
689 var dataSource = this.props.dataSource;
690 var expandedValue = this.state.expandedValue;
691
692
693 var menus = [];
694 var data = dataSource;
695
696 for (var i = 0; i <= expandedValue.length; i++) {
697 if (!data) {
698 break;
699 }
700
701 menus.push(this.renderMenu(data, i));
702
703 var expandedItem = void 0;
704 for (var j = 0; j < data.length; j++) {
705 if (data[j].value === expandedValue[i]) {
706 expandedItem = data[j];
707 break;
708 }
709 }
710 data = expandedItem ? expandedItem.children : null;
711 }
712
713 return menus;
714 };
715
716 Cascader.prototype.renderFilteredItem = function renderFilteredItem(path) {
717 var _props4 = this.props,
718 prefix = _props4.prefix,
719 resultRender = _props4.resultRender,
720 searchValue = _props4.searchValue,
721 multiple = _props4.multiple;
722 var value = this.state.value;
723
724 var lastItem = path[path.length - 1];
725
726 var Item = void 0;
727 var props = {
728 key: lastItem.value,
729 className: prefix + 'cascader-filtered-item',
730 disabled: path.some(function (item) {
731 return item.disabled;
732 }),
733 children: resultRender(searchValue, path)
734 };
735
736 if (multiple) {
737 Item = _menu2.default.CheckboxItem;
738 var _props5 = this.props,
739 checkStrictly = _props5.checkStrictly,
740 canOnlyCheckLeaf = _props5.canOnlyCheckLeaf;
741
742 props.checked = value.indexOf(lastItem.value) > -1;
743 props.indeterminate = !checkStrictly && !canOnlyCheckLeaf && this.indeterminate.indexOf(lastItem.value) > -1;
744 props.checkboxDisabled = lastItem.checkboxDisabled;
745 props.onChange = this.handleCheck.bind(this, lastItem.value);
746 } else {
747 Item = _menu2.default.Item;
748 props.selected = value[0] === lastItem.value;
749 props.onSelect = this.handleSelect.bind(this, lastItem.value, false);
750 }
751
752 return _react2.default.createElement(Item, props);
753 };
754
755 Cascader.prototype.renderFilteredList = function renderFilteredList() {
756 var _this8 = this;
757
758 var _props6 = this.props,
759 prefix = _props6.prefix,
760 filteredListStyle = _props6.filteredListStyle,
761 filteredPaths = _props6.filteredPaths,
762 _props6$focusable = _props6.focusable,
763 focusable = _props6$focusable === undefined ? false : _props6$focusable;
764 var focusedValue = this.state.focusedValue;
765
766 return _react2.default.createElement(
767 _menu2.default
768 // 如果不设置为false, CascaderSelect 开启 showSearch后,弹窗展开时,光标无法到input上去,也无法输入.
769 // TODO: set focusable=true in 2.x
770 ,
771 { focusable: focusable,
772 focusedKey: focusedValue,
773 onItemFocus: this.handleFocus,
774 className: prefix + 'cascader-filtered-list',
775 style: filteredListStyle
776 },
777 filteredPaths.map(function (path) {
778 return _this8.renderFilteredItem(path);
779 })
780 );
781 };
782
783 Cascader.prototype.render = function render() {
784 var _cx;
785
786 var _props7 = this.props,
787 prefix = _props7.prefix,
788 rtl = _props7.rtl,
789 className = _props7.className,
790 expandTriggerType = _props7.expandTriggerType,
791 multiple = _props7.multiple,
792 dataSource = _props7.dataSource,
793 checkStrictly = _props7.checkStrictly,
794 canOnlyCheckLeaf = _props7.canOnlyCheckLeaf,
795 searchValue = _props7.searchValue;
796
797 var others = pickOthers(Object.keys(Cascader.propTypes), this.props);
798 var value = this.state.value;
799
800
801 if (rtl) {
802 others.dir = 'rtl';
803 }
804
805 var props = (0, _extends3.default)({
806 className: (0, _classnames2.default)((_cx = {}, _cx[prefix + 'cascader'] = true, _cx.multiple = multiple, _cx[className] = !!className, _cx)),
807 ref: 'cascader'
808 }, others);
809 if (expandTriggerType === 'hover') {
810 props.onMouseLeave = this.handleMouseLeave;
811 }
812
813 if (multiple && !checkStrictly && !canOnlyCheckLeaf) {
814 this.indeterminate = this.getIndeterminate(value);
815 }
816
817 return _react2.default.createElement(
818 'div',
819 (0, _extends3.default)({}, props, { ref: this.getCascaderNode }),
820 !searchValue ? _react2.default.createElement(
821 'div',
822 { className: prefix + 'cascader-inner' },
823 dataSource && dataSource.length ? this.renderMenus() : null
824 ) : this.renderFilteredList()
825 );
826 };
827
828 return Cascader;
829}(_react.Component), _class.propTypes = {
830 prefix: _propTypes2.default.string,
831 rtl: _propTypes2.default.bool,
832 pure: _propTypes2.default.bool,
833 className: _propTypes2.default.string,
834 /**
835 * 数据源,结构可参考下方说明
836 */
837 dataSource: _propTypes2.default.arrayOf(_propTypes2.default.object),
838 /**
839 * (非受控)默认值
840 */
841 defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
842 /**
843 * (受控)当前值
844 */
845 value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
846 /**
847 * 选中值改变时触发的回调函数
848 * @param {String|Array} value 选中的值,单选时返回单个值,多选时返回数组
849 * @param {Object|Array} data 选中的数据,包括 value 和 label,单选时返回单个值,多选时返回数组,父子节点选中关联时,同时选中,只返回父节点
850 * @param {Object} extra 额外参数
851 * @param {Array} extra.selectedPath 单选时选中的数据的路径
852 * @param {Boolean} extra.checked 多选时当前的操作是选中还是取消选中
853 * @param {Object} extra.currentData 多选时当前操作的数据
854 * @param {Array} extra.checkedData 多选时所有被选中的数据
855 * @param {Array} extra.indeterminateData 多选时半选的数据
856 */
857 onChange: _propTypes2.default.func,
858 onSelect: _propTypes2.default.func,
859 /**
860 * (非受控)默认展开值,如果不设置,组件内部会根据 defaultValue/value 进行自动设置
861 */
862 defaultExpandedValue: _propTypes2.default.arrayOf(_propTypes2.default.string),
863 /**
864 * (受控)当前展开值
865 */
866 expandedValue: _propTypes2.default.arrayOf(_propTypes2.default.string),
867 /**
868 * 展开触发的方式
869 */
870 expandTriggerType: _propTypes2.default.oneOf(['click', 'hover']),
871 /**
872 * 展开时触发的回调函数
873 * @param {Array} expandedValue 各列展开值的数组
874 */
875 onExpand: _propTypes2.default.func,
876 /**
877 * 是否开启虚拟滚动
878 */
879 useVirtual: _propTypes2.default.bool,
880 /**
881 * 是否多选
882 */
883 multiple: _propTypes2.default.bool,
884 /**
885 * 单选时是否只能选中叶子节点
886 */
887 canOnlySelectLeaf: _propTypes2.default.bool,
888 /**
889 * 多选时是否只能选中叶子节点
890 */
891 canOnlyCheckLeaf: _propTypes2.default.bool,
892 /**
893 * 父子节点是否选中不关联
894 */
895 checkStrictly: _propTypes2.default.bool,
896 /**
897 * 每列列表样式对象
898 */
899 listStyle: _propTypes2.default.object,
900 /**
901 * 每列列表类名
902 */
903 listClassName: _propTypes2.default.string,
904 /**
905 * 每列列表项渲染函数
906 * @param {Object} data 数据
907 * @return {ReactNode} 列表项内容
908 */
909 itemRender: _propTypes2.default.func,
910 /**
911 * 异步加载数据函数
912 * @param {Object} data 当前点击异步加载的数据
913 * @param {Object} source 当前点击数据,source是原始对象
914 */
915 loadData: _propTypes2.default.func,
916 searchValue: _propTypes2.default.string,
917 onBlur: _propTypes2.default.func,
918 filteredPaths: _propTypes2.default.array,
919 filteredListStyle: _propTypes2.default.object,
920 resultRender: _propTypes2.default.func,
921 /**
922 * 是否是不可变数据
923 * @version 1.23
924 */
925 immutable: _propTypes2.default.bool
926}, _class.defaultProps = {
927 prefix: 'next-',
928 rtl: false,
929 pure: false,
930 dataSource: [],
931 defaultValue: null,
932 canOnlySelectLeaf: false,
933 canOnlyCheckLeaf: false,
934 expandTriggerType: 'click',
935 multiple: false,
936 useVirtual: false,
937 checkStrictly: false,
938 itemRender: function itemRender(item) {
939 return item.label;
940 },
941 immutable: false
942}, _temp);
943Cascader.displayName = 'Cascader';
944exports.default = (0, _reactLifecyclesCompat.polyfill)(Cascader);
945module.exports = exports['default'];
\No newline at end of file