@douyinfe/semi-ui 2.56.0-beta.0 → 2.56.0

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.
@@ -22963,9 +22963,32 @@ class Base extends external_root_React_commonjs2_react_commonjs_react_amd_react_
22963
22963
  if (!rows || rows < 1) {
22964
22964
  return false;
22965
22965
  }
22966
- const updateOverflow = rows <= 1 ? this.wrapperRef.current.scrollWidth > this.wrapperRef.current.offsetWidth : this.wrapperRef.current.scrollHeight > this.wrapperRef.current.offsetHeight;
22966
+ const updateOverflow = rows <= 1 ? this.compareSingleRow() : this.wrapperRef.current.scrollHeight > this.wrapperRef.current.offsetHeight;
22967
22967
  return updateOverflow;
22968
22968
  };
22969
+ /**
22970
+ * 通过将 content 给到 Range 对象,借助 Range 的 getBoundingClientRect 拿到 content 的准确 width
22971
+ * 不受 css ellipsis 与否的影响
22972
+ * By giving the content to the Range object, get the exact width of the content with the help of Range's getBoundingClientRect
22973
+ * Not affected by css ellipsis or not
22974
+ * https://github.com/DouyinFE/semi-design/issues/1731
22975
+ */
22976
+ this.compareSingleRow = () => {
22977
+ if (!(document && document.createRange)) {
22978
+ return false;
22979
+ }
22980
+ const containerNode = this.wrapperRef.current;
22981
+ const containerWidth = containerNode.getBoundingClientRect().width;
22982
+ const childNodes = Array.from(containerNode.childNodes);
22983
+ const range = document.createRange();
22984
+ const contentWidth = childNodes.reduce((acc, node) => {
22985
+ var _a;
22986
+ range.selectNodeContents(node);
22987
+ return acc + ((_a = range.getBoundingClientRect().width) !== null && _a !== void 0 ? _a : 0);
22988
+ }, 0);
22989
+ range.detach();
22990
+ return contentWidth > containerWidth;
22991
+ };
22969
22992
  this.showTooltip = () => {
22970
22993
  var _a, _b;
22971
22994
  const {
@@ -23072,14 +23095,15 @@ class Base extends external_root_React_commonjs2_react_commonjs_react_amd_react_
23072
23095
  expand: this.expandRef.current,
23073
23096
  copy: this.copyRef && this.copyRef.current
23074
23097
  };
23075
- const content = util(this.wrapperRef.current, rows,
23076
23098
  // Perform type conversion on children to prevent component crash due to non-string type of children
23077
- String(children), extraNode, ELLIPSIS_STR, suffix, pos);
23099
+ // https://github.com/DouyinFE/semi-design/issues/2167
23100
+ const realChildren = Array.isArray(children) ? children.join('') : String(children);
23101
+ const content = util(this.wrapperRef.current, rows, realChildren, extraNode, ELLIPSIS_STR, suffix, pos);
23078
23102
  return new Promise(resolve => {
23079
23103
  this.setState({
23080
23104
  isOverflowed: false,
23081
23105
  ellipsisContent: content,
23082
- isTruncated: children !== content
23106
+ isTruncated: realChildren !== content
23083
23107
  }, resolve);
23084
23108
  });
23085
23109
  });
@@ -36720,7 +36744,7 @@ class CascaderFoundation extends foundation {
36720
36744
  } else if (!isEmpty_default()(keyEntities)) {
36721
36745
  cacheValue = this._getCacheValue(keyEntities);
36722
36746
  }
36723
- const selectedValue = !this._isControlledComponent() ? cacheValue : value;
36747
+ const selectedValue = !this._isControlledComponent() ? cacheValue : isUndefined_default()(value) ? [] : value;
36724
36748
  if (util_isValid(selectedValue)) {
36725
36749
  this.updateSelectedKey(selectedValue, keyEntities);
36726
36750
  } else {
@@ -36734,10 +36758,7 @@ class CascaderFoundation extends foundation {
36734
36758
  const {
36735
36759
  keyEntities
36736
36760
  } = this.getStates();
36737
- const {
36738
- multiple
36739
- } = this.getProps();
36740
- !multiple && this.updateSelectedKey(value, keyEntities);
36761
+ this.updateSelectedKey(value, keyEntities);
36741
36762
  }
36742
36763
  /**
36743
36764
  * When single selection, the clear objects of
@@ -47756,9 +47777,9 @@ class Cascader extends BaseComponent {
47756
47777
  }, []);
47757
47778
  return formatKeys;
47758
47779
  };
47759
- const needUpdateTreeData = needUpdate('treeData') || needUpdateData();
47760
- const needUpdateValue = needUpdate('value') || isEmpty_default()(prevProps) && defaultValue;
47761
47780
  if (multiple) {
47781
+ const needUpdateTreeData = needUpdate('treeData') || needUpdateData();
47782
+ const needUpdateValue = needUpdate('value') || isEmpty_default()(prevProps) && defaultValue;
47762
47783
  // when value and treedata need updated
47763
47784
  if (needUpdateTreeData || needUpdateValue) {
47764
47785
  // update state.keyEntities
@@ -47806,8 +47827,11 @@ class Cascader extends BaseComponent {
47806
47827
  this.foundation.destroy();
47807
47828
  }
47808
47829
  componentDidUpdate(prevProps) {
47830
+ if (this.props.multiple) {
47831
+ return;
47832
+ }
47809
47833
  let isOptionsChanged = false;
47810
- if (!isEqual_default()(prevProps.treeData, this.props.treeData) && !this.props.multiple) {
47834
+ if (!isEqual_default()(prevProps.treeData, this.props.treeData)) {
47811
47835
  isOptionsChanged = true;
47812
47836
  this.foundation.collectOptions();
47813
47837
  }