@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.
- package/assets/index.css +63 -0
- package/assets/index.less +1 -0
- package/assets/patch.less +83 -0
- package/es/BaseSelect/index.d.ts +14 -3
- package/es/BaseSelect/index.js +137 -200
- package/es/OptionList.js +3 -3
- package/es/Select.d.ts +1 -1
- package/es/Select.js +5 -9
- package/es/SelectInput/Affix.d.ts +5 -0
- package/es/SelectInput/Affix.js +12 -0
- package/es/SelectInput/Content/MultipleContent.d.ts +4 -0
- package/es/SelectInput/Content/MultipleContent.js +152 -0
- package/es/SelectInput/Content/Placeholder.d.ts +5 -0
- package/es/SelectInput/Content/Placeholder.js +21 -0
- package/es/SelectInput/Content/SingleContent.d.ts +4 -0
- package/es/SelectInput/Content/SingleContent.js +98 -0
- package/es/SelectInput/Content/index.d.ts +6 -0
- package/es/SelectInput/Content/index.js +37 -0
- package/es/SelectInput/Input.d.ts +20 -0
- package/es/SelectInput/Input.js +214 -0
- package/es/SelectInput/context.d.ts +6 -0
- package/es/SelectInput/context.js +6 -0
- package/es/SelectInput/index.d.ts +39 -0
- package/es/SelectInput/index.js +189 -0
- package/es/SelectTrigger.d.ts +1 -0
- package/es/SelectTrigger.js +5 -3
- package/es/TransBtn.d.ts +10 -0
- package/es/TransBtn.js +12 -2
- package/es/hooks/useAllowClear.d.ts +8 -7
- package/es/hooks/useAllowClear.js +21 -23
- package/es/hooks/useBaseProps.d.ts +1 -0
- package/es/hooks/useComponents.d.ts +12 -0
- package/es/hooks/useComponents.js +23 -0
- package/es/hooks/useOpen.d.ts +15 -0
- package/es/hooks/useOpen.js +76 -0
- package/es/hooks/useSearchConfig.d.ts +2 -2
- package/es/hooks/useSearchConfig.js +3 -3
- package/es/hooks/useSelectTriggerControl.d.ts +1 -1
- package/es/hooks/useSelectTriggerControl.js +16 -21
- package/es/utils/keyUtil.js +4 -0
- package/lib/BaseSelect/index.d.ts +14 -3
- package/lib/BaseSelect/index.js +137 -201
- package/lib/OptionList.js +3 -3
- package/lib/Select.d.ts +1 -1
- package/lib/Select.js +5 -9
- package/lib/SelectInput/Affix.d.ts +5 -0
- package/lib/{hooks/useLayoutEffect.js → SelectInput/Affix.js} +11 -16
- package/lib/SelectInput/Content/MultipleContent.d.ts +4 -0
- package/lib/{Selector/MultipleSelector.js → SelectInput/Content/MultipleContent.js} +71 -104
- package/lib/SelectInput/Content/Placeholder.d.ts +5 -0
- package/lib/SelectInput/Content/Placeholder.js +29 -0
- package/lib/SelectInput/Content/SingleContent.d.ts +4 -0
- package/lib/SelectInput/Content/SingleContent.js +107 -0
- package/lib/SelectInput/Content/index.d.ts +6 -0
- package/lib/SelectInput/Content/index.js +46 -0
- package/lib/SelectInput/Input.d.ts +20 -0
- package/lib/SelectInput/Input.js +223 -0
- package/lib/SelectInput/context.d.ts +6 -0
- package/lib/SelectInput/context.js +15 -0
- package/lib/SelectInput/index.d.ts +39 -0
- package/lib/SelectInput/index.js +198 -0
- package/lib/SelectTrigger.d.ts +1 -0
- package/lib/SelectTrigger.js +5 -3
- package/lib/TransBtn.d.ts +10 -0
- package/lib/TransBtn.js +12 -3
- package/lib/hooks/useAllowClear.d.ts +8 -7
- package/lib/hooks/useAllowClear.js +21 -24
- package/lib/hooks/useBaseProps.d.ts +1 -0
- package/lib/hooks/useComponents.d.ts +12 -0
- package/lib/hooks/{useDelayReset.js → useComponents.js} +21 -30
- package/lib/hooks/useOpen.d.ts +15 -0
- package/lib/hooks/useOpen.js +82 -0
- package/lib/hooks/useSearchConfig.d.ts +2 -2
- package/lib/hooks/useSearchConfig.js +3 -3
- package/lib/hooks/useSelectTriggerControl.d.ts +1 -1
- package/lib/hooks/useSelectTriggerControl.js +16 -21
- package/lib/utils/keyUtil.js +4 -0
- package/package.json +5 -4
- package/es/Selector/Input.d.ts +0 -27
- package/es/Selector/Input.js +0 -61
- package/es/Selector/MultipleSelector.d.ts +0 -16
- package/es/Selector/MultipleSelector.js +0 -185
- package/es/Selector/SingleSelector.d.ts +0 -8
- package/es/Selector/SingleSelector.js +0 -104
- package/es/Selector/index.d.ts +0 -83
- package/es/Selector/index.js +0 -189
- package/es/hooks/useDelayReset.d.ts +0 -5
- package/es/hooks/useDelayReset.js +0 -33
- package/es/hooks/useLayoutEffect.d.ts +0 -5
- package/es/hooks/useLayoutEffect.js +0 -17
- package/lib/Selector/Input.d.ts +0 -27
- package/lib/Selector/Input.js +0 -70
- package/lib/Selector/MultipleSelector.d.ts +0 -16
- package/lib/Selector/SingleSelector.d.ts +0 -8
- package/lib/Selector/SingleSelector.js +0 -113
- package/lib/Selector/index.d.ts +0 -83
- package/lib/Selector/index.js +0 -196
- package/lib/hooks/useDelayReset.d.ts +0 -5
- package/lib/hooks/useLayoutEffect.d.ts +0 -5
|
@@ -3,38 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = useComponents;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
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); }
|
|
9
9
|
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; }
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
React.useEffect(() => {
|
|
21
|
-
return () => {
|
|
22
|
-
cancelLatest();
|
|
23
|
-
};
|
|
24
|
-
}, []);
|
|
25
|
-
const delaySetBool = (value, callback) => {
|
|
26
|
-
cancelLatest();
|
|
27
|
-
if (value === true) {
|
|
28
|
-
// true 值立即设置
|
|
29
|
-
setBool(true);
|
|
30
|
-
callback?.();
|
|
31
|
-
} else {
|
|
32
|
-
// false 值延迟设置
|
|
33
|
-
delayRef.current = window.setTimeout(() => {
|
|
34
|
-
setBool(false);
|
|
35
|
-
callback?.();
|
|
36
|
-
}, timeout);
|
|
10
|
+
function useComponents(components, getInputElement, getRawInputElement) {
|
|
11
|
+
return React.useMemo(() => {
|
|
12
|
+
let {
|
|
13
|
+
root,
|
|
14
|
+
input
|
|
15
|
+
} = components || {};
|
|
16
|
+
|
|
17
|
+
// root: getRawInputElement
|
|
18
|
+
if (getRawInputElement) {
|
|
19
|
+
root = getRawInputElement();
|
|
37
20
|
}
|
|
38
|
-
|
|
39
|
-
|
|
21
|
+
|
|
22
|
+
// input: getInputElement
|
|
23
|
+
if (getInputElement) {
|
|
24
|
+
input = getInputElement();
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
root,
|
|
28
|
+
input
|
|
29
|
+
};
|
|
30
|
+
}, [components, getInputElement, getRawInputElement]);
|
|
40
31
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trigger by latest open call, if nextOpen is undefined, means toggle.
|
|
3
|
+
* ignoreNext will skip next call in the macro task queue.
|
|
4
|
+
*/
|
|
5
|
+
export type TriggerOpenType = (nextOpen?: boolean, ignoreNext?: boolean) => void;
|
|
6
|
+
/**
|
|
7
|
+
* When `open` is controlled, follow the controlled value;
|
|
8
|
+
* Otherwise use uncontrolled logic.
|
|
9
|
+
* Setting `open` takes effect immediately,
|
|
10
|
+
* but setting it to `false` is delayed via MessageChannel.
|
|
11
|
+
*
|
|
12
|
+
* SSR handling: During SSR, `open` is always false to avoid Portal issues.
|
|
13
|
+
* On client-side hydration, it syncs with the actual open state.
|
|
14
|
+
*/
|
|
15
|
+
export default function useOpen(propOpen: boolean, onOpen: (nextOpen: boolean) => void, postOpen: (nextOpen: boolean) => boolean): [boolean, TriggerOpenType];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useOpen;
|
|
7
|
+
var _util = require("@rc-component/util");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
const internalMacroTask = fn => {
|
|
10
|
+
const channel = new MessageChannel();
|
|
11
|
+
channel.port1.onmessage = fn;
|
|
12
|
+
channel.port2.postMessage(null);
|
|
13
|
+
};
|
|
14
|
+
const macroTask = (fn, times = 1) => {
|
|
15
|
+
if (times <= 0) {
|
|
16
|
+
fn();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
internalMacroTask(() => {
|
|
20
|
+
macroTask(fn, times - 1);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Trigger by latest open call, if nextOpen is undefined, means toggle.
|
|
26
|
+
* ignoreNext will skip next call in the macro task queue.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* When `open` is controlled, follow the controlled value;
|
|
31
|
+
* Otherwise use uncontrolled logic.
|
|
32
|
+
* Setting `open` takes effect immediately,
|
|
33
|
+
* but setting it to `false` is delayed via MessageChannel.
|
|
34
|
+
*
|
|
35
|
+
* SSR handling: During SSR, `open` is always false to avoid Portal issues.
|
|
36
|
+
* On client-side hydration, it syncs with the actual open state.
|
|
37
|
+
*/
|
|
38
|
+
function useOpen(propOpen, onOpen, postOpen) {
|
|
39
|
+
// SSR not support Portal which means we need delay `open` for the first time render
|
|
40
|
+
const [rendered, setRendered] = (0, _react.useState)(false);
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
setRendered(true);
|
|
43
|
+
}, []);
|
|
44
|
+
const [stateOpen, internalSetOpen] = (0, _util.useControlledState)(false, propOpen);
|
|
45
|
+
|
|
46
|
+
// During SSR, always return false for open state
|
|
47
|
+
const ssrSafeOpen = rendered ? stateOpen : false;
|
|
48
|
+
const mergedOpen = postOpen(ssrSafeOpen);
|
|
49
|
+
const taskIdRef = (0, _react.useRef)(0);
|
|
50
|
+
const taskLockRef = (0, _react.useRef)(false);
|
|
51
|
+
const triggerEvent = (0, _util.useEvent)(nextOpen => {
|
|
52
|
+
if (onOpen && mergedOpen !== nextOpen) {
|
|
53
|
+
onOpen(nextOpen);
|
|
54
|
+
}
|
|
55
|
+
internalSetOpen(nextOpen);
|
|
56
|
+
});
|
|
57
|
+
const toggleOpen = (0, _util.useEvent)((nextOpen, ignoreNext = false) => {
|
|
58
|
+
taskIdRef.current += 1;
|
|
59
|
+
const id = taskIdRef.current;
|
|
60
|
+
const nextOpenVal = typeof nextOpen === 'boolean' ? nextOpen : !mergedOpen;
|
|
61
|
+
|
|
62
|
+
// Since `mergedOpen` is post-processed, we need to check if the value really changed
|
|
63
|
+
if (nextOpenVal) {
|
|
64
|
+
triggerEvent(true);
|
|
65
|
+
|
|
66
|
+
// Lock if needed
|
|
67
|
+
if (ignoreNext) {
|
|
68
|
+
taskLockRef.current = ignoreNext;
|
|
69
|
+
macroTask(() => {
|
|
70
|
+
taskLockRef.current = false;
|
|
71
|
+
}, 2);
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
macroTask(() => {
|
|
76
|
+
if (id === taskIdRef.current && !taskLockRef.current) {
|
|
77
|
+
triggerEvent(false);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return [mergedOpen, toggleOpen];
|
|
82
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { SearchConfig, DefaultOptionType } from
|
|
2
|
-
export default function useSearchConfig(showSearch: boolean | SearchConfig<DefaultOptionType> | undefined, props: SearchConfig<DefaultOptionType>): [boolean, SearchConfig<DefaultOptionType>];
|
|
1
|
+
import type { SearchConfig, DefaultOptionType, SelectProps } from '../Select';
|
|
2
|
+
export default function useSearchConfig(showSearch: boolean | SearchConfig<DefaultOptionType> | undefined, props: SearchConfig<DefaultOptionType>, mode: SelectProps<DefaultOptionType>['mode']): [boolean, SearchConfig<DefaultOptionType>];
|
|
@@ -8,7 +8,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
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); }
|
|
9
9
|
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; }
|
|
10
10
|
// Convert `showSearch` to unique config
|
|
11
|
-
function useSearchConfig(showSearch, props) {
|
|
11
|
+
function useSearchConfig(showSearch, props, mode) {
|
|
12
12
|
const {
|
|
13
13
|
filterOption,
|
|
14
14
|
searchValue,
|
|
@@ -28,6 +28,6 @@ function useSearchConfig(showSearch, props) {
|
|
|
28
28
|
autoClearSearchValue,
|
|
29
29
|
...(isObject ? showSearch : {})
|
|
30
30
|
};
|
|
31
|
-
return [isObject ? true : showSearch, searchConfig];
|
|
32
|
-
}, [showSearch, filterOption, searchValue, optionFilterProp, filterSort, onSearch, autoClearSearchValue]);
|
|
31
|
+
return [isObject || mode === 'combobox' || mode === 'tags' || mode === 'multiple' && showSearch === undefined ? true : showSearch, searchConfig];
|
|
32
|
+
}, [mode, showSearch, filterOption, searchValue, optionFilterProp, filterSort, onSearch, autoClearSearchValue]);
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function useSelectTriggerControl(elements: () => (HTMLElement | undefined)[], open: boolean, triggerOpen: (open: boolean) => void, customizedTrigger: boolean): void;
|
|
1
|
+
export default function useSelectTriggerControl(elements: () => (HTMLElement | SVGElement | undefined)[], open: boolean, triggerOpen: (open: boolean) => void, customizedTrigger: boolean): void;
|
|
@@ -5,31 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = useSelectTriggerControl;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _util = require("@rc-component/util");
|
|
8
9
|
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); }
|
|
9
10
|
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; }
|
|
10
11
|
function useSelectTriggerControl(elements, open, triggerOpen, customizedTrigger) {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// If trigger is customized, Trigger will take control of popupVisible
|
|
20
|
-
if (propsRef.current?.customizedTrigger) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
let target = event.target;
|
|
24
|
-
if (target.shadowRoot && event.composed) {
|
|
25
|
-
target = event.composedPath()[0] || target;
|
|
26
|
-
}
|
|
27
|
-
if (propsRef.current.open && elements().filter(element => element).every(element => !element.contains(target) && element !== target)) {
|
|
28
|
-
// Should trigger close
|
|
29
|
-
propsRef.current.triggerOpen(false);
|
|
30
|
-
}
|
|
12
|
+
const onGlobalMouseDown = (0, _util.useEvent)(event => {
|
|
13
|
+
// If trigger is customized, Trigger will take control of popupVisible
|
|
14
|
+
if (customizedTrigger) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let target = event.target;
|
|
18
|
+
if (target.shadowRoot && event.composed) {
|
|
19
|
+
target = event.composedPath()[0] || target;
|
|
31
20
|
}
|
|
21
|
+
if (open && elements().filter(element => element).every(element => !element.contains(target) && element !== target)) {
|
|
22
|
+
// Should trigger close
|
|
23
|
+
triggerOpen(false);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
React.useEffect(() => {
|
|
32
27
|
window.addEventListener('mousedown', onGlobalMouseDown);
|
|
33
28
|
return () => window.removeEventListener('mousedown', onGlobalMouseDown);
|
|
34
|
-
}, []);
|
|
29
|
+
}, [onGlobalMouseDown]);
|
|
35
30
|
}
|
package/lib/utils/keyUtil.js
CHANGED
|
@@ -16,6 +16,10 @@ function isValidateOpenKey(currentKeyCode) {
|
|
|
16
16
|
![
|
|
17
17
|
// System function button
|
|
18
18
|
_KeyCode.default.ESC, _KeyCode.default.SHIFT, _KeyCode.default.BACKSPACE, _KeyCode.default.TAB, _KeyCode.default.WIN_KEY, _KeyCode.default.ALT, _KeyCode.default.META, _KeyCode.default.WIN_KEY_RIGHT, _KeyCode.default.CTRL, _KeyCode.default.SEMICOLON, _KeyCode.default.EQUALS, _KeyCode.default.CAPS_LOCK, _KeyCode.default.CONTEXT_MENU,
|
|
19
|
+
// Arrow keys - should not trigger open when navigating in input
|
|
20
|
+
_KeyCode.default.UP,
|
|
21
|
+
// KeyCode.DOWN,
|
|
22
|
+
_KeyCode.default.LEFT, _KeyCode.default.RIGHT,
|
|
19
23
|
// F1-F12
|
|
20
24
|
_KeyCode.default.F1, _KeyCode.default.F2, _KeyCode.default.F3, _KeyCode.default.F4, _KeyCode.default.F5, _KeyCode.default.F6, _KeyCode.default.F7, _KeyCode.default.F8, _KeyCode.default.F9, _KeyCode.default.F10, _KeyCode.default.F11, _KeyCode.default.F12].includes(currentKeyCode)
|
|
21
25
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rc-component/select",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.0",
|
|
4
4
|
"description": "React Select",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.x"
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"react-dom": "*"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@rc-component/trigger": "^3.0.0",
|
|
53
52
|
"@rc-component/motion": "^1.1.4",
|
|
54
|
-
"@rc-component/
|
|
55
|
-
"
|
|
53
|
+
"@rc-component/trigger": "^3.0.0",
|
|
54
|
+
"@rc-component/util": "^1.3.0",
|
|
55
|
+
"clsx": "^2.1.1",
|
|
56
56
|
"rc-overflow": "^1.4.0",
|
|
57
57
|
"rc-virtual-list": "^3.5.2"
|
|
58
58
|
},
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@testing-library/jest-dom": "^6.4.5",
|
|
63
63
|
"@testing-library/react": "^15.0.6",
|
|
64
64
|
"@types/jest": "^29.5.12",
|
|
65
|
+
"@types/node": "^24.5.2",
|
|
65
66
|
"@types/react": "^18.3.0",
|
|
66
67
|
"@types/react-dom": "^18.3.0",
|
|
67
68
|
"babel-jest": "^29.6.1",
|
package/es/Selector/Input.d.ts
DELETED
|
@@ -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;
|
package/es/Selector/Input.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { composeRef } from "@rc-component/util/es/ref";
|
|
4
|
-
import { warning } from "@rc-component/util/es/warning";
|
|
5
|
-
import composeProps from "@rc-component/util/es/composeProps";
|
|
6
|
-
import useBaseProps from "../hooks/useBaseProps";
|
|
7
|
-
const Input = (props, ref) => {
|
|
8
|
-
const {
|
|
9
|
-
prefixCls,
|
|
10
|
-
id,
|
|
11
|
-
inputElement,
|
|
12
|
-
autoComplete,
|
|
13
|
-
editable,
|
|
14
|
-
activeDescendantId,
|
|
15
|
-
value,
|
|
16
|
-
open,
|
|
17
|
-
attrs,
|
|
18
|
-
...restProps
|
|
19
|
-
} = props;
|
|
20
|
-
const {
|
|
21
|
-
classNames: contextClassNames,
|
|
22
|
-
styles: contextStyles
|
|
23
|
-
} = useBaseProps() || {};
|
|
24
|
-
let inputNode = inputElement || /*#__PURE__*/React.createElement("input", null);
|
|
25
|
-
const {
|
|
26
|
-
ref: originRef,
|
|
27
|
-
props: originProps
|
|
28
|
-
} = inputNode;
|
|
29
|
-
warning(!('maxLength' in inputNode.props), `Passing 'maxLength' to input element directly may not work because input in BaseSelect is controlled.`);
|
|
30
|
-
inputNode = /*#__PURE__*/React.cloneElement(inputNode, {
|
|
31
|
-
type: 'search',
|
|
32
|
-
...composeProps(restProps, originProps, true),
|
|
33
|
-
// Override over origin props
|
|
34
|
-
id,
|
|
35
|
-
ref: composeRef(ref, originRef),
|
|
36
|
-
autoComplete: autoComplete || 'off',
|
|
37
|
-
className: classNames(`${prefixCls}-selection-search-input`, originProps.className, contextClassNames?.input),
|
|
38
|
-
role: 'combobox',
|
|
39
|
-
'aria-expanded': open || false,
|
|
40
|
-
'aria-haspopup': 'listbox',
|
|
41
|
-
'aria-owns': `${id}_list`,
|
|
42
|
-
'aria-autocomplete': 'list',
|
|
43
|
-
'aria-controls': `${id}_list`,
|
|
44
|
-
'aria-activedescendant': open ? activeDescendantId : undefined,
|
|
45
|
-
...attrs,
|
|
46
|
-
value: editable ? value : '',
|
|
47
|
-
readOnly: !editable,
|
|
48
|
-
unselectable: !editable ? 'on' : null,
|
|
49
|
-
style: {
|
|
50
|
-
...originProps.style,
|
|
51
|
-
opacity: editable ? null : 0,
|
|
52
|
-
...contextStyles?.input
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return inputNode;
|
|
56
|
-
};
|
|
57
|
-
const RefInput = /*#__PURE__*/React.forwardRef(Input);
|
|
58
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
59
|
-
RefInput.displayName = 'Input';
|
|
60
|
-
}
|
|
61
|
-
export 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,185 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
import pickAttrs from "@rc-component/util/es/pickAttrs";
|
|
5
|
-
import Overflow from 'rc-overflow';
|
|
6
|
-
import TransBtn from "../TransBtn";
|
|
7
|
-
import Input from "./Input";
|
|
8
|
-
import useLayoutEffect from "../hooks/useLayoutEffect";
|
|
9
|
-
import { getTitle } from "../utils/commonUtil";
|
|
10
|
-
function itemKey(value) {
|
|
11
|
-
return value.key ?? value.value;
|
|
12
|
-
}
|
|
13
|
-
const onPreventMouseDown = event => {
|
|
14
|
-
event.preventDefault();
|
|
15
|
-
event.stopPropagation();
|
|
16
|
-
};
|
|
17
|
-
const SelectSelector = props => {
|
|
18
|
-
const {
|
|
19
|
-
id,
|
|
20
|
-
prefixCls,
|
|
21
|
-
values,
|
|
22
|
-
open,
|
|
23
|
-
searchValue,
|
|
24
|
-
autoClearSearchValue,
|
|
25
|
-
inputRef,
|
|
26
|
-
placeholder,
|
|
27
|
-
disabled,
|
|
28
|
-
mode,
|
|
29
|
-
showSearch,
|
|
30
|
-
autoFocus,
|
|
31
|
-
autoComplete,
|
|
32
|
-
activeDescendantId,
|
|
33
|
-
tabIndex,
|
|
34
|
-
removeIcon,
|
|
35
|
-
maxTagCount,
|
|
36
|
-
maxTagTextLength,
|
|
37
|
-
maxTagPlaceholder = omittedValues => `+ ${omittedValues.length} ...`,
|
|
38
|
-
tagRender,
|
|
39
|
-
onToggleOpen,
|
|
40
|
-
onRemove,
|
|
41
|
-
onInputChange,
|
|
42
|
-
onInputPaste,
|
|
43
|
-
onInputKeyDown,
|
|
44
|
-
onInputMouseDown,
|
|
45
|
-
onInputCompositionStart,
|
|
46
|
-
onInputCompositionEnd,
|
|
47
|
-
onInputBlur
|
|
48
|
-
} = props;
|
|
49
|
-
const measureRef = React.useRef(null);
|
|
50
|
-
const [inputWidth, setInputWidth] = useState(0);
|
|
51
|
-
const [focused, setFocused] = useState(false);
|
|
52
|
-
const selectionPrefixCls = `${prefixCls}-selection`;
|
|
53
|
-
|
|
54
|
-
// ===================== Search ======================
|
|
55
|
-
const inputValue = open || mode === 'multiple' && autoClearSearchValue === false || mode === 'tags' ? searchValue : '';
|
|
56
|
-
const inputEditable = mode === 'tags' || mode === 'multiple' && autoClearSearchValue === false || showSearch && (open || focused);
|
|
57
|
-
|
|
58
|
-
// We measure width and set to the input immediately
|
|
59
|
-
useLayoutEffect(() => {
|
|
60
|
-
setInputWidth(measureRef.current.scrollWidth);
|
|
61
|
-
}, [inputValue]);
|
|
62
|
-
|
|
63
|
-
// ===================== Render ======================
|
|
64
|
-
// >>> Render Selector Node. Includes Item & Rest
|
|
65
|
-
const defaultRenderSelector = (item, content, itemDisabled, closable, onClose) => /*#__PURE__*/React.createElement("span", {
|
|
66
|
-
title: getTitle(item),
|
|
67
|
-
className: classNames(`${selectionPrefixCls}-item`, {
|
|
68
|
-
[`${selectionPrefixCls}-item-disabled`]: itemDisabled
|
|
69
|
-
})
|
|
70
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
71
|
-
className: `${selectionPrefixCls}-item-content`
|
|
72
|
-
}, content), closable && /*#__PURE__*/React.createElement(TransBtn, {
|
|
73
|
-
className: `${selectionPrefixCls}-item-remove`,
|
|
74
|
-
onMouseDown: onPreventMouseDown,
|
|
75
|
-
onClick: onClose,
|
|
76
|
-
customizeIcon: removeIcon
|
|
77
|
-
}, "\xD7"));
|
|
78
|
-
const customizeRenderSelector = (value, content, itemDisabled, closable, onClose, isMaxTag, info) => {
|
|
79
|
-
const onMouseDown = e => {
|
|
80
|
-
onPreventMouseDown(e);
|
|
81
|
-
onToggleOpen(!open);
|
|
82
|
-
};
|
|
83
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
84
|
-
onMouseDown: onMouseDown
|
|
85
|
-
}, tagRender({
|
|
86
|
-
label: content,
|
|
87
|
-
value,
|
|
88
|
-
index: info?.index,
|
|
89
|
-
disabled: itemDisabled,
|
|
90
|
-
closable,
|
|
91
|
-
onClose,
|
|
92
|
-
isMaxTag: !!isMaxTag
|
|
93
|
-
}));
|
|
94
|
-
};
|
|
95
|
-
const renderItem = (valueItem, info) => {
|
|
96
|
-
const {
|
|
97
|
-
disabled: itemDisabled,
|
|
98
|
-
label,
|
|
99
|
-
value
|
|
100
|
-
} = valueItem;
|
|
101
|
-
const closable = !disabled && !itemDisabled;
|
|
102
|
-
let displayLabel = label;
|
|
103
|
-
if (typeof maxTagTextLength === 'number') {
|
|
104
|
-
if (typeof label === 'string' || typeof label === 'number') {
|
|
105
|
-
const strLabel = String(displayLabel);
|
|
106
|
-
if (strLabel.length > maxTagTextLength) {
|
|
107
|
-
displayLabel = `${strLabel.slice(0, maxTagTextLength)}...`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const onClose = event => {
|
|
112
|
-
if (event) {
|
|
113
|
-
event.stopPropagation();
|
|
114
|
-
}
|
|
115
|
-
onRemove(valueItem);
|
|
116
|
-
};
|
|
117
|
-
return typeof tagRender === 'function' ? customizeRenderSelector(value, displayLabel, itemDisabled, closable, onClose, undefined, info) : defaultRenderSelector(valueItem, displayLabel, itemDisabled, closable, onClose);
|
|
118
|
-
};
|
|
119
|
-
const renderRest = omittedValues => {
|
|
120
|
-
// https://github.com/ant-design/ant-design/issues/48930
|
|
121
|
-
if (!values.length) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const content = typeof maxTagPlaceholder === 'function' ? maxTagPlaceholder(omittedValues) : maxTagPlaceholder;
|
|
125
|
-
return typeof tagRender === 'function' ? customizeRenderSelector(undefined, content, false, false, undefined, true) : defaultRenderSelector({
|
|
126
|
-
title: content
|
|
127
|
-
}, content, false);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// >>> Input Node
|
|
131
|
-
const inputNode = /*#__PURE__*/React.createElement("div", {
|
|
132
|
-
className: `${selectionPrefixCls}-search`,
|
|
133
|
-
style: {
|
|
134
|
-
width: inputWidth
|
|
135
|
-
},
|
|
136
|
-
onFocus: () => {
|
|
137
|
-
setFocused(true);
|
|
138
|
-
},
|
|
139
|
-
onBlur: () => {
|
|
140
|
-
setFocused(false);
|
|
141
|
-
}
|
|
142
|
-
}, /*#__PURE__*/React.createElement(Input, {
|
|
143
|
-
ref: inputRef,
|
|
144
|
-
open: open,
|
|
145
|
-
prefixCls: prefixCls,
|
|
146
|
-
id: id,
|
|
147
|
-
inputElement: null,
|
|
148
|
-
disabled: disabled,
|
|
149
|
-
autoFocus: autoFocus,
|
|
150
|
-
autoComplete: autoComplete,
|
|
151
|
-
editable: inputEditable,
|
|
152
|
-
activeDescendantId: activeDescendantId,
|
|
153
|
-
value: inputValue,
|
|
154
|
-
onKeyDown: onInputKeyDown,
|
|
155
|
-
onMouseDown: onInputMouseDown,
|
|
156
|
-
onChange: onInputChange,
|
|
157
|
-
onPaste: onInputPaste,
|
|
158
|
-
onCompositionStart: onInputCompositionStart,
|
|
159
|
-
onCompositionEnd: onInputCompositionEnd,
|
|
160
|
-
onBlur: onInputBlur,
|
|
161
|
-
tabIndex: tabIndex,
|
|
162
|
-
attrs: pickAttrs(props, true)
|
|
163
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
164
|
-
ref: measureRef,
|
|
165
|
-
className: `${selectionPrefixCls}-search-mirror`,
|
|
166
|
-
"aria-hidden": true
|
|
167
|
-
}, inputValue, "\xA0"));
|
|
168
|
-
|
|
169
|
-
// >>> Selections
|
|
170
|
-
const selectionNode = /*#__PURE__*/React.createElement(Overflow, {
|
|
171
|
-
prefixCls: `${selectionPrefixCls}-overflow`,
|
|
172
|
-
data: values,
|
|
173
|
-
renderItem: renderItem,
|
|
174
|
-
renderRest: renderRest,
|
|
175
|
-
suffix: inputNode,
|
|
176
|
-
itemKey: itemKey,
|
|
177
|
-
maxCount: maxTagCount
|
|
178
|
-
});
|
|
179
|
-
return /*#__PURE__*/React.createElement("span", {
|
|
180
|
-
className: `${selectionPrefixCls}-wrap`
|
|
181
|
-
}, selectionNode, !values.length && !inputValue && /*#__PURE__*/React.createElement("span", {
|
|
182
|
-
className: `${selectionPrefixCls}-placeholder`
|
|
183
|
-
}, placeholder));
|
|
184
|
-
};
|
|
185
|
-
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;
|