@hi-ui/table 4.12.2 → 4.12.3

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,11 @@
1
1
  # @hi-ui/table
2
2
 
3
+ ## 4.12.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3426](https://github.com/XiaoMi/hiui/pull/3426) [`a8cc00c`](https://github.com/XiaoMi/hiui/commit/a8cc00cc9c5591309049c25a458ffcd41e292eba) Thanks [@zyprepare](https://github.com/zyprepare)! - fix(table): 修复设置 minWidth 无效的问题 (#3425)
8
+
3
9
  ## 4.12.2
4
10
 
5
11
  ### Patch Changes
@@ -126,7 +126,7 @@ var useColWidth = function useColWidth(_ref) {
126
126
  if (virtual) {
127
127
  setColWidths(getVirtualWidths());
128
128
  } else {
129
- // 当第一行有内容时并且没有重新设置列宽时,在去设置列宽
129
+ // 当第一行有内容时并且没有重新设置列宽时,再去设置列宽
130
130
  // Warning hasResetWidths.current 作用是防止某些浏览器下,下面逻辑死循环
131
131
  if ((measureRowElement === null || measureRowElement === void 0 ? void 0 : measureRowElement.childNodes) && hasResetWidths.current === false) {
132
132
  hasResetWidths.current = true;
@@ -145,7 +145,7 @@ var useColWidth = function useColWidth(_ref) {
145
145
  headerTableElement = _React$useState2[0],
146
146
  setHeaderTableElement = _React$useState2[1];
147
147
  // 控制列最小可调整宽度
148
- var _React$useState3 = React__default["default"].useState([]),
148
+ var _React$useState3 = React__default["default"].useState(index.getGroupItemWidth(columns).minColWidths),
149
149
  minColWidths = _React$useState3[0],
150
150
  setMinColWidths = _React$useState3[1];
151
151
  // 当列变化时同步更新 minColWidths
@@ -153,17 +153,16 @@ var useColWidth = function useColWidth(_ref) {
153
153
  var resizeObserver;
154
154
  if (headerTableElement) {
155
155
  resizeObserver = new ResizeObserver(function () {
156
- var resizableHandlerWidth = 4;
157
156
  var calcMinColWidths = Array.from(headerTableElement.childNodes).map(function (th, index$1) {
158
157
  var minColWidth = index.getGroupItemWidth(columns).minColWidths[index$1];
158
+ // 如果设置了最小宽度,则直接使用最小宽度,否则使用标题宽度
159
+ if (minColWidth !== undefined && minColWidth !== 0) {
160
+ return minColWidth;
161
+ }
159
162
  var thPaddingLeft = parseFloat(window.getComputedStyle(th).getPropertyValue('padding-left'));
160
- var childNodes = Array.from(th.childNodes);
161
- var childNodesWidth = childNodes.map(function (child) {
162
- return child.offsetWidth;
163
- }).reduce(function (prev, next) {
164
- return prev + next;
165
- }, 0) + thPaddingLeft * 2 + resizableHandlerWidth;
166
- return childNodesWidth > minColWidth ? minColWidth : childNodesWidth;
163
+ var childNode = Array.from(th.childNodes)[0];
164
+ var childNodeWidth = childNode.offsetWidth + thPaddingLeft * 2;
165
+ return childNodeWidth || 40;
167
166
  });
168
167
  setMinColWidths(calcMinColWidths);
169
168
  });
@@ -220,15 +219,15 @@ var useColWidth = function useColWidth(_ref) {
220
219
  }, [minColWidths, tableWidthAdjustOnResize]);
221
220
  var getColgroupProps = React__default["default"].useCallback(function (column, index) {
222
221
  var width = colWidths[index] || undefined;
223
- var minWidth = minColWidths[index] || undefined;
222
+ // const minWidth = minColWidths[index] || undefined
224
223
  return {
225
224
  style: {
226
- width: width,
227
- minWidth: minWidth || width
225
+ width: width
226
+ // minWidth: minWidth || width,
228
227
  }
229
228
  // 'data-hover-highlight': setAttrStatus(isHoveredCol(column.dataKey)),
230
229
  };
231
- }, [colWidths, minColWidths]);
230
+ }, [colWidths]);
232
231
  return {
233
232
  measureRowElementRef: measureRowElementRef,
234
233
  onColumnResizable: onColumnResizable,
@@ -79,8 +79,8 @@ var getGroupItemWidth = function getGroupItemWidth(columns) {
79
79
  }
80
80
  // 如果没有设置列宽度,css 宽度默认是 `auto`,这里对于非数字 width 均设置为 0
81
81
  var colWidth = typeAssertion.isNumeric(width) ? Number(width) : 0;
82
- var minColWidth = typeAssertion.isNumeric(minWidth) ? Number(minWidth) : colWidth || 60;
83
- colWidths.push(colWidth < minColWidth ? minColWidth : colWidth);
82
+ var minColWidth = typeAssertion.isNumeric(minWidth) ? Number(minWidth) : 0;
83
+ colWidths.push(colWidth);
84
84
  minColWidths.push(minColWidth);
85
85
  });
86
86
  };
@@ -114,7 +114,7 @@ var useColWidth = function useColWidth(_ref) {
114
114
  if (virtual) {
115
115
  setColWidths(getVirtualWidths());
116
116
  } else {
117
- // 当第一行有内容时并且没有重新设置列宽时,在去设置列宽
117
+ // 当第一行有内容时并且没有重新设置列宽时,再去设置列宽
118
118
  // Warning hasResetWidths.current 作用是防止某些浏览器下,下面逻辑死循环
119
119
  if ((measureRowElement === null || measureRowElement === void 0 ? void 0 : measureRowElement.childNodes) && hasResetWidths.current === false) {
120
120
  hasResetWidths.current = true;
@@ -133,7 +133,7 @@ var useColWidth = function useColWidth(_ref) {
133
133
  headerTableElement = _React$useState2[0],
134
134
  setHeaderTableElement = _React$useState2[1];
135
135
  // 控制列最小可调整宽度
136
- var _React$useState3 = React__default.useState([]),
136
+ var _React$useState3 = React__default.useState(getGroupItemWidth(columns).minColWidths),
137
137
  minColWidths = _React$useState3[0],
138
138
  setMinColWidths = _React$useState3[1];
139
139
  // 当列变化时同步更新 minColWidths
@@ -141,17 +141,16 @@ var useColWidth = function useColWidth(_ref) {
141
141
  var resizeObserver;
142
142
  if (headerTableElement) {
143
143
  resizeObserver = new ResizeObserver(function () {
144
- var resizableHandlerWidth = 4;
145
144
  var calcMinColWidths = Array.from(headerTableElement.childNodes).map(function (th, index) {
146
145
  var minColWidth = getGroupItemWidth(columns).minColWidths[index];
146
+ // 如果设置了最小宽度,则直接使用最小宽度,否则使用标题宽度
147
+ if (minColWidth !== undefined && minColWidth !== 0) {
148
+ return minColWidth;
149
+ }
147
150
  var thPaddingLeft = parseFloat(window.getComputedStyle(th).getPropertyValue('padding-left'));
148
- var childNodes = Array.from(th.childNodes);
149
- var childNodesWidth = childNodes.map(function (child) {
150
- return child.offsetWidth;
151
- }).reduce(function (prev, next) {
152
- return prev + next;
153
- }, 0) + thPaddingLeft * 2 + resizableHandlerWidth;
154
- return childNodesWidth > minColWidth ? minColWidth : childNodesWidth;
151
+ var childNode = Array.from(th.childNodes)[0];
152
+ var childNodeWidth = childNode.offsetWidth + thPaddingLeft * 2;
153
+ return childNodeWidth || 40;
155
154
  });
156
155
  setMinColWidths(calcMinColWidths);
157
156
  });
@@ -208,15 +207,15 @@ var useColWidth = function useColWidth(_ref) {
208
207
  }, [minColWidths, tableWidthAdjustOnResize]);
209
208
  var getColgroupProps = React__default.useCallback(function (column, index) {
210
209
  var width = colWidths[index] || undefined;
211
- var minWidth = minColWidths[index] || undefined;
210
+ // const minWidth = minColWidths[index] || undefined
212
211
  return {
213
212
  style: {
214
- width: width,
215
- minWidth: minWidth || width
213
+ width: width
214
+ // minWidth: minWidth || width,
216
215
  }
217
216
  // 'data-hover-highlight': setAttrStatus(isHoveredCol(column.dataKey)),
218
217
  };
219
- }, [colWidths, minColWidths]);
218
+ }, [colWidths]);
220
219
  return {
221
220
  measureRowElementRef: measureRowElementRef,
222
221
  onColumnResizable: onColumnResizable,
@@ -74,8 +74,8 @@ var getGroupItemWidth = function getGroupItemWidth(columns) {
74
74
  }
75
75
  // 如果没有设置列宽度,css 宽度默认是 `auto`,这里对于非数字 width 均设置为 0
76
76
  var colWidth = isNumeric(width) ? Number(width) : 0;
77
- var minColWidth = isNumeric(minWidth) ? Number(minWidth) : colWidth || 60;
78
- colWidths.push(colWidth < minColWidth ? minColWidth : colWidth);
77
+ var minColWidth = isNumeric(minWidth) ? Number(minWidth) : 0;
78
+ colWidths.push(colWidth);
79
79
  minColWidths.push(minColWidth);
80
80
  });
81
81
  };
@@ -5,7 +5,6 @@ export declare const TableProvider: import("react").Provider<(Omit<{
5
5
  getColgroupProps: (column: import("./types").FlattedTableColumnItemData, index: number) => {
6
6
  style: {
7
7
  width: number | undefined;
8
- minWidth: number | undefined;
9
8
  };
10
9
  };
11
10
  getStickyColProps: (column: any) => {
@@ -137,7 +136,6 @@ export declare const useTableContext: () => Omit<{
137
136
  getColgroupProps: (column: import("./types").FlattedTableColumnItemData, index: number) => {
138
137
  style: {
139
138
  width: number | undefined;
140
- minWidth: number | undefined;
141
139
  };
142
140
  };
143
141
  getStickyColProps: (column: any) => {
@@ -12,7 +12,6 @@ export declare const useColWidth: ({ resizable, tableWidthAdjustOnResize, data,
12
12
  getColgroupProps: (column: FlattedTableColumnItemData, index: number) => {
13
13
  style: {
14
14
  width: number | undefined;
15
- minWidth: number | undefined;
16
15
  };
17
16
  };
18
17
  setHeaderTableElement: React.Dispatch<React.SetStateAction<HTMLTableRowElement | null>>;
@@ -7,7 +7,6 @@ export declare const useTable: ({ data, columns: columnsProp, defaultFixedToColu
7
7
  getColgroupProps: (column: FlattedTableColumnItemData, index: number) => {
8
8
  style: {
9
9
  width: number | undefined;
10
- minWidth: number | undefined;
11
10
  };
12
11
  };
13
12
  getStickyColProps: (column: any) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/table",
3
- "version": "4.12.2",
3
+ "version": "4.12.3",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",