@rc-component/select 1.1.4 → 1.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/assets/index.css +63 -0
  2. package/assets/index.less +1 -0
  3. package/assets/patch.less +83 -0
  4. package/es/BaseSelect/index.d.ts +14 -3
  5. package/es/BaseSelect/index.js +137 -200
  6. package/es/OptionList.js +3 -3
  7. package/es/Select.d.ts +1 -1
  8. package/es/Select.js +5 -9
  9. package/es/SelectInput/Affix.d.ts +5 -0
  10. package/es/SelectInput/Affix.js +12 -0
  11. package/es/SelectInput/Content/MultipleContent.d.ts +4 -0
  12. package/es/SelectInput/Content/MultipleContent.js +152 -0
  13. package/es/SelectInput/Content/Placeholder.d.ts +5 -0
  14. package/es/SelectInput/Content/Placeholder.js +21 -0
  15. package/es/SelectInput/Content/SingleContent.d.ts +4 -0
  16. package/es/SelectInput/Content/SingleContent.js +98 -0
  17. package/es/SelectInput/Content/index.d.ts +6 -0
  18. package/es/SelectInput/Content/index.js +37 -0
  19. package/es/SelectInput/Input.d.ts +20 -0
  20. package/es/SelectInput/Input.js +214 -0
  21. package/es/SelectInput/context.d.ts +6 -0
  22. package/es/SelectInput/context.js +6 -0
  23. package/es/SelectInput/index.d.ts +39 -0
  24. package/es/SelectInput/index.js +189 -0
  25. package/es/SelectTrigger.d.ts +1 -0
  26. package/es/SelectTrigger.js +5 -3
  27. package/es/TransBtn.d.ts +10 -0
  28. package/es/TransBtn.js +12 -2
  29. package/es/hooks/useAllowClear.d.ts +8 -7
  30. package/es/hooks/useAllowClear.js +21 -23
  31. package/es/hooks/useBaseProps.d.ts +1 -0
  32. package/es/hooks/useComponents.d.ts +12 -0
  33. package/es/hooks/useComponents.js +23 -0
  34. package/es/hooks/useOpen.d.ts +15 -0
  35. package/es/hooks/useOpen.js +76 -0
  36. package/es/hooks/useSearchConfig.d.ts +2 -2
  37. package/es/hooks/useSearchConfig.js +3 -3
  38. package/es/hooks/useSelectTriggerControl.d.ts +1 -1
  39. package/es/hooks/useSelectTriggerControl.js +16 -21
  40. package/es/utils/keyUtil.js +4 -0
  41. package/lib/BaseSelect/index.d.ts +14 -3
  42. package/lib/BaseSelect/index.js +137 -201
  43. package/lib/OptionList.js +3 -3
  44. package/lib/Select.d.ts +1 -1
  45. package/lib/Select.js +5 -9
  46. package/lib/SelectInput/Affix.d.ts +5 -0
  47. package/lib/{hooks/useLayoutEffect.js → SelectInput/Affix.js} +11 -16
  48. package/lib/SelectInput/Content/MultipleContent.d.ts +4 -0
  49. package/lib/{Selector/MultipleSelector.js → SelectInput/Content/MultipleContent.js} +71 -104
  50. package/lib/SelectInput/Content/Placeholder.d.ts +5 -0
  51. package/lib/SelectInput/Content/Placeholder.js +29 -0
  52. package/lib/SelectInput/Content/SingleContent.d.ts +4 -0
  53. package/lib/SelectInput/Content/SingleContent.js +107 -0
  54. package/lib/SelectInput/Content/index.d.ts +6 -0
  55. package/lib/SelectInput/Content/index.js +46 -0
  56. package/lib/SelectInput/Input.d.ts +20 -0
  57. package/lib/SelectInput/Input.js +223 -0
  58. package/lib/SelectInput/context.d.ts +6 -0
  59. package/lib/SelectInput/context.js +15 -0
  60. package/lib/SelectInput/index.d.ts +39 -0
  61. package/lib/SelectInput/index.js +198 -0
  62. package/lib/SelectTrigger.d.ts +1 -0
  63. package/lib/SelectTrigger.js +5 -3
  64. package/lib/TransBtn.d.ts +10 -0
  65. package/lib/TransBtn.js +12 -3
  66. package/lib/hooks/useAllowClear.d.ts +8 -7
  67. package/lib/hooks/useAllowClear.js +21 -24
  68. package/lib/hooks/useBaseProps.d.ts +1 -0
  69. package/lib/hooks/useComponents.d.ts +12 -0
  70. package/lib/hooks/{useDelayReset.js → useComponents.js} +21 -30
  71. package/lib/hooks/useOpen.d.ts +15 -0
  72. package/lib/hooks/useOpen.js +82 -0
  73. package/lib/hooks/useSearchConfig.d.ts +2 -2
  74. package/lib/hooks/useSearchConfig.js +3 -3
  75. package/lib/hooks/useSelectTriggerControl.d.ts +1 -1
  76. package/lib/hooks/useSelectTriggerControl.js +16 -21
  77. package/lib/utils/keyUtil.js +4 -0
  78. package/package.json +5 -4
  79. package/es/Selector/Input.d.ts +0 -27
  80. package/es/Selector/Input.js +0 -61
  81. package/es/Selector/MultipleSelector.d.ts +0 -16
  82. package/es/Selector/MultipleSelector.js +0 -185
  83. package/es/Selector/SingleSelector.d.ts +0 -8
  84. package/es/Selector/SingleSelector.js +0 -104
  85. package/es/Selector/index.d.ts +0 -83
  86. package/es/Selector/index.js +0 -189
  87. package/es/hooks/useDelayReset.d.ts +0 -5
  88. package/es/hooks/useDelayReset.js +0 -33
  89. package/es/hooks/useLayoutEffect.d.ts +0 -5
  90. package/es/hooks/useLayoutEffect.js +0 -17
  91. package/lib/Selector/Input.d.ts +0 -27
  92. package/lib/Selector/Input.js +0 -70
  93. package/lib/Selector/MultipleSelector.d.ts +0 -16
  94. package/lib/Selector/SingleSelector.d.ts +0 -8
  95. package/lib/Selector/SingleSelector.js +0 -113
  96. package/lib/Selector/index.d.ts +0 -83
  97. package/lib/Selector/index.js +0 -196
  98. package/lib/hooks/useDelayReset.d.ts +0 -5
  99. package/lib/hooks/useLayoutEffect.d.ts +0 -5
