@@ -35,8 +35,8 @@ describe('Table.resizable', () => {
35
35
const [ widthMap , setWidthMap ] = React . useState ( new Map ( ) ) ;
36
36
37
37
const columns = [
38
- { key : 'a' , dataIndex : 'a' , width : 100 } ,
39
- { key : 'b' , dataIndex : 'b' , width : 100 } ,
38
+ { key : 'a' , dataIndex : 'a' , width : 400 } ,
39
+ { key : 'b' , dataIndex : 'b' , width : 400 } ,
40
40
] . map ( col => ( { ...col , width : widthMap . get ( col . key ?? col . dataIndex ) || col . width } ) ) ;
41
41
42
42
return (
@@ -69,11 +69,11 @@ describe('Table.resizable', () => {
69
69
await triggerResize ( [
70
70
{
71
71
data : wrapper . find ( 'ResizeObserver' ) . at ( 1 ) . props ( ) . data ,
72
- size : { width : 100 , offsetWidth : 100 } ,
72
+ size : { width : 400 , offsetWidth : 400 } ,
73
73
} ,
74
74
{
75
75
data : wrapper . find ( 'ResizeObserver' ) . at ( 2 ) . props ( ) . data ,
76
- size : { width : 100 , offsetWidth : 100 } ,
76
+ size : { width : 400 , offsetWidth : 400 } ,
77
77
} ,
78
78
] ) ;
79
79
@@ -99,15 +99,15 @@ describe('Table.resizable', () => {
99
99
100
100
expect ( onColumnResizeComplete ) . toHaveBeenCalledWith ( {
101
101
columnKey : 'a' ,
102
- width : 200 ,
102
+ width : 500 ,
103
103
columnKeyWidths : [
104
- { columnKey : 'a' , width : 200 } ,
105
- { columnKey : 'b' , width : 100 } ,
104
+ { columnKey : 'a' , width : 500 } ,
105
+ { columnKey : 'b' , width : 400 } ,
106
106
] ,
107
107
} ) ;
108
108
109
- expect ( wrapper . find ( 'colgroup col' ) . at ( 0 ) . props ( ) . style . width ) . toBe ( 200 ) ;
110
- expect ( wrapper . find ( 'colgroup col' ) . at ( 1 ) . props ( ) . style . width ) . toBe ( 100 ) ;
109
+ expect ( wrapper . find ( 'colgroup col' ) . at ( 0 ) . props ( ) . style . width ) . toBe ( 500 ) ;
110
+ expect ( wrapper . find ( 'colgroup col' ) . at ( 1 ) . props ( ) . style . width ) . toBe ( 400 ) ;
111
111
} ) ;
112
112
113
113
it ( 'columns total width < componentWidth' , async ( ) => {
@@ -194,4 +194,86 @@ describe('Table.resizable', () => {
194
194
expect ( wrapper . find ( 'colgroup col' ) . at ( 0 ) . props ( ) . style . width ) . toBe ( 300 ) ;
195
195
expect ( wrapper . find ( 'colgroup col' ) . at ( 1 ) . props ( ) . style . width ) . toBe ( 500 ) ;
196
196
} ) ;
197
+
198
+ it ( 'minWidth should be worked' , async ( ) => {
199
+ const onColumnResizeComplete = vi . fn ( ) ;
200
+
201
+ const App = ( ) => {
202
+ const [ widthMap , setWidthMap ] = React . useState ( new Map ( ) ) ;
203
+
204
+ const columns = [
205
+ { key : 'a' , dataIndex : 'a' , width : 800 , resizable : { minWidth : 400 } } ,
206
+ { key : 'b' , dataIndex : 'b' , width : 800 } ,
207
+ ] . map ( col => ( { ...col , width : widthMap . get ( col . key ?? col . dataIndex ) || col . width } ) ) ;
208
+
209
+ return (
210
+ < Table
211
+ columnResizable
212
+ data = { [ { a : '123' , b : '123' , key : '1' } ] }
213
+ columns = { columns }
214
+ scroll = { { x : columns . reduce ( ( t , c ) => t + c . width , 0 ) } }
215
+ onColumnResizeComplete = { info => {
216
+ setWidthMap ( prev => {
217
+ const result = new Map ( prev ) ;
218
+ info . columnKeyWidths . forEach ( i => {
219
+ result . set ( i . columnKey , i . width ) ;
220
+ } ) ;
221
+ return result ;
222
+ } ) ;
223
+ onColumnResizeComplete ( info ) ;
224
+ } }
225
+ />
226
+ ) ;
227
+ } ;
228
+ const wrapper = mount ( < App /> ) ;
229
+
230
+ async function triggerResize ( resizeList ) {
231
+ wrapper . find ( RcResizeObserver . Collection ) . first ( ) . props ( ) . onBatchResize ( resizeList ) ;
232
+ await safeAct ( wrapper ) ;
233
+ wrapper . update ( ) ;
234
+ }
235
+
236
+ await triggerResize ( [
237
+ {
238
+ data : wrapper . find ( 'ResizeObserver' ) . at ( 1 ) . props ( ) . data ,
239
+ size : { width : 800 , offsetWidth : 800 } ,
240
+ } ,
241
+ {
242
+ data : wrapper . find ( 'ResizeObserver' ) . at ( 2 ) . props ( ) . data ,
243
+ size : { width : 800 , offsetWidth : 800 } ,
244
+ } ,
245
+ ] ) ;
246
+
247
+ wrapper . find ( '.rc-table-cell-resize-handle' ) . first ( ) . simulate ( 'mousedown' , { pageX : 0 } ) ;
248
+
249
+ const mousemoveEvent = new Event ( 'mousemove' ) ;
250
+ mousemoveEvent . pageX = - 1000 ;
251
+
252
+ await act ( async ( ) => {
253
+ document . body . dispatchEvent ( mousemoveEvent ) ;
254
+ await Promise . resolve ( ) ;
255
+ wrapper . update ( ) ;
256
+ } ) ;
257
+
258
+ const mouseupEvent = new Event ( 'mouseup' ) ;
259
+ mouseupEvent . pageX = - 1000 ;
260
+
261
+ await act ( async ( ) => {
262
+ document . body . dispatchEvent ( mouseupEvent ) ;
263
+ await Promise . resolve ( ) ;
264
+ wrapper . update ( ) ;
265
+ } ) ;
266
+
267
+ expect ( onColumnResizeComplete ) . toHaveBeenCalledWith ( {
268
+ columnKey : 'a' ,
269
+ width : 400 ,
270
+ columnKeyWidths : [
271
+ { columnKey : 'a' , width : 400 } ,
272
+ { columnKey : 'b' , width : 800 } ,
273
+ ] ,
274
+ } ) ;
275
+
276
+ expect ( wrapper . find ( 'colgroup col' ) . at ( 0 ) . props ( ) . style . width ) . toBe ( 400 ) ;
277
+ expect ( wrapper . find ( 'colgroup col' ) . at ( 1 ) . props ( ) . style . width ) . toBe ( 800 ) ;
278
+ } ) ;
197
279
} ) ;
0 commit comments