@kne/super-select 0.1.42 → 0.1.44

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.
@@ -1,4 +1,4 @@
1
- import React, { useState, useRef, useLayoutEffect, forwardRef, useMemo, useCallback, useImperativeHandle, useEffect } from 'react';
1
+ import React, { useState, useRef, useLayoutEffect, forwardRef, useMemo, useCallback, useEffect, useImperativeHandle } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { createContext } from '@kne/global-context';
4
4
  import useResize from '@kne/use-resize';
@@ -239,6 +239,9 @@ const pxToNumber = value => {
239
239
  return match ? Number(match[0]) : 0;
240
240
  };
241
241
 
242
+ /** 未传 overlayWidth 时的面板最小宽度(与 .overlay-content min-width 一致) */
243
+ const DEFAULT_OVERLAY_MIN_WIDTH = 300;
244
+
242
245
  // 与 Modal 模式一致:面板内用临时 value,确认后才写回
243
246
  const ModalContent = _ref => {
244
247
  let {
@@ -465,12 +468,14 @@ const SelectInput = createWithIntlProvider({
465
468
  onComplete();
466
469
  onOpenChange(false);
467
470
  }
468
- }, children(contextProps)));
471
+ }, open ? children(contextProps) : null));
469
472
  }
470
473
  return /*#__PURE__*/React.createElement(Modal, {
471
474
  className: overlayClassName,
472
475
  width: 1000,
473
476
  open: open,
477
+ destroyOnClose: true,
478
+ destroyOnHidden: true,
474
479
  title: placeholder,
475
480
  onCancel: () => {
476
481
  onOpenChange(false);
@@ -479,7 +484,7 @@ const SelectInput = createWithIntlProvider({
479
484
  onComplete();
480
485
  onOpenChange(false);
481
486
  }
482
- }, children(contextProps));
487
+ }, open ? children(contextProps) : null);
483
488
  }
484
489
  }, p);
