UNPKG

3.29 kBJavaScriptView Raw
1import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2import _createClass from "@babel/runtime/helpers/esm/createClass";
3import _inherits from "@babel/runtime/helpers/esm/inherits";
4import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
6/**
7 * To match accessibility requirement, we always provide an input in the component.
8 * Other element will not set `tabIndex` to avoid `onBlur` sequence problem.
9 * For focused select, we set `aria-live="polite"` to update the accessibility content.
10 *
11 * ref:
12 * - keyboard: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role#Keyboard_interactions
13 *
14 * New api:
15 * - listHeight
16 * - listItemHeight
17 * - component
18 *
19 * Remove deprecated api:
20 * - multiple
21 * - tags
22 * - combobox
23 * - firstActiveValue
24 * - dropdownMenuStyle
25 * - openClassName (Not list in api)
26 *
27 * Update:
28 * - `backfill` only support `combobox` mode
29 * - `combobox` mode not support `labelInValue` since it's meaningless
30 * - `getInputElement` only support `combobox` mode
31 * - `onChange` return OptionData instead of ReactNode
32 * - `filterOption` `onChange` `onSelect` accept OptionData instead of ReactNode
33 * - `combobox` mode trigger `onChange` will get `undefined` if no `value` match in Option
34 * - `combobox` mode not support `optionLabelProp`
35 */
36import * as React from 'react';
37import SelectOptionList from './OptionList';
38import Option from './Option';
39import OptGroup from './OptGroup';
40import { convertChildrenToData as convertSelectChildrenToData } from './utils/legacyUtil';
41import { getLabeledValue as getSelectLabeledValue, filterOptions as selectDefaultFilterOptions, isValueDisabled as isSelectValueDisabled, findValueOption as findSelectValueOption, flattenOptions, fillOptionsWithMissingValue } from './utils/valueUtil';
42import generateSelector from './generate';
43import warningProps from './utils/warningPropsUtil';
44var RefSelect = generateSelector({
45 prefixCls: 'rc-select',
46 components: {
47 optionList: SelectOptionList
48 },
49 convertChildrenToData: convertSelectChildrenToData,
50 flattenOptions: flattenOptions,
51 getLabeledValue: getSelectLabeledValue,
52 filterOptions: selectDefaultFilterOptions,
53 isValueDisabled: isSelectValueDisabled,
54 findValueOption: findSelectValueOption,
55 warningProps: warningProps,
56 fillOptionsWithMissingValue: fillOptionsWithMissingValue
57});
58/**
59 * Typescript not support generic with function component,
60 * we have to wrap an class component to handle this.
61 */
62
63var Select = /*#__PURE__*/function (_React$Component) {
64 _inherits(Select, _React$Component);
65
66 var _super = _createSuper(Select);
67
68 function Select() {
69 var _this;
70
71 _classCallCheck(this, Select);
72
73 _this = _super.apply(this, arguments);
74 _this.selectRef = React.createRef();
75
76 _this.focus = function () {
77 _this.selectRef.current.focus();
78 };
79
80 _this.blur = function () {
81 _this.selectRef.current.blur();
82 };
83
84 return _this;
85 }
86
87 _createClass(Select, [{
88 key: "render",
89 value: function render() {
90 return React.createElement(RefSelect, Object.assign({
91 ref: this.selectRef
92 }, this.props));
93 }
94 }]);
95
96 return Select;
97}(React.Component);
98
99Select.Option = Option;
100Select.OptGroup = OptGroup;
101export default Select;
\No newline at end of file