x-ui-design 0.3.1 → 0.3.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.
@@ -40,7 +40,7 @@ declare const Select: React.ForwardRefExoticComponent<import("../../types").Defa
40
40
  suffixIcon?: ReactNode;
41
41
  open?: boolean;
42
42
  notFoundContent?: ReactNode;
43
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
43
+ getPopupContainer?: (triggerNode: HTMLElement | null) => HTMLElement;
44
44
  dropdownRender?: (menu: ReactNode) => ReactNode;
45
45
  feedbackIcons?: boolean;
46
46
  placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
@@ -138,7 +138,7 @@ declare const Select: import("react").ComponentType<import("@/types").DefaultPro
138
138
  suffixIcon?: import("react").ReactNode;
139
139
  open?: boolean;
140
140
  notFoundContent?: import("react").ReactNode;
141
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
141
+ getPopupContainer?: (triggerNode: HTMLElement | null) => HTMLElement;
142
142
  dropdownRender?: (menu: import("react").ReactNode) => import("react").ReactNode;
143
143
  feedbackIcons?: boolean;
144
144
  placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
@@ -39,7 +39,7 @@ export type SelectProps = DefaultProps & {
39
39
  suffixIcon?: ReactNode;
40
40
  open?: boolean;
41
41
  notFoundContent?: ReactNode;
42
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
42
+ getPopupContainer?: (triggerNode: HTMLElement | null) => HTMLElement;
43
43
  dropdownRender?: (menu: ReactNode) => ReactNode;
44
44
  feedbackIcons?: boolean;
45
45
  placement?: 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
package/dist/index.d.ts CHANGED
@@ -222,7 +222,7 @@ declare const Select: react.ComponentType<__types.DefaultProps & {
222
222
  suffixIcon?: react.ReactNode;
223
223
  open?: boolean;
224
224
  notFoundContent?: react.ReactNode;
225
- getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
225
+ getPopupContainer?: (triggerNode: HTMLElement | null) => HTMLElement;
226
226
  dropdownRender?: (menu: react.ReactNode) => react.ReactNode;
227
227
  feedbackIcons?: boolean;
228
228
  placement?: "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
package/dist/index.esm.js CHANGED
@@ -2880,7 +2880,7 @@ var Option$1 = /*#__PURE__*/Object.freeze({
2880
2880
  default: Option
2881
2881
  });
2882
2882
 
2883
- var css_248z$6 = ".xUi-select .xUi-select-tag-container{display:flex;flex:auto;flex-wrap:wrap;gap:4px;line-height:12px;position:relative}.xUi-select.large .xUi-select-tag-container,.xUi-select.middle .xUi-select-tag-container{line-height:22px}.xUi-select .xUi-select-tag{align-items:center;align-self:center;background:rgba(0,0,0,.06);border:1px solid transparent;border-radius:var(--xui-border-radius-sm);box-sizing:border-box;cursor:default;display:flex;flex:none;height:100%;max-width:100%;overflow:hidden;padding:2px;text-overflow:ellipsis;transition:font-size .3s,line-height .3s,height .3s;white-space:nowrap}.xUi-select.middle .xUi-select-tag{padding:4px 8px}.xUi-select.large .xUi-select-tag{font-size:var(--xui-font-size-lg);padding:8px}.xUi-select .xUi-select-tag span{font-size:var(--xui-font-size-sm);margin:0 2px}.xUi-select .xUi-select-tag .xUi-select-tag-close-icon{color:rgba(0,0,0,.5);cursor:pointer;font-size:var(--xui-font-size-xs)}.xUi-select .xUi-select-tag .xUi-select-tag-close-icon:hover{color:var(--xui-text-color)}.xUi-select .xUi-select-tag:has([class=xUi-select-tag-input]){background:transparent;border:none;color:var(--xui-text-color);font-size:var(--xui-font-size-md);outline:none;padding:0}.xUi-select .xUi-select-tag:has([class=xUi-select-tag-input]) input{background-color:transparent;border:none;font-size:var(--xui-font-size-md);height:-webkit-fill-available;padding:0}.xUi-select .xUi-select-tag-input:focus{border:none;box-shadow:none;outline:none}";
2883
+ var css_248z$6 = ".xUi-select .xUi-select-tag-container{display:flex;flex:auto;flex-wrap:wrap;gap:4px;line-height:12px;position:relative}.xUi-select.large .xUi-select-tag-container,.xUi-select.middle .xUi-select-tag-container{line-height:22px}.xUi-select .xUi-select-tag{align-items:center;align-self:center;background:rgba(0,0,0,.06);border:1px solid transparent;border-radius:var(--xui-border-radius-sm);box-sizing:border-box;cursor:default;display:flex;flex:none;height:100%;max-width:100%;overflow:hidden;padding:2px;text-overflow:ellipsis;transition:font-size .3s,line-height .3s,height .3s;white-space:nowrap}.xUi-select.middle .xUi-select-tag{padding:4px 8px}.xUi-select.large .xUi-select-tag{font-size:var(--xui-font-size-lg);padding:4px 8px}.xUi-select .xUi-select-tag span{font-size:var(--xui-font-size-sm);margin:0 2px}.xUi-select .xUi-select-tag .xUi-select-tag-close-icon{color:rgba(0,0,0,.5);cursor:pointer;font-size:var(--xui-font-size-xs)}.xUi-select .xUi-select-tag .xUi-select-tag-close-icon:hover{color:var(--xui-text-color)}.xUi-select .xUi-select-tag:has([class=xUi-select-tag-input]){background:transparent;border:none;color:var(--xui-text-color);font-size:var(--xui-font-size-md);outline:none;padding:0}.xUi-select .xUi-select-tag:has([class=xUi-select-tag-input]) input{background-color:transparent;border:none;font-size:var(--xui-font-size-md);height:-webkit-fill-available;padding:0}.xUi-select .xUi-select-tag-input:focus{border:none;box-shadow:none;outline:none}";
2884
2884
  styleInject(css_248z$6);
2885
2885
 
2886
2886
  const Tag = ({
@@ -2922,7 +2922,6 @@ styleInject(css_248z$5);
2922
2922
  const LIST_HEIGHT = 200;
2923
2923
  const PADDING_PLACEMENT = 18;
2924
2924
  const PADDING_TAG_INPUT = 4;
2925
- const DROPDOWN_CONTENT_PADDING = 8;
2926
2925
  function getTextFromNode(node) {
2927
2926
  if (typeof node === 'string' || typeof node === 'number') {
2928
2927
  return node.toString();
@@ -3016,8 +3015,11 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3016
3015
  }, [autoClearSearchValue, prefixCls]);
3017
3016
  useEffect(() => {
3018
3017
  const handleClickOutside = event => {
3019
- if (selectRef.current && !selectRef.current.contains(event.target)) {
3020
- setIsOpen(open);
3018
+ if (!selectRef.current) return;
3019
+ const dropdown = document.querySelector(`.${prefixCls}-dropdown`);
3020
+ const clickedInside = selectRef.current.contains(event.target) || dropdown && dropdown.contains(event.target);
3021
+ if (!clickedInside) {
3022
+ setIsOpen(false);
3021
3023
  handleClearInputValue();
3022
3024
  }
3023
3025
  };
@@ -3025,7 +3027,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3025
3027
  return () => {
3026
3028
  document.removeEventListener('mousedown', handleClickOutside);
3027
3029
  };
3028
- }, [handleClearInputValue, open, hasMode]);
3030
+ }, [handleClearInputValue, open, hasMode, prefixCls]);
3029
3031
  const updateDropdownPosition = useCallback(() => {
3030
3032
  if (!selectRef.current) return;
3031
3033
  const selectBox = selectRef.current.getBoundingClientRect();
@@ -3034,36 +3036,37 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3034
3036
  const spaceBelow = windowHeight - selectBox.bottom;
3035
3037
  const spaceAbove = selectBox.top;
3036
3038
  let positionStyle = {
3037
- top: `${selectBox.bottom + window.scrollY - DROPDOWN_CONTENT_PADDING}px`,
3038
- left: `${selectBox.left + window.scrollX - DROPDOWN_CONTENT_PADDING}px`,
3039
+ ...(getPopupContainer ? {
3040
+ top: `${selectBox.bottom}px`,
3041
+ left: `${selectBox.left}px`
3042
+ } : {}),
3039
3043
  width: `${selectBox.width}px`,
3040
3044
  position: 'absolute'
3041
3045
  };
3042
3046
  if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) {
3043
3047
  positionStyle = {
3044
- top: `${selectBox.top + window.scrollY - dropdownHeight - DROPDOWN_CONTENT_PADDING}px`,
3045
- left: `${selectBox.left + window.scrollX - DROPDOWN_CONTENT_PADDING}px`,
3048
+ ...(getPopupContainer ? {
3049
+ top: `${selectBox.top - dropdownHeight}px`,
3050
+ left: `${selectBox.left}px`
3051
+ } : {}),
3046
3052
  width: `${selectBox.width}px`,
3047
3053
  position: 'absolute'
3048
3054
  };
3049
3055
  }
3050
3056
  setDropdownPosition(positionStyle);
3051
- }, [listHeight]);
3057
+ }, [listHeight, getPopupContainer]);
3052
3058
  useEffect(() => {
3053
3059
  if (!isOpen) return;
3054
3060
  updateDropdownPosition();
3055
- // const container = getPopupContainer?.(selectRef.current!);
3056
3061
  const scrollableParents = getScrollParents(selectRef.current);
3057
3062
  const handleScroll = () => {
3058
3063
  updateDropdownPosition();
3059
3064
  };
3060
- // Add scroll listeners to all scrollable parents
3061
3065
  scrollableParents.forEach(el => {
3062
3066
  el.addEventListener('scroll', handleScroll, {
3063
3067
  passive: true
3064
3068
  });
3065
3069
  });
3066
- // Add resize listener
3067
3070
  window.addEventListener('resize', updateDropdownPosition);
3068
3071
  return () => {
3069
3072
  scrollableParents.forEach(el => {
@@ -3072,7 +3075,6 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3072
3075
  window.removeEventListener('resize', updateDropdownPosition);
3073
3076
  };
3074
3077
  }, [isOpen, getPopupContainer, updateDropdownPosition]);
3075
- // Helper function to get all scrollable parents
3076
3078
  const getScrollParents = element => {
3077
3079
  const parents = [];
3078
3080
  let current = element.parentElement;
@@ -3178,10 +3180,12 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3178
3180
  isOpen: isOpen
3179
3181
  }));
