@@ -35,8 +35,8 @@ describe('Table.resizable', () => {
3535 const [ widthMap , setWidthMap ] = React . useState ( new Map ( ) ) ;
3636
3737 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 } ,
4040 ] . map ( col => ( { ...col , width : widthMap . get ( col . key ?? col . dataIndex ) || col . width } ) ) ;
4141
4242 return (
@@ -69,11 +69,11 @@ describe('Table.resizable', () => {
6969 await triggerResize ( [
7070 {
7171 data : wrapper . find ( 'ResizeObserver' ) . at ( 1 ) . props ( ) . data ,
72- size : { width : 100 , offsetWidth : 100 } ,
72+ size : { width : 400 , offsetWidth : 400 } ,
7373 } ,
7474 {
7575 data : wrapper . find ( 'ResizeObserver' ) . at ( 2 ) . props ( ) . data ,
76- size : { width : 100 , offsetWidth : 100 } ,
76+ size : { width : 400 , offsetWidth : 400 } ,
7777 } ,
7878 ] ) ;
7979
@@ -99,15 +99,15 @@ describe('Table.resizable', () => {
9999
100100 expect ( onColumnResizeComplete ) . toHaveBeenCalledWith ( {
101101 columnKey : 'a' ,
102- width : 200 ,
102+ width : 500 ,
103103 columnKeyWidths : [
104- { columnKey : 'a' , width : 200 } ,
105- { columnKey : 'b' , width : 100 } ,
104+ { columnKey : 'a' , width : 500 } ,
105+ { columnKey : 'b' , width : 400 } ,
106106 ] ,
107107 } ) ;
108108
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 ) ;
111111 } ) ;
112112
113113 it ( 'columns total width < componentWidth' , async ( ) => {
@@ -194,4 +194,86 @@ describe('Table.resizable', () => {
194194 expect ( wrapper . find ( 'colgroup col' ) . at ( 0 ) . props ( ) . style . width ) . toBe ( 300 ) ;
195195 expect ( wrapper . find ( 'colgroup col' ) . at ( 1 ) . props ( ) . style . width ) . toBe ( 500 ) ;
196196 } ) ;
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+ } ) ;
197279} ) ;
0 commit comments