@@ -1,104 +0,0 @@
1
- import * as React from 'react';
2
- import pickAttrs from "@rc-component/util/es/pickAttrs";
3
- import Input from "./Input";
4
- import { getTitle } from "../utils/commonUtil";
5
- const SingleSelector = props => {
6
- const {
7
- inputElement,
8
- prefixCls,
9
- id,
10
- inputRef,
11
- disabled,
12
- autoFocus,
13
- autoComplete,
14
- activeDescendantId,
15
- mode,
16
- open,
17
- values,
18
- placeholder,
19
- tabIndex,
20
- showSearch,
21
- searchValue,
22
- activeValue,
23
- maxLength,
24
- onInputKeyDown,
25
- onInputMouseDown,
26
- onInputChange,
27
- onInputPaste,
28
- onInputCompositionStart,
29
- onInputCompositionEnd,
30
- onInputBlur,
31
- title
32
- } = props;
33
- const [inputChanged, setInputChanged] = React.useState(false);
34
- const combobox = mode === 'combobox';
35
- const inputEditable = combobox || showSearch;
36
- const item = values[0];
37
- let inputValue = searchValue || '';
38
- if (combobox && activeValue && !inputChanged) {
39
- inputValue = activeValue;
40
- }
41
- React.useEffect(() => {
42
- if (combobox) {
43
- setInputChanged(false);
44
- }
45
- }, [combobox, activeValue]);
46
-
47
- // Not show text when closed expect combobox mode
48
- const hasTextInput = mode !== 'combobox' && !open && !showSearch ? false : !!inputValue;
49
-
50
- // Get title of selection item
51
- const selectionTitle = title === undefined ? getTitle(item) : title;
52
- const placeholderNode = React.useMemo(() => {
53
- if (item) {
54
- return null;
55
- }
56
- return /*#__PURE__*/React.createElement("span", {
57
- className: `${prefixCls}-selection-placeholder`,
58
- style: hasTextInput ? {
59
- visibility: 'hidden'
60
- } : undefined
61
- }, placeholder);
62
- }, [item, hasTextInput, placeholder, prefixCls]);
63
- return /*#__PURE__*/React.createElement("span", {
64
- className: `${prefixCls}-selection-wrap`
65
- }, /*#__PURE__*/React.createElement("span", {
66
- className: `${prefixCls}-selection-search`
67
- }, /*#__PURE__*/React.createElement(Input, {
68
- ref: inputRef,
69
- prefixCls: prefixCls,
70
- id: id,
71
- open: open,
72
- inputElement: inputElement,
73
- disabled: disabled,
74
- autoFocus: autoFocus,
75
- autoComplete: autoComplete,
76
- editable: inputEditable,
77
- activeDescendantId: activeDescendantId,
78
- value: inputValue,
79
- onKeyDown: onInputKeyDown,
80
- onMouseDown: onInputMouseDown,
81
- onChange: e => {
82
- setInputChanged(true);
83
- onInputChange(e);
84
- },
85
- onPaste: onInputPaste,
86
- onCompositionStart: onInputCompositionStart,
87
- onCompositionEnd: onInputCompositionEnd,
88
- onBlur: onInputBlur,
89
- tabIndex: tabIndex,
90
- attrs: pickAttrs(props, true),
91
- maxLength: combobox ? maxLength : undefined
92
- })), !combobox && item ? /*#__PURE__*/React.createElement("span", {
93
- className: `${prefixCls}-selection-item`,
94
- title: selectionTitle
95
- // 当 Select 已经选中选项时,还需 selection 隐藏但留在原地占位
96
- // https://github.com/ant-design/ant-design/issues/27688
97
- // https://github.com/ant-design/ant-design/issues/41530
98
- ,
99
- style: hasTextInput ? {
100
- visibility: 'hidden'
101
- } : undefined
102
- }, item.label) : null, placeholderNode);
103
- };
104
- export default SingleSelector;
@@ -1,83 +0,0 @@
1
- /**
2
- * Cursor rule:
3
- * 1. Only `showSearch` enabled
4
- * 2. Only `open` is `true`
5
- * 3. When typing, set `open` to `true` which hit rule of 2
6
- *
7
- * Accessibility:
8
- * - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
9
- */
10
- import type { ScrollTo } from 'rc-virtual-list/lib/List';
11
- import * as React from 'react';
12
- import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../BaseSelect';
13
- export interface InnerSelectorProps {
14
- prefixCls: string;
15
- id: string;
16
- mode: Mode;
17
- title?: string;
18
- inputRef: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
19
- placeholder?: React.ReactNode;
20
- disabled?: boolean;
21
- autoFocus?: boolean;
22
- autoComplete?: string;
23
- values: DisplayValueType[];
24
- showSearch?: boolean;
25
- searchValue: string;
26
- autoClearSearchValue?: boolean;
27
- activeDescendantId?: string;
28
- open: boolean;
29
- tabIndex?: number;
30
- maxLength?: number;
31
- onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
32
- onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
33
- onInputChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
34
- onInputPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
35
- onInputCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
36
- onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
37
- onInputBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
38
- }
39
- export interface RefSelectorProps {
40
- focus: (options?: FocusOptions) => void;
41
- blur: () => void;
42
- scrollTo?: ScrollTo;
43
- nativeElement: HTMLDivElement;
44
- }
45
- export interface SelectorProps {
46
- prefixClassName: string;
47
- prefixStyle: React.CSSProperties;
48
- id: string;
49
- prefixCls: string;
50
- showSearch?: boolean;
51
- open: boolean;
52
- /** Display in the Selector value, it's not same as `value` prop */
53
- values: DisplayValueType[];
54
- mode: Mode;
55
- searchValue: string;
56
- activeValue: string;
57
- autoClearSearchValue: boolean;
58
- inputElement: JSX.Element;
59
- maxLength?: number;
60
- autoFocus?: boolean;
61
- activeDescendantId?: string;
62
- tabIndex?: number;
63
- disabled?: boolean;
64
- placeholder?: React.ReactNode;
65
- removeIcon?: RenderNode;
66
- prefix?: React.ReactNode;
67
- maxTagCount?: number | 'responsive';
68
- maxTagTextLength?: number;
69
- maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
70
- tagRender?: (props: CustomTagProps) => React.ReactElement;
71
- /** Check if `tokenSeparators` contains `\n` or `\r\n` */
72
- tokenWithEnter?: boolean;
73
- choiceTransitionName?: string;
74
- onToggleOpen: (open?: boolean) => void;
75
- /** `onSearch` returns go next step boolean to check if need do toggle open */
76
- onSearch: (searchText: string, fromTyping: boolean, isCompositing: boolean) => boolean;
77
- onSearchSubmit?: (searchText: string) => void;
78
- onRemove: (value: DisplayValueType) => void;
79
- onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
80
- onInputBlur?: () => void;
81
- }
82
- declare const ForwardSelector: React.ForwardRefExoticComponent<SelectorProps & React.RefAttributes<RefSelectorProps>>;
83
- export default ForwardSelector;
@@ -1,189 +0,0 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- /**
3
- * Cursor rule:
4
- * 1. Only `showSearch` enabled
5
- * 2. Only `open` is `true`
6
- * 3. When typing, set `open` to `true` which hit rule of 2
7
- *
8
- * Accessibility:
9
- * - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
10
- */
11
-
12
- import KeyCode from "@rc-component/util/es/KeyCode";
13
- import * as React from 'react';
14
- import { useRef } from 'react';
15
- import useLock from "../hooks/useLock";
16
- import { isValidateOpenKey } from "../utils/keyUtil";
17
- import MultipleSelector from "./MultipleSelector";
18
- import SingleSelector from "./SingleSelector";
19
- import classNames from 'classnames';
20
- const Selector = (props, ref) => {
21
- const inputRef = useRef(null);
22
- const compositionStatusRef = useRef(false);
23
- const {
24
- prefixClassName,
25
- prefixStyle,
26
- prefixCls,
27
- open,
28
- mode,
29
- showSearch,
30
- tokenWithEnter,
31
- disabled,
32
- prefix,
33
- autoClearSearchValue,
34
- onSearch,
35
- onSearchSubmit,
36
- onToggleOpen,
37
- onInputKeyDown,
38
- onInputBlur
39
- } = props;
40
-
41
- // ======================= Ref =======================
42
- const containerRef = React.useRef(null);
43
- React.useImperativeHandle(ref, () => ({
44
- focus: options => {
45
- inputRef.current.focus(options);
46
- },
47
- blur: () => {
48
- inputRef.current.blur();
49
- },
50
- nativeElement: containerRef.current
51
- }));
52
-
53
- // ====================== Input ======================
54
- const [getInputMouseDown, setInputMouseDown] = useLock(0);
55
- const onInternalInputKeyDown = event => {
56
- const {
57
- which
58
- } = event;
59
-
60
- // Compatible with multiple lines in TextArea
61
- const isTextAreaElement = inputRef.current instanceof HTMLTextAreaElement;
62
- if (!isTextAreaElement && open && (which === KeyCode.UP || which === KeyCode.DOWN)) {
63
- event.preventDefault();
64
- }
65
- if (onInputKeyDown) {
66
- onInputKeyDown(event);
67
- }
68
- if (which === KeyCode.ENTER && mode === 'tags' && !compositionStatusRef.current && !open) {
69
- // When menu isn't open, OptionList won't trigger a value change
70
- // So when enter is pressed, the tag's input value should be emitted here to let selector know
71
- onSearchSubmit?.(event.target.value);
72
- }
73
- // Move within the text box
74
- if (isTextAreaElement && !open && ~[KeyCode.UP, KeyCode.DOWN, KeyCode.LEFT, KeyCode.RIGHT].indexOf(which)) {
75
- return;
76
- }
77
- if (isValidateOpenKey(which)) {
78
- onToggleOpen(true);
79
- }
80
- };
81
-
82
- /**
83
- * We can not use `findDOMNode` sine it will get warning,
84
- * have to use timer to check if is input element.
85
- */
86
- const onInternalInputMouseDown = () => {
87
- setInputMouseDown(true);
88
- };
89
-
90
- // When paste come, ignore next onChange
91
- const pastedTextRef = useRef(null);
92
- const triggerOnSearch = value => {
93
- if (onSearch(value, true, compositionStatusRef.current) !== false) {
94
- onToggleOpen(true);
95
- }
96
- };
97
- const onInputCompositionStart = () => {
98
- compositionStatusRef.current = true;
99
- };
100
- const onInputCompositionEnd = e => {
101
- compositionStatusRef.current = false;
102
-
103
- // Trigger search again to support `tokenSeparators` with typewriting
104
- if (mode !== 'combobox') {
105
- triggerOnSearch(e.target.value);
106
- }
107
- };
108
- const onInputChange = event => {
109
- let {
110
- target: {
111
- value
112
- }
113
- } = event;
114
-
115
- // Pasted text should replace back to origin content
116
- if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) {
117
- // CRLF will be treated as a single space for input element
118
- const replacedText = pastedTextRef.current.replace(/[\r\n]+$/, '').replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' ');
119
- value = value.replace(replacedText, pastedTextRef.current);
120
- }
121
- pastedTextRef.current = null;
122
- triggerOnSearch(value);
123
- };
124
- const onInputPaste = e => {
125
- const {
126
- clipboardData
127
- } = e;
128
- const value = clipboardData?.getData('text');
129
- pastedTextRef.current = value || '';
130
- };
131
- const onClick = ({
132
- target
133
- }) => {
134
- if (target !== inputRef.current) {
135
- // Should focus input if click the selector
136
- const isIE = document.body.style.msTouchAction !== undefined;
137
- if (isIE) {
138
- setTimeout(() => {
139
- inputRef.current.focus();
140
- });
141
- } else {
142
- inputRef.current.focus();
143
- }
144
- }
145
- };
146
- const onMouseDown = event => {
147
- const inputMouseDown = getInputMouseDown();
148
-
149
- // when mode is combobox and it is disabled, don't prevent default behavior
150
- // https://github.com/ant-design/ant-design/issues/37320
151
- // https://github.com/ant-design/ant-design/issues/48281
152
- if (event.target !== inputRef.current && !inputMouseDown && !(mode === 'combobox' && disabled)) {
153
- event.preventDefault();
154
- }
155
- if (mode !== 'combobox' && (!showSearch || !inputMouseDown) || !open) {
156
- if (open && autoClearSearchValue !== false) {
157
- onSearch('', true, false);
158
- }
159
- onToggleOpen();
160
- }
161
- };
162
-
163
- // ================= Inner Selector ==================
164
- const sharedProps = {
165
- inputRef,
166
- onInputKeyDown: onInternalInputKeyDown,
167
- onInputMouseDown: onInternalInputMouseDown,
168
- onInputChange,
169
- onInputPaste,
170
- onInputCompositionStart,
171
- onInputCompositionEnd,
172
- onInputBlur
173
- };
174
- const selectNode = mode === 'multiple' || mode === 'tags' ? /*#__PURE__*/React.createElement(MultipleSelector, _extends({}, props, sharedProps)) : /*#__PURE__*/React.createElement(SingleSelector, _extends({}, props, sharedProps));
175
- return /*#__PURE__*/React.createElement("div", {
176
- ref: containerRef,
177
- className: `${prefixCls}-selector`,
178
- onClick: onClick,
179
- onMouseDown: onMouseDown
180
- }, prefix && /*#__PURE__*/React.createElement("div", {
181
- className: classNames(`${prefixCls}-prefix`, prefixClassName),
182
- style: prefixStyle
183
- }, prefix), selectNode);
184
- };
185
- const ForwardSelector = /*#__PURE__*/React.forwardRef(Selector);
186
- if (process.env.NODE_ENV !== 'production') {
187
- ForwardSelector.displayName = 'Selector';
188
- }
189
- export default ForwardSelector;
@@ -1,5 +0,0 @@
1
- /**
2
- * Similar with `useLock`, but this hook will always execute last value.
3
- * When set to `true`, it will keep `true` for a short time even if `false` is set.
4
- */
5
- export default function useDelayReset(timeout?: number): [boolean, (val: boolean, callback?: () => void) => void, () => void];
@@ -1,33 +0,0 @@
1
- import * as React from 'react';
2
-
3
- /**
4
- * Similar with `useLock`, but this hook will always execute last value.
5
- * When set to `true`, it will keep `true` for a short time even if `false` is set.
6
- */
7
- export default function useDelayReset(timeout = 10) {
8
- const [bool, setBool] = React.useState(false);
9
- const delayRef = React.useRef(null);
10
- const cancelLatest = () => {
11
- window.clearTimeout(delayRef.current);
12
- };
13
- React.useEffect(() => {
14
- return () => {
15
- cancelLatest();
16
- };
17
- }, []);
18
- const delaySetBool = (value, callback) => {
19
- cancelLatest();
20
- if (value === true) {
21
- // true 值立即设置
22
- setBool(true);
23
- callback?.();
24
- } else {
25
- // false 值延迟设置
26
- delayRef.current = window.setTimeout(() => {
27
- setBool(false);
28
- callback?.();
29
- }, timeout);
30
- }
31
- };
32
- return [bool, delaySetBool, cancelLatest];
33
- }
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- /**
3
- * Wrap `React.useLayoutEffect` which will not throw warning message in test env
4
- */
5
- export default function useLayoutEffect(effect: React.EffectCallback, deps?: React.DependencyList): void;
@@ -1,17 +0,0 @@
1
- /* eslint-disable react-hooks/rules-of-hooks */
2
- import * as React from 'react';
3
- import { isBrowserClient } from "../utils/commonUtil";
4
-
5
- /**
6
- * Wrap `React.useLayoutEffect` which will not throw warning message in test env
7
- */
8
- export default function useLayoutEffect(effect, deps) {
9
- // Never happen in test env
10
- if (isBrowserClient) {
11
- /* istanbul ignore next */
12
- React.useLayoutEffect(effect, deps);
13
- } else {
14
- React.useEffect(effect, deps);
15
- }
16
- }
17
- /* eslint-enable */
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- type InputRef = HTMLInputElement | HTMLTextAreaElement;
3
- interface InputProps {
4
- prefixCls: string;
5
- id: string;
6
- inputElement: React.ReactElement;
7
- disabled: boolean;
8
- autoFocus: boolean;
9
- autoComplete: string;
10
- editable: boolean;
11
- activeDescendantId?: string;
12
- value: string;
13
- maxLength?: number;
14
- open: boolean;
15
- tabIndex: number;
16
- /** Pass accessibility props to input */
17
- attrs: Record<string, unknown>;
18
- onKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
19
- onMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
20
- onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
21
- onPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
22
- onBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
23
- onCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
24
- onCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement | HTMLElement>;
25
- }
26
- declare const RefInput: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<InputRef>>;
27
- export default RefInput;
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- var _classnames = _interopRequireDefault(require("classnames"));
9
- var _ref = require("@rc-component/util/lib/ref");
10
- var _warning = require("@rc-component/util/lib/warning");
11
- var _composeProps = _interopRequireDefault(require("@rc-component/util/lib/composeProps"));
12
- var _useBaseProps = _interopRequireDefault(require("../hooks/useBaseProps"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
- const Input = (props, ref) => {
17
- const {
18
- prefixCls,
19
- id,
20
- inputElement,
21
- autoComplete,
22
- editable,
23
- activeDescendantId,
24
- value,
25
- open,
26
- attrs,
27
- ...restProps
28
- } = props;
29
- const {
30
- classNames: contextClassNames,
31
- styles: contextStyles
32
- } = (0, _useBaseProps.default)() || {};
33
- let inputNode = inputElement || /*#__PURE__*/React.createElement("input", null);
34
- const {
35
- ref: originRef,
36
- props: originProps
37
- } = inputNode;
38
- (0, _warning.warning)(!('maxLength' in inputNode.props), `Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.`);
39
- inputNode = /*#__PURE__*/React.cloneElement(inputNode, {
40
- type: 'search',
41
- ...(0, _composeProps.default)(restProps, originProps, true),
42
- // Override over origin props
43
- id,
44
- ref: (0, _ref.composeRef)(ref, originRef),
45
- autoComplete: autoComplete || 'off',
46
- className: (0, _classnames.default)(`${prefixCls}-selection-search-input`, originProps.className, contextClassNames?.input),
47
- role: 'combobox',
48
- 'aria-expanded': open || false,
49
- 'aria-haspopup': 'listbox',
50
- 'aria-owns': `${id}_list`,
51
- 'aria-autocomplete': 'list',
52
- 'aria-controls': `${id}_list`,
53
- 'aria-activedescendant': open ? activeDescendantId : undefined,
54
- ...attrs,
55
- value: editable ? value : '',
56
- readOnly: !editable,
57
- unselectable: !editable ? 'on' : null,
58
- style: {
59
- ...originProps.style,
60
- opacity: editable ? null : 0,
61
- ...contextStyles?.input
62
- }
63
- });
64
- return inputNode;
65
- };
66
- const RefInput = /*#__PURE__*/React.forwardRef(Input);
67
- if (process.env.NODE_ENV !== 'production') {
68
- RefInput.displayName = 'Input';
69
- }
70
- var _default = exports.default = RefInput;
@@ -1,16 +0,0 @@
1
- import * as React from 'react';
2
- import type { InnerSelectorProps } from '.';
3
- import type { DisplayValueType, RenderNode, CustomTagProps } from '../BaseSelect';
4
- interface SelectorProps extends InnerSelectorProps {
5
- removeIcon?: RenderNode;
6
- maxTagCount?: number | 'responsive';
7
- maxTagTextLength?: number;
8
- maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
9
- tokenSeparators?: string[];
10
- tagRender?: (props: CustomTagProps) => React.ReactElement;
11
- onToggleOpen: (open?: boolean) => void;
12
- choiceTransitionName?: string;
13
- onRemove: (value: DisplayValueType) => void;
14
- }
15
- declare const SelectSelector: React.FC<SelectorProps>;
16
- export default SelectSelector;
@@ -1,8 +0,0 @@
1
- import * as React from 'react';
2
- import type { InnerSelectorProps } from '.';
3
- interface SelectorProps extends InnerSelectorProps {
4
- inputElement: React.ReactElement;
5
- activeValue: string;
6
- }
7
- declare const SingleSelector: React.FC<SelectorProps>;
8
- export default SingleSelector;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
9
- var _Input = _interopRequireDefault(require("./Input"));
10
- var _commonUtil = require("../utils/commonUtil");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- const SingleSelector = props => {
15
- const {
16
- inputElement,
17
- prefixCls,
18
- id,
19
- inputRef,
20
- disabled,
21
- autoFocus,
22
- autoComplete,
23
- activeDescendantId,
24
- mode,
25
- open,
26
- values,
27
- placeholder,
28
- tabIndex,
29
- showSearch,
30
- searchValue,
31
- activeValue,
32
- maxLength,
33
- onInputKeyDown,
34
- onInputMouseDown,
35
- onInputChange,
36
- onInputPaste,
37
- onInputCompositionStart,
38
- onInputCompositionEnd,
39
- onInputBlur,
40
- title
41
- } = props;
42
- const [inputChanged, setInputChanged] = React.useState(false);
43
- const combobox = mode === 'combobox';
44
- const inputEditable = combobox || showSearch;
45
- const item = values[0];
46
- let inputValue = searchValue || '';
47
- if (combobox && activeValue && !inputChanged) {
48
- inputValue = activeValue;
49
- }
50
- React.useEffect(() => {
51
- if (combobox) {
52
- setInputChanged(false);
53
- }
54
- }, [combobox, activeValue]);
55
-
56
- // Not show text when closed expect combobox mode
57
- const hasTextInput = mode !== 'combobox' && !open && !showSearch ? false : !!inputValue;
58
-
59
- // Get title of selection item
60
- const selectionTitle = title === undefined ? (0, _commonUtil.getTitle)(item) : title;
61
- const placeholderNode = React.useMemo(() => {
62
- if (item) {
63
- return null;
64
- }
65
- return /*#__PURE__*/React.createElement("span", {
66
- className: `${prefixCls}-selection-placeholder`,
67
- style: hasTextInput ? {
68
- visibility: 'hidden'
69
- } : undefined
70
- }, placeholder);
71
- }, [item, hasTextInput, placeholder, prefixCls]);
72
- return /*#__PURE__*/React.createElement("span", {
73
- className: `${prefixCls}-selection-wrap`
74
- }, /*#__PURE__*/React.createElement("span", {
75
- className: `${prefixCls}-selection-search`
76
- }, /*#__PURE__*/React.createElement(_Input.default, {
77
- ref: inputRef,
78
- prefixCls: prefixCls,
79
- id: id,
80
- open: open,
81
- inputElement: inputElement,
82
- disabled: disabled,
83
- autoFocus: autoFocus,
84
- autoComplete: autoComplete,
85
- editable: inputEditable,
86
- activeDescendantId: activeDescendantId,
87
- value: inputValue,
88
- onKeyDown: onInputKeyDown,
89
- onMouseDown: onInputMouseDown,
90
- onChange: e => {
91
- setInputChanged(true);
92
- onInputChange(e);
93
- },
94
- onPaste: onInputPaste,
95
- onCompositionStart: onInputCompositionStart,
96
- onCompositionEnd: onInputCompositionEnd,
97
- onBlur: onInputBlur,
98
- tabIndex: tabIndex,
99
- attrs: (0, _pickAttrs.default)(props, true),
100
- maxLength: combobox ? maxLength : undefined
101
- })), !combobox && item ? /*#__PURE__*/React.createElement("span", {
102
- className: `${prefixCls}-selection-item`,
103
- title: selectionTitle
104
- // 当 Select 已经选中选项时,还需 selection 隐藏但留在原地占位
105
- // https://github.com/ant-design/ant-design/issues/27688
106
- // https://github.com/ant-design/ant-design/issues/41530
107
- ,
108
- style: hasTextInput ? {
109
- visibility: 'hidden'
110
- } : undefined
111
- }, item.label) : null, placeholderNode);
112
- };
113
- var _default = exports.default = SingleSelector;