@rc-component/select 1.6.11 → 1.6.13
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.
|
@@ -16,7 +16,8 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
16
16
|
activeValue,
|
|
17
17
|
displayValues,
|
|
18
18
|
maxLength,
|
|
19
|
-
mode
|
|
19
|
+
mode,
|
|
20
|
+
components
|
|
20
21
|
} = useSelectInputContext();
|
|
21
22
|
const {
|
|
22
23
|
triggerOpen,
|
|
@@ -68,7 +69,9 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
68
69
|
const showHasValueCls = displayValue && displayValue.label !== null && displayValue.label !== undefined && String(displayValue.label).trim() !== '';
|
|
69
70
|
|
|
70
71
|
// Render value
|
|
71
|
-
|
|
72
|
+
// Only render value when not using custom input in combobox mode
|
|
73
|
+
const shouldRenderValue = !(combobox && components?.input);
|
|
74
|
+
const renderValue = shouldRenderValue ? displayValue ? hasOptionStyle ? /*#__PURE__*/React.createElement("div", {
|
|
72
75
|
className: clsx(`${prefixCls}-content-value`, optionClassName),
|
|
73
76
|
style: {
|
|
74
77
|
...(mergedSearchValue ? {
|
|
@@ -79,8 +82,7 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
79
82
|
title: optionTitle
|
|
80
83
|
}, displayValue.label) : displayValue.label : /*#__PURE__*/React.createElement(Placeholder, {
|
|
81
84
|
show: !mergedSearchValue
|
|
82
|
-
});
|
|
83
|
-
|
|
85
|
+
}) : null;
|
|
84
86
|
// Render
|
|
85
87
|
return /*#__PURE__*/React.createElement("div", {
|
|
86
88
|
className: clsx(`${prefixCls}-content`, showHasValueCls && `${prefixCls}-content-has-value`, mergedSearchValue && `${prefixCls}-content-has-search-value`, hasOptionStyle && `${prefixCls}-content-has-option-style`, classNames?.content),
|
package/es/SelectInput/index.js
CHANGED
|
@@ -114,13 +114,18 @@ export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
|
114
114
|
// When icon is dynamic render, the parentNode will miss
|
|
115
115
|
// so we need to mark the event directly
|
|
116
116
|
event.nativeEvent._ori_target = inputDOM;
|
|
117
|
-
|
|
117
|
+
const isClickOnInput = inputDOM === event.target || inputDOM?.contains(event.target);
|
|
118
|
+
if (inputDOM && !isClickOnInput) {
|
|
118
119
|
event.preventDefault();
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
// Check if we should prevent closing when clicking on selector
|
|
122
123
|
// Don't close if: open && not multiple && (combobox mode || showSearch)
|
|
123
|
-
const
|
|
124
|
+
const shouldPreventCloseOnSingle = triggerOpen && !multiple && (mode === 'combobox' || showSearch);
|
|
125
|
+
|
|
126
|
+
// Don't close if: open && multiple && click on input
|
|
127
|
+
const shouldPreventCloseOnMultipleInput = triggerOpen && multiple && isClickOnInput;
|
|
128
|
+
const shouldPreventClose = shouldPreventCloseOnSingle || shouldPreventCloseOnMultipleInput;
|
|
124
129
|
if (!event.nativeEvent._select_lazy) {
|
|
125
130
|
inputRef.current?.focus();
|
|
126
131
|
|
|
@@ -154,13 +159,28 @@ export default /*#__PURE__*/React.forwardRef(function SelectInput(props, ref) {
|
|
|
154
159
|
onInputKeyDown: onInternalInputKeyDown
|
|
155
160
|
};
|
|
156
161
|
if (RootComponent) {
|
|
162
|
+
const originProps = RootComponent.props || {};
|
|
163
|
+
const mergedProps = {
|
|
164
|
+
...originProps,
|
|
165
|
+
...domProps
|
|
166
|
+
};
|
|
167
|
+
Object.keys(originProps).forEach(key => {
|
|
168
|
+
const originVal = originProps[key];
|
|
169
|
+
const domVal = domProps[key];
|
|
170
|
+
if (typeof originVal === 'function' && typeof domVal === 'function') {
|
|
171
|
+
mergedProps[key] = (...args) => {
|
|
172
|
+
domVal(...args);
|
|
173
|
+
originVal(...args);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
});
|
|
157
177
|
if ( /*#__PURE__*/React.isValidElement(RootComponent)) {
|
|
158
178
|
return /*#__PURE__*/React.cloneElement(RootComponent, {
|
|
159
|
-
...
|
|
179
|
+
...mergedProps,
|
|
160
180
|
ref: composeRef(RootComponent.ref, rootRef)
|
|
161
181
|
});
|
|
162
182
|
}
|
|
163
|
-
return /*#__PURE__*/React.createElement(RootComponent, _extends({},
|
|
183
|
+
return /*#__PURE__*/React.createElement(RootComponent, _extends({}, mergedProps, {
|
|
164
184
|
ref: rootRef
|
|
165
185
|
}));
|
|
166
186
|
}
|
|
@@ -25,7 +25,8 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
25
25
|
activeValue,
|
|
26
26
|
displayValues,
|
|
27
27
|
maxLength,
|
|
28
|
-
mode
|
|
28
|
+
mode,
|
|
29
|
+
components
|
|
29
30
|
} = (0, _context.useSelectInputContext)();
|
|
30
31
|
const {
|
|
31
32
|
triggerOpen,
|
|
@@ -77,7 +78,9 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
77
78
|
const showHasValueCls = displayValue && displayValue.label !== null && displayValue.label !== undefined && String(displayValue.label).trim() !== '';
|
|
78
79
|
|
|
79
80
|
// Render value
|
|
80
|
-
|
|
81
|
+
// Only render value when not using custom input in combobox mode
|
|
82
|
+
const shouldRenderValue = !(combobox && components?.input);
|
|
83
|
+
const renderValue = shouldRenderValue ? displayValue ? hasOptionStyle ? /*#__PURE__*/React.createElement("div", {
|
|
81
84
|
className: (0, _clsx.clsx)(`${prefixCls}-content-value`, optionClassName),
|
|
82
85
|
style: {
|
|
83
86
|
...(mergedSearchValue ? {
|
|
@@ -88,8 +91,7 @@ const SingleContent = /*#__PURE__*/React.forwardRef(({
|
|
|
88
91
|
title: optionTitle
|
|
89
92
|
}, displayValue.label) : displayValue.label : /*#__PURE__*/React.createElement(_Placeholder.default, {
|
|
90
93
|
show: !mergedSearchValue
|
|
91
|
-
});
|
|
92
|
-
|
|
94
|
+
}) : null;
|
|
93
95
|
// Render
|
|
94
96
|
return /*#__PURE__*/React.createElement("div", {
|
|
95
97
|
className: (0, _clsx.clsx)(`${prefixCls}-content`, showHasValueCls && `${prefixCls}-content-has-value`, mergedSearchValue && `${prefixCls}-content-has-search-value`, hasOptionStyle && `${prefixCls}-content-has-option-style`, classNames?.content),
|
package/lib/SelectInput/index.js
CHANGED
|
@@ -123,13 +123,18 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectIn
|
|
|
123
123
|
// When icon is dynamic render, the parentNode will miss
|
|
124
124
|
// so we need to mark the event directly
|
|
125
125
|
event.nativeEvent._ori_target = inputDOM;
|
|
126
|
-
|
|
126
|
+
const isClickOnInput = inputDOM === event.target || inputDOM?.contains(event.target);
|
|
127
|
+
if (inputDOM && !isClickOnInput) {
|
|
127
128
|
event.preventDefault();
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
// Check if we should prevent closing when clicking on selector
|
|
131
132
|
// Don't close if: open && not multiple && (combobox mode || showSearch)
|
|
132
|
-
const
|
|
133
|
+
const shouldPreventCloseOnSingle = triggerOpen && !multiple && (mode === 'combobox' || showSearch);
|
|
134
|
+
|
|
135
|
+
// Don't close if: open && multiple && click on input
|
|
136
|
+
const shouldPreventCloseOnMultipleInput = triggerOpen && multiple && isClickOnInput;
|
|
137
|
+
const shouldPreventClose = shouldPreventCloseOnSingle || shouldPreventCloseOnMultipleInput;
|
|
133
138
|
if (!event.nativeEvent._select_lazy) {
|
|
134
139
|
inputRef.current?.focus();
|
|
135
140
|
|
|
@@ -163,13 +168,28 @@ var _default = exports.default = /*#__PURE__*/React.forwardRef(function SelectIn
|
|
|
163
168
|
onInputKeyDown: onInternalInputKeyDown
|
|
164
169
|
};
|
|
165
170
|
if (RootComponent) {
|
|
171
|
+
const originProps = RootComponent.props || {};
|
|
172
|
+
const mergedProps = {
|
|
173
|
+
...originProps,
|
|
174
|
+
...domProps
|
|
175
|
+
};
|
|
176
|
+
Object.keys(originProps).forEach(key => {
|
|
177
|
+
const originVal = originProps[key];
|
|
178
|
+
const domVal = domProps[key];
|
|
179
|
+
if (typeof originVal === 'function' && typeof domVal === 'function') {
|
|
180
|
+
mergedProps[key] = (...args) => {
|
|
181
|
+
domVal(...args);
|
|
182
|
+
originVal(...args);
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
});
|
|
166
186
|
if ( /*#__PURE__*/React.isValidElement(RootComponent)) {
|
|
167
187
|
return /*#__PURE__*/React.cloneElement(RootComponent, {
|
|
168
|
-
...
|
|
188
|
+
...mergedProps,
|
|
169
189
|
ref: (0, _ref.composeRef)(RootComponent.ref, rootRef)
|
|
170
190
|
});
|
|
171
191
|
}
|
|
172
|
-
return /*#__PURE__*/React.createElement(RootComponent, _extends({},
|
|
192
|
+
return /*#__PURE__*/React.createElement(RootComponent, _extends({}, mergedProps, {
|
|
173
193
|
ref: rootRef
|
|
174
194
|
}));
|
|
175
195
|
}
|