3180
3182
  }, [showArrow, showSearch, isOpen, suffixIcon]);
3181
- const popupContainer = (() => {
3182
- if (typeof window === 'undefined') return null;
3183
- return selectRef.current ? getPopupContainer?.(selectRef.current) : document.body;
3184
- })();
3183
+ const popupContainer = useMemo(() => {
3184
+ if (typeof window === 'undefined') {
3185
+ return selectRef.current;
3186
+ }
3187
+ return getPopupContainer?.(selectRef.current) || selectRef.current;
3188
+ }, [getPopupContainer]);
3185
3189
  const extractedOptions = children ? (Array.isArray(children) ? children : [children]).filter(e => e).map(child => child.props) : options;
3186
3190
  const filteredOptions = extractedOptions.filter(option => {
3187
3191
  if (typeof filterOption === 'function') {
@@ -3267,7 +3271,7 @@ const SelectComponent = /*#__PURE__*/forwardRef(({
3267
3271
  style: {
3268
3272
  maxHeight: listHeight,
3269
3273
  overflowY: 'auto',
3270
- maxWidth: selectRef.current ? `${selectRef.current.getBoundingClientRect().width - DROPDOWN_CONTENT_PADDING}px` : 'inherit'
3274
+ maxWidth: selectRef.current ? `${selectRef.current.getBoundingClientRect().width}px` : 'inherit'
3271
3275
  }
3272
3276
  }, asTag && !!searchQuery && /*#__PURE__*/React$1.createElement(Option, {
3273
3277
  value: searchQuery,