@hi-ui/cascader 4.4.1 → 4.5.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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @hi-ui/cascader
|
|
2
2
|
|
|
3
|
+
## 4.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#3407](https://github.com/XiaoMi/hiui/pull/3407) [`4a1444965`](https://github.com/XiaoMi/hiui/commit/4a1444965bdeeeb12333e43a05caa2e76d74eb47) Thanks [@zyprepare](https://github.com/zyprepare)! - perf(cascader): 体验优化:每次打开菜单时自动定位到已选节点 (#3406)
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`b2de718e9`](https://github.com/XiaoMi/hiui/commit/b2de718e9fd12dbe8fa1d762c6924696c19bc924)]:
|
|
10
|
+
- @hi-ui/core@4.0.11
|
|
11
|
+
|
|
12
|
+
## 4.5.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#3231](https://github.com/XiaoMi/hiui/pull/3231) [`bbba46153`](https://github.com/XiaoMi/hiui/commit/bbba4615313cd0618deff633bebc657e7f34ec94) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(cascader): onChange 回调中增加选中项对象参数返回 (#3230)
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`dc1311a91`](https://github.com/XiaoMi/hiui/commit/dc1311a917518bc5debef755a9fcd4e33fb58790)]:
|
|
21
|
+
- @hi-ui/use-search-mode@4.2.1
|
|
22
|
+
|
|
3
23
|
## 4.4.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -22,12 +22,14 @@ var index = require('./utils/index.js');
|
|
|
22
22
|
var context = require('./context.js');
|
|
23
23
|
var treeUtils = require('@hi-ui/tree-utils');
|
|
24
24
|
var typeAssertion = require('@hi-ui/type-assertion');
|
|
25
|
+
var scrollIntoView = require('scroll-into-view-if-needed');
|
|
25
26
|
function _interopDefaultCompat(e) {
|
|
26
27
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
|
27
28
|
'default': e
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
32
|
+
var scrollIntoView__default = /*#__PURE__*/_interopDefaultCompat(scrollIntoView);
|
|
31
33
|
var menuListPrefix = classname.getPrefixCls('cascader-menu-list');
|
|
32
34
|
var CascaderMenuList = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
33
35
|
var _a$prefixCls = _a.prefixCls,
|
|
@@ -74,6 +76,24 @@ var CascaderMenu = function CascaderMenu(_ref) {
|
|
|
74
76
|
onLoadChildren = _useCascaderContext2.onLoadChildren,
|
|
75
77
|
getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
|
|
76
78
|
var cls = classname.cx(prefixCls, className);
|
|
79
|
+
var activeNodeRef = React.useRef();
|
|
80
|
+
var rafId = React.useRef(0);
|
|
81
|
+
React.useEffect(function () {
|
|
82
|
+
if (activeNodeRef.current) {
|
|
83
|
+
// 每次打开菜单时,滚动到选中的节点,双重 requestAnimationFrame 确保 DOM 已经渲染后再滚动
|
|
84
|
+
rafId.current = requestAnimationFrame(function () {
|
|
85
|
+
rafId.current = requestAnimationFrame(function () {
|
|
86
|
+
scrollIntoView__default["default"](activeNodeRef.current, {
|
|
87
|
+
scrollMode: 'if-needed',
|
|
88
|
+
block: 'center'
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return function () {
|
|
94
|
+
cancelAnimationFrame(rafId.current);
|
|
95
|
+
};
|
|
96
|
+
}, [activeNodeRef]);
|
|
77
97
|
return /*#__PURE__*/React__default["default"].createElement("ul", {
|
|
78
98
|
className: cls,
|
|
79
99
|
style: style,
|
|
@@ -86,6 +106,11 @@ var CascaderMenu = function CascaderMenu(_ref) {
|
|
|
86
106
|
var disabled = disabledContext || option.disabled;
|
|
87
107
|
var optionCls = classname.cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
|
|
88
108
|
return /*#__PURE__*/React__default["default"].createElement("li", {
|
|
109
|
+
ref: function ref(node) {
|
|
110
|
+
if (node && active) {
|
|
111
|
+
activeNodeRef.current = node;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
89
114
|
key: option.id,
|
|
90
115
|
role: "menu-item",
|
|
91
116
|
className: prefixCls + "-item"
|
package/lib/cjs/use-cascader.js
CHANGED
|
@@ -56,7 +56,7 @@ var useCascader = function useCascader(_a) {
|
|
|
56
56
|
tryChangeValue(itemPaths.map(function (_ref) {
|
|
57
57
|
var id = _ref.id;
|
|
58
58
|
return id;
|
|
59
|
-
}));
|
|
59
|
+
}), item, itemPaths);
|
|
60
60
|
onSelectProp === null || onSelectProp === void 0 ? void 0 : onSelectProp(value, item, itemPaths);
|
|
61
61
|
};
|
|
62
62
|
// 单击选中某项
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
import { __rest } from 'tslib';
|
|
11
|
-
import React, { forwardRef } from 'react';
|
|
11
|
+
import React, { forwardRef, useRef, useEffect } from 'react';
|
|
12
12
|
import { getPrefixCls, cx } from '@hi-ui/classname';
|
|
13
13
|
import { __DEV__ } from '@hi-ui/env';
|
|
14
14
|
import { defaultLoadingIcon, defaultSuffixIcon, defaultLeafIcon } from './icons/index.js';
|
|
@@ -16,6 +16,7 @@ import { getItemEventData, checkCanLoadChildren } from './utils/index.js';
|
|
|
16
16
|
import { useCascaderContext } from './context.js';
|
|
17
17
|
import { getTopDownAncestors } from '@hi-ui/tree-utils';
|
|
18
18
|
import { isArrayNonEmpty, isFunction } from '@hi-ui/type-assertion';
|
|
19
|
+
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
19
20
|
var menuListPrefix = getPrefixCls('cascader-menu-list');
|
|
20
21
|
var CascaderMenuList = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
21
22
|
var _a$prefixCls = _a.prefixCls,
|
|
@@ -62,6 +63,24 @@ var CascaderMenu = function CascaderMenu(_ref) {
|
|
|
62
63
|
onLoadChildren = _useCascaderContext2.onLoadChildren,
|
|
63
64
|
getItemRequiredProps = _useCascaderContext2.getItemRequiredProps;
|
|
64
65
|
var cls = cx(prefixCls, className);
|
|
66
|
+
var activeNodeRef = useRef();
|
|
67
|
+
var rafId = useRef(0);
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
if (activeNodeRef.current) {
|
|
70
|
+
// 每次打开菜单时,滚动到选中的节点,双重 requestAnimationFrame 确保 DOM 已经渲染后再滚动
|
|
71
|
+
rafId.current = requestAnimationFrame(function () {
|
|
72
|
+
rafId.current = requestAnimationFrame(function () {
|
|
73
|
+
scrollIntoView(activeNodeRef.current, {
|
|
74
|
+
scrollMode: 'if-needed',
|
|
75
|
+
block: 'center'
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return function () {
|
|
81
|
+
cancelAnimationFrame(rafId.current);
|
|
82
|
+
};
|
|
83
|
+
}, [activeNodeRef]);
|
|
65
84
|
return /*#__PURE__*/React.createElement("ul", {
|
|
66
85
|
className: cls,
|
|
67
86
|
style: style,
|
|
@@ -74,6 +93,11 @@ var CascaderMenu = function CascaderMenu(_ref) {
|
|
|
74
93
|
var disabled = disabledContext || option.disabled;
|
|
75
94
|
var optionCls = cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
|
|
76
95
|
return /*#__PURE__*/React.createElement("li", {
|
|
96
|
+
ref: function ref(node) {
|
|
97
|
+
if (node && active) {
|
|
98
|
+
activeNodeRef.current = node;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
77
101
|
key: option.id,
|
|
78
102
|
role: "menu-item",
|
|
79
103
|
className: prefixCls + "-item"
|
package/lib/esm/use-cascader.js
CHANGED
|
@@ -51,7 +51,7 @@ var useCascader = function useCascader(_a) {
|
|
|
51
51
|
tryChangeValue(itemPaths.map(function (_ref) {
|
|
52
52
|
var id = _ref.id;
|
|
53
53
|
return id;
|
|
54
|
-
}));
|
|
54
|
+
}), item, itemPaths);
|
|
55
55
|
onSelectProp === null || onSelectProp === void 0 ? void 0 : onSelectProp(value, item, itemPaths);
|
|
56
56
|
};
|
|
57
57
|
// 单击选中某项
|
|
@@ -41,7 +41,7 @@ export interface UseCascaderProps {
|
|
|
41
41
|
/**
|
|
42
42
|
* 选中值改变时的回调
|
|
43
43
|
*/
|
|
44
|
-
onChange?: (value: React.ReactText[]) => void;
|
|
44
|
+
onChange?: (value: React.ReactText[], targetOption?: CascaderItemEventData, optionPaths?: FlattedCascaderDataItem[]) => void;
|
|
45
45
|
/**
|
|
46
46
|
* 选中选项时触发,仅供内部使用。暂不对外暴露
|
|
47
47
|
* @private
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ui/cascader",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "HiUI <mi-hiui@xiaomi.com>",
|
|
@@ -58,17 +58,18 @@
|
|
|
58
58
|
"@hi-ui/use-check-state": "^4.0.4",
|
|
59
59
|
"@hi-ui/use-data-source": "^4.0.4",
|
|
60
60
|
"@hi-ui/use-latest": "^4.0.4",
|
|
61
|
-
"@hi-ui/use-search-mode": "^4.1
|
|
61
|
+
"@hi-ui/use-search-mode": "^4.2.1",
|
|
62
62
|
"@hi-ui/use-toggle": "^4.0.4",
|
|
63
|
-
"@hi-ui/use-uncontrolled-state": "^4.0.4"
|
|
63
|
+
"@hi-ui/use-uncontrolled-state": "^4.0.4",
|
|
64
|
+
"scroll-into-view-if-needed": "^3.1.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@hi-ui/core": ">=4.0.
|
|
67
|
+
"@hi-ui/core": ">=4.0.11",
|
|
67
68
|
"react": ">=16.8.6",
|
|
68
69
|
"react-dom": ">=16.8.6"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
|
-
"@hi-ui/core": "^4.0.
|
|
72
|
+
"@hi-ui/core": "^4.0.11",
|
|
72
73
|
"@hi-ui/core-css": "^4.1.5",
|
|
73
74
|
"react": "^17.0.1",
|
|
74
75
|
"react-dom": "^17.0.1"
|