rsuite 4.10.3 → 4.10.4

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.
@@ -36,6 +36,7 @@ function (_React$Component) {
36
36
  _this.triggerRef = void 0;
37
37
  _this.containerRef = void 0;
38
38
  _this.positionRef = void 0;
39
+ _this.menuWrapperRef = void 0;
39
40
  _this.menuContainerRef = void 0;
40
41
  _this.isControlled = void 0;
41
42
 
@@ -291,7 +292,7 @@ function (_React$Component) {
291
292
  items: []
292
293
  };
293
294
  _this.state = _extends({}, initState, {}, getDerivedStateForCascade(props, initState), {
294
- flattenData: flattenTree(props.data)
295
+ flattenData: flattenTree(props.data, props.childrenKey)
295
296
  });
296
297
  _this.isControlled = !_isUndefined(props.value);
297
298
  _this.triggerRef = React.createRef();
@@ -299,6 +300,7 @@ function (_React$Component) {
299
300
  _this.positionRef = React.createRef();
300
301
  _this.toggleRef = React.createRef(); // for test
301
302
 
303
+ _this.menuWrapperRef = React.createRef();
302
304
  _this.menuContainerRef = React.createRef();
303
305
  return _this;
304
306
  }
@@ -307,7 +309,8 @@ function (_React$Component) {
307
309
  var value = nextProps.value,
308
310
  data = nextProps.data,
309
311
  labelKey = nextProps.labelKey,
310
- valueKey = nextProps.valueKey;
312
+ valueKey = nextProps.valueKey,
313
+ childrenKey = nextProps.childrenKey;
311
314
 
312
315
  if (data !== prevState.data) {
313
316
  var _prevState$selectNode;
@@ -325,12 +328,12 @@ function (_React$Component) {
325
328
  return _stringToObject(item, labelKey, valueKey);
326
329
  })), {
327
330
  data: data,
328
- flattenData: flattenTree(data)
331
+ flattenData: flattenTree(data, childrenKey)
329
332
  });
330
333
  }
331
334
 
332
335
  return _extends({}, getDerivedStateForCascade(nextProps, prevState), {
333
- flattenData: flattenTree(data),
336
+ flattenData: flattenTree(data, childrenKey),
334
337
  data: data
335
338
  });
336
339
  }
