@kne/super-select 0.1.42 → 0.1.43

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';
@@ -465,12 +465,14 @@ const SelectInput = createWithIntlProvider({
465
465
  onComplete();
466
466
  onOpenChange(false);
467
467
  }
468
- }, children(contextProps)));
468
+ }, open ? children(contextProps) : null));
469
469
  }
470
470
  return /*#__PURE__*/React.createElement(Modal, {
471
471
  className: overlayClassName,
472
472
  width: 1000,
473
473
  open: open,
474
+ destroyOnClose: true,
475
+ destroyOnHidden: true,
474
476
  title: placeholder,
475
477
  onCancel: () => {
476
478
  onOpenChange(false);
@@ -479,7 +481,7 @@ const SelectInput = createWithIntlProvider({
479
481
  onComplete();
480
482
  onOpenChange(false);
481
483
  }
482
- }, children(contextProps));
484
+ }, open ? children(contextProps) : null);
483
485
  }
484
486
  }, p);
485
487
  props.selectedAllValue = {
@@ -676,6 +678,13 @@ const SelectInput = createWithIntlProvider({
676
678
  const handleOpenChange = useCallback(nextOpen => {
677
679
  setOpen(nextOpen);
678
680
  }, [setOpen]);
681
+
682
+ // 关闭时清空搜索,保证下次展开重新请求且从初始搜索态开始
683
+ useEffect(() => {
684
+ if (!open) {
685
+ setSearchProps({});
686
+ }
687
+ }, [open]);
679
688
  const contextProps = {
680
689
  props,
681
690
  value: value,
@@ -757,9 +766,14 @@ const SelectInput = createWithIntlProvider({
757
766
  useImperativeHandle(ref, () => {
758
767
  return contextProps;
759
768
  });
769
+
770
+ // 嵌入模式内容常显,视为已展开,保证会发起请求
760
771
  if (props.renderContent && typeof props.renderContent === 'function') {
761
- return props.renderContent(children(contextProps));
772
+ return props.renderContent(children(Object.assign({}, contextProps, {
773
+ open: true
774
+ })));
762
775
  }
776
+ const isOverlayOpen = !disabled && open;
763
777
 
764
778
  // 移动端半屏:与 Modal 一致,临时选中 + 取消/确认
765
779
  if (useMobileSheet) {
@@ -798,7 +812,7 @@ const SelectInput = createWithIntlProvider({
798
812
  onComplete();
799
813
  setOpen(false);
800
814
  }
801
- }, children(sheetContextProps)));
815
+ }, sheetOpen ? children(sheetContextProps) : null));
802
816
  }));
803
817
  }
