@hi-ui/cascader 4.5.0 → 4.5.2

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,20 @@
1
1
  # @hi-ui/cascader
2
2
 
3
+ ## 4.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3415](https://github.com/XiaoMi/hiui/pull/3415) [`e7a09db`](https://github.com/XiaoMi/hiui/commit/e7a09db7f75022fee82a254a74a2ec17c6b03638) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(cascader): 修复在异步加载数据下,首次打开弹窗没有定位到已选节点位置的问题 (#3414)
8
+
9
+ ## 4.5.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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)
14
+
15
+ - Updated dependencies [[`b2de718e9`](https://github.com/XiaoMi/hiui/commit/b2de718e9fd12dbe8fa1d762c6924696c19bc924)]:
16
+ - @hi-ui/core@4.0.11
17
+
3
18
  ## 4.5.0
4
19
 
5
20
  ### Minor 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,26 @@ 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 _useState = React.useState(null),
81
+ activeNode = _useState[0],
82
+ setActiveNode = _useState[1];
83
+ var timeoutId = React.useRef(null);
84
+ React.useEffect(function () {
85
+ if (activeNode) {
86
+ timeoutId.current = setTimeout(function () {
87
+ scrollIntoView__default["default"](activeNode, {
88
+ scrollMode: 'if-needed',
89
+ block: 'center'
90
+ });
91
+ }, 100);
92
+ }
93
+ return function () {
94
+ if (timeoutId.current) {
95
+ clearTimeout(timeoutId.current);
96
+ }
97
+ };
98
+ }, [activeNode, activeNodeRef]);
77
99
  return /*#__PURE__*/React__default["default"].createElement("ul", {
78
100
  className: cls,
79
101
  style: style,
@@ -86,6 +108,11 @@ var CascaderMenu = function CascaderMenu(_ref) {
86
108
  var disabled = disabledContext || option.disabled;
87
109
  var optionCls = classname.cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
88
110
  return /*#__PURE__*/React__default["default"].createElement("li", {
111
+ ref: function ref(node) {
112
+ if (node && active) {
113
+ setActiveNode(node);
114
+ }
115
+ },
89
116
  key: option.id,
90
117
  role: "menu-item",
91
118
  className: prefixCls + "-item"
@@ -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, useState, 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,26 @@ 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 _useState = useState(null),
68
+ activeNode = _useState[0],
69
+ setActiveNode = _useState[1];
70
+ var timeoutId = useRef(null);
71
+ useEffect(function () {
72
+ if (activeNode) {
73
+ timeoutId.current = setTimeout(function () {
74
+ scrollIntoView(activeNode, {
75
+ scrollMode: 'if-needed',
76
+ block: 'center'
77
+ });
78
+ }, 100);
79
+ }
80
+ return function () {
81
+ if (timeoutId.current) {
82
+ clearTimeout(timeoutId.current);
83
+ }
84
+ };
85
+ }, [activeNode, activeNodeRef]);
65
86
  return /*#__PURE__*/React.createElement("ul", {
66
87
  className: cls,
67
88
  style: style,
@@ -74,6 +95,11 @@ var CascaderMenu = function CascaderMenu(_ref) {
74
95
  var disabled = disabledContext || option.disabled;
75
96
  var optionCls = cx(prefixCls + "-option", active && prefixCls + "-option--active", loading && prefixCls + "-option--loading", disabled && prefixCls + "-option--disabled", selected && prefixCls + "-option--selected");
76
97
  return /*#__PURE__*/React.createElement("li", {
98
+ ref: function ref(node) {
99
+ if (node && active) {
100
+ setActiveNode(node);
101
+ }
102
+ },
77
103
  key: option.id,
78
104
  role: "menu-item",
79
105
  className: prefixCls + "-item"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/cascader",
3
- "version": "4.5.0",
3
+ "version": "4.5.2",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",
@@ -60,15 +60,16 @@
60
60
  "@hi-ui/use-latest": "^4.0.4",
61
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.8",
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.8",
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"