rsuite 4.11.0 → 4.11.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.
@@ -23,7 +23,6 @@ import {
23
23
  getExpandWhenSearching,
24
24
  getNodeParents,
25
25
  shouldShowNodeByExpanded,
26
- getVirtualLisHeight,
27
26
  treeDeprecatedWarning,
28
27
  hasVisibleChildren,
29
28
  compareArray,
@@ -97,6 +96,7 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
97
96
  };
98
97
  static defaultProps = {
99
98
  ...listPickerDefaultProps,
99
+ height: defaultHeight,
100
100
  searchable: true,
101
101
  menuAutoWidth: true,
102
102
  locale: {
@@ -163,7 +163,10 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
163
163
  nextState.selectedValue = value;
164
164
  }
165
165
 
166
- if (compareArray(expandItemValues, prevState.expandItemValues)) {
166
+ if (
167
+ compareArray(expandItemValues, prevState.expandItemValues) &&
168
+ Array.isArray(expandItemValues)
169
+ ) {
167
170
  nextState.expandItemValues = expandItemValues;
168
171
  }
169
172
 
@@ -249,7 +252,10 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
249
252
 
250
253
  updateExpandItemValuesChange(prevState: TreePickerState) {
251
254
  const { expandItemValues } = this.props;
252
- if (compareArray(expandItemValues, prevState.expandItemValues)) {
255
+ if (
256
+ compareArray(expandItemValues, prevState.expandItemValues) &&
257
+ Array.isArray(expandItemValues)
258
+ ) {
253
259
  this.unserializeLists('expand', expandItemValues);
254
260
 
255
261
  this.setState({
@@ -858,27 +864,23 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
858
864
 
859
865
  renderDropdownMenu() {
860
866
  const {
861
- height = defaultHeight,
862
867
  searchable,
863
868
  searchKeyword,
864
869
  renderExtraFooter,
865
870
  locale,
866
871
  renderMenu,
867
872
  menuStyle,
868
- virtualized,
869
873
  menuClassName,
870
874
  menuAutoWidth
871
875
  } = this.props;
872
876
  const keyword = !_.isUndefined(searchKeyword) ? searchKeyword : this.state.searchKeyword;
873
877
  const classes = classNames(menuClassName, this.addPrefix('tree-menu'));
874
878
 
875
- const styles = virtualized ? { height, ...menuStyle } : menuStyle;
876
-
877
879
  return (
878
880
  <MenuWrapper
879
881
  autoWidth={menuAutoWidth}
880
882
  className={classes}
881
- style={styles}
883
+ style={menuStyle}
882
884
  ref={this.menuRef}
883
885
  getToggleInstance={this.getToggleInstance}
884
886
  getPositionInstance={this.getPositionInstance}
@@ -977,7 +979,7 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
977
979
 
978
980
  renderTree() {
979
981
  const { filterData } = this.state;
980
- const { height, className, inline, style, locale, virtualized, searchable } = this.props;
982
+ const { height, className, inline, style, locale, virtualized } = this.props;
981
983
 
982
984
  const layer = 0;
983
985
 
@@ -999,30 +1001,32 @@ class TreePicker extends React.Component<TreePickerProps, TreePickerState> {
999
1001
  }
1000
1002
  }
1001
1003
 
1002
- // 当未定义 height 设置了 virtualized true,treeHeight 设置默认高度
1003
- const treeHeight = _.isUndefined(height) && virtualized ? defaultHeight : height;
1004
+ // The height of virtualized tree should be subtract the value of paddingBottom
1005
+ const treeHeight = height - 12;
1004
1006
  const treeWidth = _.isUndefined(style?.width) ? defaultWidth : style.width;
1005
- const styles = inline ? { height: treeHeight, ...style } : {};
1006
-
1007
- const listHeight = getVirtualLisHeight(inline, searchable, treeHeight);
1007
+ const listStyles = inline ? { height, ...style } : style;
1008
1008
 
1009
1009
  return (
1010
1010
  <React.Fragment>
1011
1011
  <div
1012
1012
  ref={this.treeViewRef}
1013
1013
  className={classes}
1014
- style={styles}
1014
+ style={listStyles}
1015
1015
  onKeyDown={this.handleKeyDown}
1016
1016
  >
1017
1017
  <div className={this.addTreePrefix('nodes')}>
1018
1018
  {virtualized ? (
1019
- <AutoSizer defaultHeight={listHeight} defaultWidth={treeWidth}>
1019
+ <AutoSizer
1020
+ defaultHeight={treeHeight}
1021
+ defaultWidth={treeWidth}
1022
+ style={{ width: 'auto', height: 'auto' }}
1023
+ >
1020
1024
  {({ height, width }) => (
1021
1025
  <List
1022
1026
  ref={this.listRef}
1023
1027
  width={width || treeWidth}
1024
- height={height || listHeight}
1025
- rowHeight={38}
1028
+ height={height}
1029
+ rowHeight={36}
1026
1030
  rowCount={nodes.length}
1027
1031
  rowRenderer={this.measureRowRenderer(nodes)}
1028
1032
  />
@@ -428,4 +428,9 @@ describe('TreePicker', () => {
428
428
  1
429
429
  );
430
430
  });
431
+
432
+ it('should render all nodes when set virtualized and defaultExpandAll', () => {
433
+ const instance = mount(<TreePicker data={data} open virtualized defaultExpandAll />);
434
+ assert.equal(instance.find('.rs-tree-node').length, 5);
435
+ });
431
436
  });
@@ -6,13 +6,12 @@ import { TREE_NODE_DROP_POSITION } from '../constants';
6
6
  import { TreePickerProps } from '../TreePicker/TreePicker.d';
7
7
  import { CheckTreePickerProps } from '../CheckTreePicker/CheckTreePicker.d';
8
8
 
9
- const SEARCH_BAR_HEIGHT = 48;
10
- const MENU_PADDING = 12;
11
9
  // Tree Node 之间的 间隔
12
10
  const TREE_NODE_GAP = 4;
13
11
 
14
12
  /**
15
- * 判断当前节点是否应该显示
13
+ * Whether current node is visible
14
+ * when all the parents of the current node is expanded, the current node should be visible
16
15
  * @param {*} expandItemValues
17
16
  * @param {*} parentKeys
18
17
  */
@@ -80,16 +79,6 @@ export function getNodeParents(node: object, parentKey = 'parent', valueKey?: st
80
79
  return parents;
81
80
  }
82
81
 
83
- /**
84
- * 获取 VirtualList 的高度
85
- * @param {*} inline
86
- * @param {*} height
87
- */
88
- export function getVirtualLisHeight(inline: boolean, searchable: boolean, height = 0) {
89
- const searchBarHeight = searchable ? SEARCH_BAR_HEIGHT : 0;
90
- return inline ? height - MENU_PADDING * 2 : height - searchBarHeight - MENU_PADDING * 2;
91
- }
92
-
93
82
  /**
94
83
  * 判断节点是否存在可见的子节点。
95
84
  * @param node