804
818
  const overlayContent = /*#__PURE__*/React.createElement("div", {
@@ -809,11 +823,11 @@ const SelectInput = createWithIntlProvider({
809
823
  onClick: e => {
810
824
  e.stopPropagation();
811
825
  }
812
- }, children(contextProps));
826
+ }, isOverlayOpen ? children(contextProps) : null);
813
827
  return /*#__PURE__*/React.createElement(Provider, {
814
828
  value: contextProps
815
829
  }, isPopup ? /*#__PURE__*/React.createElement(Dropdown, {
816
- open: !disabled && open,
830
+ open: isOverlayOpen,
817
831
  onOpenChange: handleOpenChange,
818
832
  placement: placement,
819
833
  arrow: false,
@@ -824,6 +838,8 @@ const SelectInput = createWithIntlProvider({
824
838
  autoAdjustOverflow: autoAdjustOverflow,
825
839
  transitionName: transitionName,
826
840
  trigger: "click",
841
+ destroyPopupOnHide: true,
842
+ destroyOnHidden: true,
827
843
  popupRender: () => overlayContent,
828
844
  dropdownRender: () => overlayContent
829
845
  }, /*#__PURE__*/React.createElement("span", null, inputInnerRender())) : /*#__PURE__*/React.createElement(React.Fragment, null, inputInnerRender({
@@ -1036,7 +1052,8 @@ const SelectList = forwardRef((_ref, ref) => {
1036
1052
  searchProps,
1037
1053
  setSearchProps,
1038
1054
  onOpenChange,
1039
- isMobile
1055
+ isMobile,
1056
+ open
1040
1057
  } = targetProps;
1041
1058
  const {
1042
1059
  footer,
@@ -1073,7 +1090,7 @@ const SelectList = forwardRef((_ref, ref) => {
1073
1090
  'is-popup': isPopup
1074
1091
  })
1075
1092
  }, /*#__PURE__*/React.createElement(SelectedAll, null)),
1076
- fetchList: /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1093
+ fetchList: open ? /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1077
1094
  className: classnames(style$3['list'], 'select-list-scroll-list', {
1078
1095
  'is-popup': isPopup
1079
1096
  }),
@@ -1109,7 +1126,7 @@ const SelectList = forwardRef((_ref, ref) => {
1109
1126
  return renderList(Object.assign({}, fetchProps, targetProps, {
1110
1127
  isSelectedAll
1111
1128
  }));
1112
- }),
1129
+ }) : null,
1113
1130
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
1114
1131
  className: classnames(style$3['selected-tag'], 'select-list-selected-tag', {
1115
1132
  'is-popup': isPopup
@@ -1278,7 +1295,8 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1278
1295
  onRemove,
1279
1296
  onOpenChange,
1280
1297
  searchProps,
1281
- isMobile
1298
+ isMobile,
1299
+ open
1282
1300
  } = targetProps;
1283
1301
  const {
1284
1302
  footer,
@@ -1323,7 +1341,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1323
1341
  onOpenChange(false);
1324
1342
  }
1325
1343
  }) : footer);
1326
- const renderScrollList = renderContent => /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1344
+ const renderScrollList = renderContent => open ? /*#__PURE__*/React.createElement(FetchScrollLoader, _extends({}, props, {
1327
1345
  className: classnames(style$2['list'], 'select-table-list-scroll-list', {
1328
1346
  'is-popup': isPopup
1329
1347
  }),
@@ -1366,7 +1384,7 @@ const SelectTableList = createWithIntlProvider('zh-CN', locale$1, 'super-select'
1366
1384
  });
1367
1385
  }
1368
1386
  return renderContent(list, contextProps);
1369
- });
1387
+ }) : null;
1370
1388
  const tableSelection = {
1371
1389
  allowSelectedAll,
1372
1390
  isSelectedAll,
@@ -1692,7 +1710,8 @@ const SelectTree = forwardRef((_ref, ref) => {
1692
1710
  props,
1693
1711
  value,
1694
1712
  onOpenChange,
1695
- isMobile
1713
+ isMobile,
1714
+ open
1696
1715
  } = targetProps;
1697
1716
  const {
1698
1717
  footer,
@@ -1712,7 +1731,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1712
1731
  'is-popup': isPopup
1713
1732
  })
1714
1733
  }, /*#__PURE__*/React.createElement(SelectedAll, null)),
1715
- treeList: /*#__PURE__*/React.createElement(Fetch, _extends({}, Object.assign({}, options ? {
1734
+ treeList: open ? /*#__PURE__*/React.createElement(Fetch, _extends({}, Object.assign({}, options ? {
1716
1735
  data: {
1717
1736
  options
1718
1737
  },
@@ -1745,7 +1764,7 @@ const SelectTree = forwardRef((_ref, ref) => {
1745
1764
  autoHide: false
1746
1765
  }, treeContent);
1747
1766
  }
1748
- })),
1767
+ })) : null,
1749
1768
  selectedTag: showSelectedTag && /*#__PURE__*/React.createElement("div", {
1750
1769
  className: classnames(style$1['selected-tag'], 'select-tree-selected-tag', {
1751
1770
  'is-popup': isPopup
@@ -2126,7 +2145,7 @@ const CascaderInner = ({
2126
2145
  treeUtils
2127
2146
  };
2128
2147
  useEffect(() => {
2129
- if (!openLoadData || !onLoadMore) {
2148
+ if (!open || !openLoadData || !onLoadMore) {
2130
2149
  return;
2131
2150
  }
2132
2151
  const lastNode = mapping.get(last(selectedIds));
@@ -2146,7 +2165,7 @@ const CascaderInner = ({
2146
2165
  }).catch(() => {
2147
2166
  setLoading(false);
2148
2167
  });
2149
- }, [selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
2168
+ }, [open, selectedIds, mapping, openLoadData, onLoadMore, parentIdKey]);
2150
2169
 
2151
2170
  // 检查是否为非叶子节点
2152
2171
  const isNotLastNode = useCallback(id => {
@@ -2576,7 +2595,7 @@ const SelectCascader = _ref => {
2576
2595
  [labelKey]: String(item)
2577
2596
  };
2578
2597
  }).filter(Boolean);
2579
- return /*#__PURE__*/React.createElement(CascaderInner, {
2598
+ return contextProps.open ? /*#__PURE__*/React.createElement(CascaderInner, {
2580
2599
  options: options,
2581
2600
  value: currentDisplayValue,
2582
2601
  setValue: contextSetValue,
@@ -2595,7 +2614,7 @@ const SelectCascader = _ref => {
2595
2614
  onOpenChange: contextProps.onOpenChange,
2596
2615
  open: contextProps.open,
2597
2616
  isMobile: contextProps.isMobile
2598
- });
2617
+ }) : null;
2599
2618
  });
2600
2619
  };
2601
2620