@douyinfe/semi-ui 2.17.0-beta.0 → 2.17.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.
@@ -361,6 +361,8 @@ class AutoComplete<T extends AutoCompleteItems> extends BaseComponent<AutoComple
361
361
  ref: this.triggerRef,
362
362
  id,
363
363
  ...keyboardEventSet,
364
+ // tooltip give tabindex 0 to children by default, autoComplete just need the input get focus, so outer div's tabindex set to -1
365
+ tabIndex: -1
364
366
  };
365
367
 
366
368
  const innerProps = {
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useState, useCallback, useEffect } from 'react';
2
2
  import CustomTrigger from './CustomTrigger';
3
3
  import { Button, Typography, Toast, Cascader } from '../../index';
4
4
 
@@ -262,6 +262,96 @@ const treedataWithNodeLabel = [
262
262
  }
263
263
  ];
264
264
 
265
+ export const issue703 = () => {
266
+ const initialData = [
267
+ {
268
+ label: 'Node1',
269
+ value: '0-0',
270
+ },
271
+ {
272
+ label: 'Node2',
273
+ value: '0-1',
274
+ },
275
+ {
276
+ label: 'Node3',
277
+ value: '0-2',
278
+ isLeaf: true
279
+ },
280
+ ];
281
+ const [data, setData] = useState(initialData);
282
+
283
+ const updateTreeData = (list, value, children) => {
284
+ return list.map(node => {
285
+ if (node.value === value) {
286
+ return { ...node, children };
287
+ }
288
+ if (node.children) {
289
+ return { ...node, children: updateTreeData(node.children, value, children) };
290
+ }
291
+ return node;
292
+ });
293
+ };
294
+
295
+ const onLoadData = selectedOpt => {
296
+ const targetOpt = selectedOpt[selectedOpt.length - 1];
297
+ const { label, value } = targetOpt;
298
+ return new Promise(resolve => {
299
+ if (targetOpt.children) {
300
+ resolve();
301
+ return;
302
+ }
303
+
304
+ setTimeout(() => {
305
+ setData(origin =>
306
+ updateTreeData(origin, value, [
307
+ {
308
+ label: `${label}-1`,
309
+ value: `${label}-1`,
310
+ isLeaf: selectedOpt.length > 1
311
+ },
312
+ {
313
+ label: `${label}-2`,
314
+ value: `${label}-2`,
315
+ isLeaf: selectedOpt.length > 1
316
+ },
317
+ ]),
318
+ );
319
+ resolve();
320
+ }, 1000);
321
+ });
322
+ };
323
+
324
+ const [v,setV]=useState([['0-0'], ['0-1', 'Node2-2']]);
325
+ useEffect(()=>{
326
+ console.log('data change');
327
+ setTimeout(()=>setV([['0-0'], ['0-1', 'Node2-2', 'Node2-2-2']]),0);
328
+ },[data])
329
+
330
+ return (
331
+ <>
332
+ <div>treeData和value动态更新,value中的值在treeData中存在则能够正确显示</div>
333
+ <Cascader
334
+ multiple
335
+ onChange={(a)=>console.log(a)}
336
+ value={v}
337
+ style={{ width: 300 }}
338
+ treeData={data}
339
+ loadData={onLoadData}
340
+ placeholder="Please select"
341
+ />
342
+ <div>非受控,动态更新treeData</div>
343
+ <Cascader
344
+ multiple
345
+ onChange={(a)=>console.log(a)}
346
+ style={{ width: 300 }}
347
+ treeData={data}
348
+ loadData={onLoadData}
349
+ placeholder="Please select"
350
+ />
351
+ </>
352
+ );
353
+ };
354
+
265
355
  export const _Cascader = () => {
266
356
  return (
267
357
  <div>
@@ -394,6 +394,34 @@ class Cascader extends BaseComponent<CascaderProps, CascaderState> {
394
394
  const treeDataHasChange = prevProps && prevProps.treeData !== props.treeData;
395
395
  return firstInProps || treeDataHasChange;
396
396
  };
397
+ const getRealKeys = (realValue: Value, keyEntities: Entities) => {
398
+ // normallizedValue is used to save the value in two-dimensional array format
399
+ let normallizedValue: SimpleValueType[][] = [];
400
+ if (Array.isArray(realValue)) {
401
+ normallizedValue = Array.isArray(realValue[0])
402
+ ? (realValue as SimpleValueType[][])
403
+ : ([realValue] as SimpleValueType[][]);
404
+ } else {
405
+ if (realValue !== undefined) {
406
+ normallizedValue = [[realValue]];
407
+ }
408
+ }
409
+ // formatValuePath is used to save value of valuePath
410
+ const formatValuePath: (string | number)[][] = [];
411
+ normallizedValue.forEach((valueItem: SimpleValueType[]) => {
412
+ const formatItem: (string | number)[] = onChangeWithObject ?
413
+ (valueItem as CascaderData[]).map(i => i?.value) :
414
+ valueItem as (string | number)[];
415
+ formatValuePath.push(formatItem);
416
+ });
417
+ // formatKeys is used to save key of value
418
+ const formatKeys: any[] = [];
419
+ formatValuePath.forEach(v => {
420
+ const formatKeyItem = findKeysForValues(v, keyEntities);
421
+ !isEmpty(formatKeyItem) && formatKeys.push(formatKeyItem);
422
+ });
423
+ return formatKeys;
424
+ };
397
425
  const needUpdateTreeData = needUpdate('treeData') || needUpdateData();
398
426
  const needUpdateValue = needUpdate('value') || (isEmpty(prevProps) && defaultValue);
399
427
  if (multiple) {
@@ -408,34 +436,15 @@ class Cascader extends BaseComponent<CascaderProps, CascaderState> {
408
436
  let realKeys: Array<string> | Set<string> = prevState.checkedKeys;
409
437
  // when data was updated
410
438
  if (needUpdateValue) {
411
- // normallizedValue is used to save the value in two-dimensional array format
412
- let normallizedValue: SimpleValueType[][] = [];
413
439
  const realValue = needUpdate('value') ? value : defaultValue;
414
- // eslint-disable-next-line max-depth
415
- if (Array.isArray(realValue)) {
416
- normallizedValue = Array.isArray(realValue[0])
417
- ? (realValue as SimpleValueType[][])
418
- : ([realValue] as SimpleValueType[][]);
419
- } else {
420
- if (realValue !== undefined) {
421
- normallizedValue = [[realValue]];
422
- }
440
+ realKeys = getRealKeys(realValue, keyEntities);
441
+ } else {
442
+ // needUpdateValue is false
443
+ // if treeData is updated & Cascader is controlled, realKeys should be recalculated
444
+ if (needUpdateTreeData && 'value' in props) {
445
+ const realValue = value;
446
+ realKeys = getRealKeys(realValue, keyEntities);
423
447
  }
424
- // formatValuePath is used to save value of valuePath
425
- const formatValuePath: (string | number)[][] = [];
426
- normallizedValue.forEach((valueItem: SimpleValueType[]) => {
427
- const formatItem: (string | number)[] = onChangeWithObject ?
428
- (valueItem as CascaderData[]).map(i => i?.value) :
429
- valueItem as (string | number)[];
430
- formatValuePath.push(formatItem);
431
- });
432
- // formatKeys is used to save key of value
433
- const formatKeys: any[] = [];
434
- formatValuePath.forEach(v => {
435
- const formatKeyItem = findKeysForValues(v, keyEntities);
436
- !isEmpty(formatKeyItem) && formatKeys.push(formatKeyItem);
437
- });
438
- realKeys = formatKeys;
439
448
  }
440
449
  if (isSet(realKeys)) {
441
450
  realKeys = [...realKeys];
@@ -139,7 +139,10 @@ class Checkbox extends BaseComponent<CheckboxProps, CheckboxState> {
139
139
  }
140
140
 
141
141
  isInGroup() {
142
- return Boolean(this.context && this.context.checkboxGroup);
142
+ // Why do we need to determine whether there is a value in props?
143
+ // If there is no value in the props of the checkbox in the context of the checkboxGroup,
144
+ // it will be considered not to belong to the checkboxGroup。
145
+ return Boolean(this.context && this.context.checkboxGroup && ('value' in this.props));
143
146
  }
144
147
 
145
148
  focus() {
package/dist/css/semi.css CHANGED
@@ -519,7 +519,7 @@ body[theme-mode=dark], body .semi-always-dark {
519
519
  .semi-portal-inner {
520
520
  position: absolute;
521
521
  background-color: transparent;
522
- min-width: fit-content;
522
+ min-width: max-content;
523
523
  }
524
524
 
525
525
  .semi-anchor {