485
490
  props.selectedAllValue = {
@@ -536,11 +541,6 @@ const SelectInput = createWithIntlProvider({
536
541
  });
537
542
  const useMobileSheet = isMobile && !disableMobileSheet;
538
543
  const useBoundaryMount = !!(isMobile && fixedModeClass === MOBILE_POPUP_MODE.boundary);
539
- const mergedOverlayStyle = useMemo(() => {
540
- return Object.assign({}, overlayStyle, zIndex != null ? {
541
- zIndex
542
- } : null);
543
- }, [overlayStyle, zIndex]);
544
544
  const transformValue = value => {
545
545
  if (single) {
546
546
  return isNotEmpty(value) ? [value] : [];
@@ -577,8 +577,19 @@ const SelectInput = createWithIntlProvider({
577
577
  setInnerWidth(innerEl.clientWidth);
578
578
  };
579
579
  const popupOverlayWidth = useMemo(() => {
580
- return numberToPx$1(Math.max(containerWidth, pxToNumber(overlayWidth)));
580
+ const configured = overlayWidth != null && overlayWidth !== '' ? pxToNumber(overlayWidth) : DEFAULT_OVERLAY_MIN_WIDTH;
581
+ return numberToPx$1(Math.max(containerWidth || 0, configured));
581
582
  }, [containerWidth, overlayWidth]);
583
+
584
+ // 同步给 Dropdown 外层 minWidth,避免 antd 按窄触发器裁剪面板
585
+ const mergedOverlayStyle = useMemo(() => {
586
+ return Object.assign({}, overlayStyle, zIndex != null ? {
587
+ zIndex
588
+ } : null, {
589
+ minWidth: popupOverlayWidth,
590
+ ['--overlay-width']: popupOverlayWidth
591
+ });
592
+ }, [overlayStyle, zIndex, popupOverlayWidth]);
582
593
  const resizeRef = useResize(containerWidthChange);
583
594
  const setContainerRef = useCallback(node => {
584
595
  resizeRef.current = node;
@@ -676,6 +687,13 @@ const SelectInput = createWithIntlProvider({
676
687
  const handleOpenChange = useCallback(nextOpen => {
677
688
  setOpen(nextOpen);
678
689
  }, [setOpen]);
690
+
691
+ // 关闭时清空搜索,保证下次展开重新请求且从初始搜索态开始
692
+ useEffect(() => {
693
+ if (!open) {
694
+ setSearchProps({});
695
+ }
696
+ }, [open]);
679
697
  const contextProps = {
680
698
  props,
681
699
  value: value,
@@ -757,9 +775,14 @@ const SelectInput = createWithIntlProvider({
757
775
  useImperativeHandle(ref, () => {
758
776
  return contextProps;
759
777
  });
778
+
779
+ // 嵌入模式内容常显,视为已展开,保证会发起请求
760
780
  if (props.renderContent && typeof props.renderContent === 'function') {
761
- return props.renderContent(children(contextProps));
781
+ return props.renderContent(children(Object.assign({}, contextProps, {
782
+ open: true
783
+ })));
762
784
  }
785
+ const isOverlayOpen = !disabled && open;
763
786
 
764
787
  // 移动端半屏:与 Modal 一致,临时选中 + 取消/确认
765
788
  if (useMobileSheet) {
@@ -798,7 +821,7 @@ const SelectInput = createWithIntlProvider({
798
821
  onComplete();
799
822
  setOpen(false);
800
823
  }
801
- }, children(sheetContextProps)));
824
+ }, sheetOpen ? children(sheetContextProps) : null));
802
825
  }));
803
826
  }
804
827
  const overlayContent = /*#__PURE__*/React.createElement("div", {
@@ -809,11 +832,11 @@ const SelectInput = createWithIntlProvider({
809
832
  onClick: e => {
810
833
  e.stopPropagation();
811
834
  }
812
- }, children(contextProps));
835
+ }, isOverlayOpen ? children(contextProps) : null);
813
836
  return /*#__PURE__*/React.createElement(Provider, {
814
837
  value: contextProps
815
838
  }, isPopup ? /*#__PURE__*/React.createElement(Dropdown, {
816
- open: !disabled && open,
839
+ open: isOverlayOpen,
817
840
  onOpenChange: handleOpenChange,
818
841
  placement: placement,
819
842
  arrow: false,
@@ -824,6 +847,8 @@ const SelectInput = createWithIntlProvider({
824
847
  autoAdjustOverflow: autoAdjustOverflow,
825
848
  transitionName: transitionName,
826
849
  trigger: "click",
850
+ destroyPopupOnHide: true,
851
+ destroyOnHidden: true,
827
852
  popupRender: () => overlayContent,
828
853
  dropdownRender: () => overlayContent
829
854
  }, /*#__PURE__*/React.createElement("span", null, inputInnerRender())) : /*#__PURE__*/React.createElement(React.Fragment, null, inputInnerRender({
@@ -1036,7 +1061,8 @@ const SelectList = forwardRef((_ref, ref) => {
1036
1061
  searchProps,
1037
1062
  setSearchProps,
1038
1063
  onOpenChange,
1039
- isMobile
1064
+ isMobile,
1065
+ open
1040
1066
  } = targetProps;
1041
1067
  const {
1042
1068
  footer,
@@ -1073,7 +1099,7 @@ const SelectList = forwardRef((_ref, ref) => {
1073
1099
  'is-popup': isPopup
1074
1100
  })
1075
1101
  }, /*#__PURE__*/React.createElement(SelectedAll, null)),
1076
- fetchList: /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1102
+ fetchList: open ? /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1077
1103
  className: classnames(style$3['list'], 'select-list-scroll-list', {
1078
1104
  'is-popup': isPopup
1079
1105
  }),
@@ -1109,7 +1135,7 @@ const SelectList = forwardRef((_ref, ref) => {
1109
1135
  return renderList(Object.assign({}, fetchProps, targetProps, {
1110
1136
  isSelectedAll
1111
1137
  }));
1112
- }),
1138
+ }) : null,
1113
1139
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
1114
1140
  className: classnames(style$3['selected-tag'], 'select-list-selected-tag', {
1115
1141
  'is-popup': isPopup
@@ -1278,7 +1304,8 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1278
1304
  onRemove,
1279
1305
  onOpenChange,
1280
1306
  searchProps,
1281
- isMobile
1307
+ isMobile,
1308
+ open
1282
1309
  } = targetProps;
1283
1310
  const {
1284
1311
  footer,
@@ -1323,7 +1350,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1323
1350
  onOpenChange(false);
1324
1351
  }
1325
1352
  }) : footer);
1326
- const renderScrollList = renderContent => /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1353
+ const renderScrollList = renderContent => open ? /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1327
1354
  className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1328
1355
  'is-popup': isPopup
1329
1356
  }),
@@ -1366,7 +1393,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1366
1393
  });
1367
1394
  }
