@zidian-primitive/cascader 0.3.0 → 0.3.1

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,11 +40,13 @@ function useCascader(options) {
40
40
  sourceNodeData2.find((node) => showConfig.depth === node.depth && node[showConfig.showType] === value)
41
41
  );
42
42
  }, [showConfig]);
43
- const isControlled = useMemo(() => pathOption?.showValue || pathOption?.showValue === 0, [pathOption?.showValue]);
44
- const initialPath = useMemo(() => getPathByOption(
45
- sourceNodeData,
46
- pathOption?.showValue ?? pathOption?.defaultShowValue
47
- ), [sourceNodeData, pathOption?.defaultShowValue, pathOption?.showValue]);
43
+ const isControlled = useMemo(() => pathOption?.showValue || pathOption?.showValue === 0 || pathOption?.showValue === "", [pathOption?.showValue]);
44
+ const initialPath = useMemo(() => {
45
+ return getPathByOption(
46
+ sourceNodeData,
47
+ pathOption?.showValue ?? pathOption?.defaultShowValue
48
+ );
49
+ }, [sourceNodeData, pathOption?.defaultShowValue, pathOption?.showValue]);
48
50
  const initialSelected = useMemo(() => new Set(
49
51
  selectOption?.selected ?? selectOption?.defaultSelected
50
52
  ), [selectOption?.selected, selectOption?.defaultSelected]);
@@ -55,19 +57,19 @@ function useCascader(options) {
55
57
  const [internalPath, setInternalPath] = useState(initialPath);
56
58
  const [internalSelected, setInternalSelected] = useState(initialSelected);
57
59
  const [checkStatusArray, setCheckStatusArray] = useState(initialStatusArray);
58
- const path = useMemo(() => isControlled ? initialPath : internalPath, [sourceNodeData, internalPath, isControlled]);
59
- const columns = useMemo(() => getCascadeColumns(sourceNodeData, path), [sourceNodeData, initialPath, path]);
60
+ const path = useMemo(() => isControlled ? initialPath : internalPath, [internalPath, isControlled]);
61
+ const columns = useMemo(() => getCascadeColumns(sourceNodeData, path), [sourceNodeData, path]);
60
62
  const handleChangePath = useCallback((depth, index) => {
61
63
  if (pathOption?.onShowValueChange && depth === showConfig.depth) {
62
64
  pathOption.onShowValueChange(sourceNodeData[index][showConfig.showType], depth);
63
65
  }
64
- if (pathOption?.showValue !== 0 && !pathOption?.showValue) {
66
+ if (!isControlled) {
65
67
  setInternalPath(changeShowPath(
66
68
  sourceNodeData,
67
69
  { oldPath: path, action: { depth, nodeIdx: index } }
68
70
  ));
69
71
  }
70
- }, [pathOption, sourceNodeData]);
72
+ }, [pathOption, sourceNodeData, isControlled]);
71
73
  const handleChangeCheckStatus = useCallback((nodeIdx, checkStatus) => {
72
74
  if (selectOption) {
73
75
  if (selectOption?.selected) {
package/esm/utils/data.js CHANGED
@@ -89,7 +89,7 @@ function getShowPath(nodes, targetNode) {
89
89
  }
90
90
  while (childNode) {
91
91
  showPath[childNode.depth] = childNode.index;
92
- childNode = childNode.childrenIndices[0] ? childNode : null;
92
+ childNode = childNode.childrenIndices[0] ? nodes[childNode.childrenIndices[0]] : null;
93
93
  }
94
94
  return showPath;
95
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zidian-primitive/cascader",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "./src/index.ts",
5
5
  "license": "MIT",
6
6
  "type": "module",