x-ui-design 0.2.97 → 0.2.99
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/dist/index.esm.js +53 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +53 -11
- package/dist/index.js.map +1 -1
- package/lib/components/Select/Select.tsx +62 -12
- package/package.json +1 -1
- package/src/app/page.tsx +22 -2
package/dist/index.esm.js
CHANGED
|
@@ -3025,27 +3025,64 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3025
3025
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
3026
3026
|
};
|
|
3027
3027
|
}, [handleClearInputValue, open, hasMode]);
|
|
3028
|
-
|
|
3029
|
-
if (!selectRef.current
|
|
3030
|
-
return;
|
|
3031
|
-
}
|
|
3028
|
+
const updateDropdownPosition = useCallback(() => {
|
|
3029
|
+
if (!selectRef.current) return;
|
|
3032
3030
|
const selectBox = selectRef.current.getBoundingClientRect();
|
|
3033
3031
|
const dropdownHeight = listHeight;
|
|
3034
3032
|
const windowHeight = window.innerHeight;
|
|
3035
3033
|
const spaceBelow = windowHeight - selectBox.bottom;
|
|
3036
3034
|
const spaceAbove = selectBox.top;
|
|
3037
3035
|
let positionStyle = {
|
|
3038
|
-
top: `${selectBox.bottom}px
|
|
3039
|
-
|
|
3036
|
+
top: `${selectBox.bottom + window.scrollY}px`,
|
|
3037
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3038
|
+
width: `${selectBox.width}px`,
|
|
3039
|
+
position: 'absolute'
|
|
3040
3040
|
};
|
|
3041
3041
|
if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
|
|
3042
3042
|
positionStyle = {
|
|
3043
|
-
top: `${selectBox.top - dropdownHeight}px
|
|
3044
|
-
|
|
3043
|
+
top: `${selectBox.top + window.scrollY - dropdownHeight}px`,
|
|
3044
|
+
left: `${selectBox.left + window.scrollX}px`,
|
|
3045
|
+
width: `${selectBox.width}px`,
|
|
3046
|
+
position: 'absolute'
|
|
3045
3047
|
};
|
|
3046
3048
|
}
|
|
3047
3049
|
setDropdownPosition(positionStyle);
|
|
3048
|
-
}, [listHeight
|
|
3050
|
+
}, [listHeight]);
|
|
3051
|
+
useEffect(() => {
|
|
3052
|
+
if (!isOpen) return;
|
|
3053
|
+
updateDropdownPosition();
|
|
3054
|
+
// const container = getPopupContainer?.(selectRef.current!);
|
|
3055
|
+
const scrollableParents = getScrollParents(selectRef.current);
|
|
3056
|
+
const handleScroll = () => {
|
|
3057
|
+
updateDropdownPosition();
|
|
3058
|
+
};
|
|
3059
|
+
// Add scroll listeners to all scrollable parents
|
|
3060
|
+
scrollableParents.forEach(el => {
|
|
3061
|
+
el.addEventListener('scroll', handleScroll, {
|
|
3062
|
+
passive: true
|
|
3063
|
+
});
|
|
3064
|
+
});
|
|
3065
|
+
// Add resize listener
|
|
3066
|
+
window.addEventListener('resize', updateDropdownPosition);
|
|
3067
|
+
return () => {
|
|
3068
|
+
scrollableParents.forEach(el => {
|
|
3069
|
+
el.removeEventListener('scroll', handleScroll);
|
|
3070
|
+
});
|
|
3071
|
+
window.removeEventListener('resize', updateDropdownPosition);
|
|
3072
|
+
};
|
|
3073
|
+
}, [isOpen, getPopupContainer, updateDropdownPosition]);
|
|
3074
|
+
// Helper function to get all scrollable parents
|
|
3075
|
+
const getScrollParents = element => {
|
|
3076
|
+
const parents = [];
|
|
3077
|
+
let current = element.parentElement;
|
|
3078
|
+
while (current) {
|
|
3079
|
+
if (current.scrollHeight > current.clientHeight) {
|
|
3080
|
+
parents.push(current);
|
|
3081
|
+
}
|
|
3082
|
+
current = current.parentElement;
|
|
3083
|
+
}
|
|
3084
|
+
return parents;
|
|
3085
|
+
};
|
|
3049
3086
|
const handleSearch = e => {
|
|
3050
3087
|
setSearchQuery(e.target.value);
|
|
3051
3088
|
onSearch?.(e.target.value);
|
|
@@ -3064,7 +3101,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3064
3101
|
}
|
|
3065
3102
|
const updatedSelected = [...selected, newOptionValue];
|
|
3066
3103
|
onChange?.(updatedSelected);
|
|
3067
|
-
onSelect?.(
|
|
3104
|
+
onSelect?.(updatedSelected);
|
|
3068
3105
|
const input = selectRef.current?.querySelector('input');
|
|
3069
3106
|
if (input) {
|
|
3070
3107
|
input.value = '';
|
|
@@ -3080,6 +3117,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3080
3117
|
const newSelection = selected.includes(optionValue) ? selected.filter(item => item !== optionValue) : [...selected, optionValue];
|
|
3081
3118
|
setSelected(newSelection);
|
|
3082
3119
|
onChange?.(newSelection, option);
|
|
3120
|
+
onSelect?.(newSelection, option);
|
|
3083
3121
|
if (selected.includes(optionValue)) {
|
|
3084
3122
|
onDeselect?.(optionValue, option);
|
|
3085
3123
|
} else {
|
|
@@ -3097,12 +3135,14 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3097
3135
|
const value = hasMode ? [] : '';
|
|
3098
3136
|
setSelected(value);
|
|
3099
3137
|
onChange?.('');
|
|
3138
|
+
onSelect?.('');
|
|
3100
3139
|
onClear?.();
|
|
3101
3140
|
handleClearInputValue();
|
|
3102
3141
|
};
|
|
3103
3142
|
const handleRemoveTag = e => {
|
|
3104
3143
|
const updatedSelected = hasMode ? selected.filter(item => item !== e.target.value) : e.target.value;
|
|
3105
3144
|
onChange?.(updatedSelected);
|
|
3145
|
+
onSelect?.(updatedSelected);
|
|
3106
3146
|
setSelected(updatedSelected);
|
|
3107
3147
|
};
|
|
3108
3148
|
const handleOnKeyDown = e => {
|
|
@@ -3123,6 +3163,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3123
3163
|
if (e.key === 'Backspace' && (hasMode ? !searchQuery.trim().length : searchQuery.trim().length)) {
|
|
3124
3164
|
const updatedSelected = hasMode ? selected.filter(item => item !== selected[selected.length - 1]) : searchQuery.trim();
|
|
3125
3165
|
onChange?.(updatedSelected);
|
|
3166
|
+
onSelect?.(updatedSelected);
|
|
3126
3167
|
setSelected(updatedSelected);
|
|
3127
3168
|
}
|
|
3128
3169
|
clearTimeout(timeout);
|
|
@@ -3137,7 +3178,8 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
|
|
|
3137
3178
|
}));
|
|
3138
3179
|
}, [showArrow, showSearch, isOpen, suffixIcon]);
|
|
3139
3180
|
const popupContainer = useMemo(() => {
|
|
3140
|
-
|
|
3181
|
+
if (typeof window === 'undefined') return null;
|
|
3182
|
+
return selectRef.current ? getPopupContainer?.(selectRef.current) : document.body;
|
|
3141
3183
|
}, [getPopupContainer]);
|
|
3142
3184
|
const extractedOptions = children ? (Array.isArray(children) ? children : [children]).filter(e => e).map(child => child.props) : options;
|
|
3143
3185
|
const filteredOptions = extractedOptions.filter(option => {
|