1368
1395
  return renderContent(list, contextProps);
1369
- });
1396
+ }) : null;
1370
1397
  const tableSelection = {
1371
1398
  allowSelectedAll,
1372
1399
  isSelectedAll,
@@ -1692,7 +1719,8 @@ const SelectTree = forwardRef((_ref, ref) => {
1692
1719
  props,
1693
1720
  value,
1694
1721
  onOpenChange,
1695
- isMobile
1722
+ isMobile,
1723
+ open
1696
1724
  } = targetProps;
1697
1725
  const {
1698
1726
  footer,
@@ -1712,7 +1740,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1712
1740
  'is-popup': isPopup
1713
1741
  })
1714
1742
  }, /*#__PURE__*/React.createElement(SelectedAll, null)),
1715
- treeList: /*#__PURE__*/React.createElement(Fetch, _extends({}, Object.assign({}, options ? {
1743
+ treeList: open ? /*#__PURE__*/React.createElement(Fetch, _extends({}, Object.assign({}, options ? {
1716
1744
  data: {
1717
1745
  options
1718
1746
  },
@@ -1745,7 +1773,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1745
1773
  autoHide: false
1746
1774
  }, treeContent);
1747
1775
  }
1748
- })),
1776
+ })) : null,
1749
1777
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
1750
1778
  className: classnames(style$1['selected-tag'], 'select-tree-selected-tag', {
1751
1779
  'is-popup': isPopup
@@ -2126,7 +2154,7 @@ const CascaderInner = ({
2126
2154
  treeUtils
2127
2155
  };
2128
2156
  useEffect(() => {
2129
- if (!openLoadData || !onLoadMore) {
2157
+ if (!open || !openLoadData || !onLoadMore) {
2130
2158
  return;
2131
2159
  }
2132
2160
  const lastNode = mapping.get(last(selectedIds));
@@ -2146,7 +2174,7 @@ const CascaderInner = ({
2146
2174
  }).catch(() => {
2147
2175
  setLoading(false);
2148
2176
  });
2149
- }, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
2177
+ }, [open, selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
2150
2178
 
2151
2179
  // 检查是否为非叶子节点
2152
2180
  const isNotLastNode = useCallback(id => {
@@ -2576,7 +2604,7 @@ const SelectCascader = _ref => {
2576
2604
  [labelKey]: String(item)
2577
2605
  };
2578
2606
  }).filter(Boolean);
2579
- return /*#__PURE__*/React.createElement(CascaderInner, {
2607
+ return contextProps.open ? /*#__PURE__*/React.createElement(CascaderInner, {
2580
2608
  options: options,
2581
2609
  value: currentDisplayValue,
2582
2610
  setValue: contextSetValue,
@@ -2595,7 +2623,7 @@ const SelectCascader = _ref => {
2595
2623
  onOpenChange: contextProps.onOpenChange,
2596
2624
  open: contextProps.open,
2597
2625
  isMobile: contextProps.isMobile
2598
- });
2626
+ }) : null;
2599
2627
  });
2600
2628
  };
2601
2629