@@ -441,6 +444,7 @@ function (_React$Component) {
441
444
  var menuProps = _pick(this.props, Object.keys(_omit(dropdownMenuPropTypes, ['classPrefix'])));
442
445
 
443
446
  return React.createElement(MenuWrapper, {
447
+ ref: this.menuWrapperRef,
444
448
  className: classes,
445
449
  style: menuStyle,
446
450
  getToggleInstance: this.getToggleInstance,
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
- import { StandardProps } from '../@types/common';
2
+ import { StandardProps, FormControlBaseProps } from '../@types/common';
3
3
 
4
- export interface SliderProps<ValueType = number> extends StandardProps {
4
+ export interface SliderProps<ValueType = number>
5
+ extends StandardProps,
6
+ FormControlBaseProps<ValueType> {
5
7
  /** Minimum value of sliding range */
6
8
  min?: number;
7
9
 
@@ -11,12 +13,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
11
13
  /** Slide the value of one step */
12
14
  step?: number;
13
15
 
14
- /** Value (Controlled) */
15
- value?: ValueType;
16
-
17
- /** Default value */
18
- defaultValue?: ValueType;
19
-
20
16
  /** A css class to apply to the Handle node. */
21
17
  handleClassName?: string;
22
18
 
@@ -44,9 +40,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
44
40
  /** Vertical Slide */
45
41
  vertical?: boolean;
46
42
 
47
- /** Callback function that changes data */
48
- onChange?: (value: ValueType, event: React.MouseEvent) => void;
49
-
50
43
  /** Customize labels on the render ruler */
51
44
  renderMark?: (mark: number) => React.ReactNode;
52
45
  }
@@ -66,6 +66,7 @@ function (_React$Component) {
66
66
  _this.triggerRef = void 0;
67
67
  _this.containerRef = void 0;
68
68
  _this.positionRef = void 0;
69
+ _this.menuWrapperRef = void 0;
69
70
  _this.menuContainerRef = void 0;
70
71
  _this.isControlled = void 0;
71
72
 
@@ -321,7 +322,7 @@ function (_React$Component) {
321
322
  items: []
322
323
  };
323
324
  _this.state = (0, _extends3.default)({}, initState, {}, (0, _utils.getDerivedStateForCascade)(props, initState), {
324
- flattenData: (0, _treeUtils.flattenTree)(props.data)
325
+ flattenData: (0, _treeUtils.flattenTree)(props.data, props.childrenKey)
325
326
  });
326
327
  _this.isControlled = !(0, _isUndefined2.default)(props.value);
327
328
  _this.triggerRef = React.createRef();
@@ -329,6 +330,7 @@ function (_React$Component) {
329
330
  _this.positionRef = React.createRef();
330
331
  _this.toggleRef = React.createRef(); // for test
331
332
 
333
+ _this.menuWrapperRef = React.createRef();
332
334
  _this.menuContainerRef = React.createRef();
333
335
  return _this;
334
336
  }
@@ -337,7 +339,8 @@ function (_React$Component) {
337
339
  var value = nextProps.value,
338
340
  data = nextProps.data,
339
341
  labelKey = nextProps.labelKey,
340
- valueKey = nextProps.valueKey;
342
+ valueKey = nextProps.valueKey,
343
+ childrenKey = nextProps.childrenKey;
341
344
 
342
345
  if (data !== prevState.data) {
343
346
  var _prevState$selectNode;
@@ -355,12 +358,12 @@ function (_React$Component) {
355
358
  return (0, _stringToObject2.default)(item, labelKey, valueKey);
356
359
  })), {
357
360
  data: data,
358
- flattenData: (0, _treeUtils.flattenTree)(data)
361
+ flattenData: (0, _treeUtils.flattenTree)(data, childrenKey)
359
362
  });
360
363
  }
361
364
 
362
365
  return (0, _extends3.default)({}, (0, _utils.getDerivedStateForCascade)(nextProps, prevState), {
363
- flattenData: (0, _treeUtils.flattenTree)(data),
366
+ flattenData: (0, _treeUtils.flattenTree)(data, childrenKey),
364
367
  data: data
365
368
  });
366
369
  }
@@ -469,6 +472,7 @@ function (_React$Component) {
469
472
  var classes = (0, _classnames.default)(this.addPrefix('cascader-menu'), menuClassName, (_classNames2 = {}, _classNames2[this.addPrefix('inline')] = inline, _classNames2));
470
473
  var menuProps = (0, _pick2.default)(this.props, Object.keys((0, _omit2.default)(_DropdownMenu.dropdownMenuPropTypes, ['classPrefix'])));
471
474
  return React.createElement(_Picker.MenuWrapper, {
475
+ ref: this.menuWrapperRef,
472
476
  className: classes,
473
477
  style: menuStyle,
474
478
  getToggleInstance: this.getToggleInstance,
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
- import { StandardProps } from '../@types/common';
2
+ import { StandardProps, FormControlBaseProps } from '../@types/common';
3
3
 
4
- export interface SliderProps<ValueType = number> extends StandardProps {
4
+ export interface SliderProps<ValueType = number>
5
+ extends StandardProps,
6
+ FormControlBaseProps<ValueType> {
5
7
  /** Minimum value of sliding range */
6
8
  min?: number;
7
9
 
@@ -11,12 +13,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
11
13
  /** Slide the value of one step */
12
14
  step?: number;
13
15
 
14
- /** Value (Controlled) */
15
- value?: ValueType;
16
-
17
- /** Default value */
18
- defaultValue?: ValueType;
19
-
20
16
  /** A css class to apply to the Handle node. */
21
17
  handleClassName?: string;
22
18
 
@@ -44,9 +40,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
44
40
  /** Vertical Slide */
45
41
  vertical?: boolean;
46
42
 
47
- /** Callback function that changes data */
48
- onChange?: (value: ValueType, event: React.MouseEvent) => void;
49
-
50
43
  /** Customize labels on the render ruler */
51
44
  renderMark?: (mark: number) => React.ReactNode;
52
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "4.10.3",
3
+ "version": "4.10.4",
4
4
  "description": "A suite of react components",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -29,7 +29,8 @@
29
29
  "test:component": "cross-env NODE_ENV=coverage RUN_ENV=test karma start --single-run",
30
30
  "test:styles": "node test/stylesSpec.js",
31
31
  "coveralls": "cat ./coverage/lcov/lcov.info | ./node_modules/.bin/coveralls",
32
- "prepublishOnly": "npm run build"
32
+ "prepublishOnly": "npm run build",
33
+ "version": "npm run changelog && git add -A"
33
34
  },
34
35
  "keywords": [
35
36
  "react",
@@ -73,6 +73,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
73
73
  triggerRef: React.RefObject<any>;
74
74
  containerRef: React.RefObject<any>;
75
75
  positionRef: React.RefObject<any>;
76
+ menuWrapperRef: React.RefObject<any>;
76
77
  menuContainerRef: React.RefObject<any>;
77
78
  isControlled: boolean;
78
79
 
@@ -98,7 +99,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
98
99
  this.state = {
99
100
  ...initState,
100
101
  ...getDerivedStateForCascade(props, initState),
101
- flattenData: flattenTree(props.data)
102
+ flattenData: flattenTree(props.data, props.childrenKey)
102
103
  };
103
104
 
104
105
  this.isControlled = !_.isUndefined(props.value);
@@ -108,11 +109,12 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
108
109
  this.toggleRef = React.createRef();
109
110
 
110
111
  // for test
112
+ this.menuWrapperRef = React.createRef();
111
113
  this.menuContainerRef = React.createRef();
112
114
  }
113
115
 
114
116
  static getDerivedStateFromProps(nextProps, prevState) {
115
- const { value, data, labelKey, valueKey } = nextProps;
117
+ const { value, data, labelKey, valueKey, childrenKey } = nextProps;
116
118
  if (data !== prevState.data) {
117
119
  // First get the value of the clicked node `selectNodeValue`, and then get the new `newChildren`.
118
120
  const selectNodeValue = prevState?.selectNode?.[valueKey];
@@ -129,13 +131,13 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
129
131
  newChildren.map(item => stringToObject(item, labelKey, valueKey))
130
132
  ),
131
133
  data,
132
- flattenData: flattenTree(data)
134
+ flattenData: flattenTree(data, childrenKey)
133
135
  };
134
136
  }
135
137
 
136
138
  return {
137
139
  ...getDerivedStateForCascade(nextProps, prevState),
138
- flattenData: flattenTree(data),
140
+ flattenData: flattenTree(data, childrenKey),
139
141
  data
140
142
  };
141
143
  }
@@ -450,6 +452,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
450
452
 
451
453
  return (
452
454
  <MenuWrapper
455
+ ref={this.menuWrapperRef}
453
456
  className={classes}
454
457
  style={menuStyle}
455
458
  getToggleInstance={this.getToggleInstance}
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import ReactTestUtils from 'react-dom/test-utils';
2
+ import ReactTestUtils, { act } from 'react-dom/test-utils';
3
3
  import Cascader from '../Cascader';
4
4
  import Button from '../../Button';
5
5
  import { getDOMNode, getInstance } from '@test/testUtils';
@@ -214,4 +214,59 @@ describe('Cascader', () => {
214
214
  assert.equal(instance2.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
215
215
  assert.equal(instance3.querySelector('.rs-picker-toggle-placeholder').innerText, 'Select');
216
216
  });
217
+
218
+ it('Should show search items with childrenKey', () => {
219
+ const itemsWithChildrenKey = {
220
+ childrenKey: 'sub',
221
+ data: [
222
+ {
223
+ value: 't',
224
+ label: 't'
225
+ },
226
+ {
227
+ value: 'h',
228
+ label: 'h'
229
+ },
230
+ {
231
+ value: 'g',
232
+ label: 'g',
233
+ sub: [
234
+ {
235
+ value: 'g-m',
236
+ label: 'g-m'
237
+ },
238
+ {
239
+ value: 'g-b',
240
+ label: 'g-b'
241
+ }
242
+ ]
243
+ }
244
+ ]
245
+ };
246
+
247
+ const instance = getInstance(
248
+ <Cascader
249
+ defaultOpen
250
+ data={itemsWithChildrenKey.data}
251
+ childrenKey={itemsWithChildrenKey.childrenKey}
252
+ />
253
+ );
254
+
255
+ const overlay = getDOMNode(instance.menuWrapperRef.current);
256
+
257
+ ReactTestUtils.act(() => {
258
+ const input = overlay.querySelector('.rs-picker-search-bar-input');
259
+
260
+ ReactTestUtils.Simulate.focus(input);
261
+
262
+ input.value = 'g';
263
+ ReactTestUtils.Simulate.change(input);
264
+ });
265
+
266
+ ReactTestUtils.act(() => {
267
+ const searchResult = overlay.querySelectorAll('.rs-picker-cascader-row');
268
+
269
+ assert.equal(searchResult.length, 2);
270
+ });
271
+ });
217
272
  });
@@ -1,7 +1,9 @@
1
1
  import * as React from 'react';
2
- import { StandardProps } from '../@types/common';
2
+ import { StandardProps, FormControlBaseProps } from '../@types/common';
3
3
 
4
- export interface SliderProps<ValueType = number> extends StandardProps {
4
+ export interface SliderProps<ValueType = number>
5
+ extends StandardProps,
6
+ FormControlBaseProps<ValueType> {
5
7
  /** Minimum value of sliding range */
6
8
  min?: number;
7
9
 
@@ -11,12 +13,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
11
13
  /** Slide the value of one step */
12
14
  step?: number;
13
15
 
14
- /** Value (Controlled) */
15
- value?: ValueType;
16
-
17
- /** Default value */
18
- defaultValue?: ValueType;
19
-
20
16
  /** A css class to apply to the Handle node. */
21
17
  handleClassName?: string;
22
18
 
@@ -44,9 +40,6 @@ export interface SliderProps<ValueType = number> extends StandardProps {
44
40
  /** Vertical Slide */
45
41
  vertical?: boolean;
46
42
 
47
- /** Callback function that changes data */
48
- onChange?: (value: ValueType, event: React.MouseEvent) => void;
49
-
50
43
  /** Customize labels on the render ruler */
51
44
  renderMark?: (mark: number) => React.ReactNode;
52
45
  }