@@ -57,7 +57,7 @@ const columns: readonly Column<Row>[] = [
5757 }
5858] ;
5959
60- test ( 'cannot not resize or auto resize column when resizable is not specified' , ( ) => {
60+ test ( 'cannot resize or auto resize column when resizable is not specified' , ( ) => {
6161 setup < Row , unknown > ( { columns, rows : [ ] } ) ;
6262 const [ col1 ] = getHeaderCells ( ) ;
6363 expect ( queryResizeHandle ( col1 ) ) . not . toBeInTheDocument ( ) ;
@@ -75,7 +75,7 @@ test('should resize column when dragging the handle', async () => {
7575 expect ( onColumnResize ) . toHaveBeenCalledExactlyOnceWith ( expect . objectContaining ( columns [ 1 ] ) , 150 ) ;
7676} ) ;
7777
78- test ( 'should use the maxWidth if specified' , async ( ) => {
78+ test ( 'should use the maxWidth if specified when dragging the handle ' , async ( ) => {
7979 setup < Row , unknown > ( { columns, rows : [ ] } ) ;
8080 const grid = getGrid ( ) ;
8181 await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px ' } ) ;
@@ -84,7 +84,7 @@ test('should use the maxWidth if specified', async () => {
8484 await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 400px' } ) ;
8585} ) ;
8686
87- test ( 'should use the minWidth if specified' , async ( ) => {
87+ test ( 'should use the minWidth if specified when dragging the handle ' , async ( ) => {
8888 setup < Row , unknown > ( { columns, rows : [ ] } ) ;
8989 const grid = getGrid ( ) ;
9090 await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px' } ) ;
@@ -93,6 +93,49 @@ test('should use the minWidth if specified', async () => {
9393 await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 100px' } ) ;
9494} ) ;
9595
96+ test ( 'should resize column using keboard' , async ( ) => {
97+ const onColumnResize = vi . fn ( ) ;
98+ setup < Row , unknown > ( { columns, rows : [ ] , onColumnResize } ) ;
99+ const grid = getGrid ( ) ;
100+ expect ( onColumnResize ) . not . toHaveBeenCalled ( ) ;
101+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px' } ) ;
102+ const [ , col2 ] = getHeaderCells ( ) ;
103+ await userEvent . click ( col2 ) ;
104+
105+ await userEvent . keyboard ( '{Control>}{ArrowRight}{/Control}' ) ;
106+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 210px' } ) ;
107+ expect ( onColumnResize ) . toHaveBeenCalledWith ( expect . objectContaining ( columns [ 1 ] ) , 210 ) ;
108+
109+ await userEvent . keyboard ( '{Control>}{ArrowLeft}{/Control}' ) ;
110+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px' } ) ;
111+ expect ( onColumnResize ) . toHaveBeenCalledWith ( expect . objectContaining ( columns [ 1 ] ) , 200 ) ;
112+ expect ( onColumnResize ) . toHaveBeenCalledTimes ( 2 ) ;
113+ } ) ;
114+
115+ test ( 'should use the maxWidth if specified when resizing using keyboard' , async ( ) => {
116+ const onColumnResize = vi . fn ( ) ;
117+ setup < Row , unknown > ( { columns, rows : [ ] , onColumnResize } ) ;
118+ const grid = getGrid ( ) ;
119+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px ' } ) ;
120+ const [ , col2 ] = getHeaderCells ( ) ;
121+ await userEvent . click ( col2 ) ;
122+ await userEvent . keyboard ( `{Control>}${ '{ArrowRight}' . repeat ( 22 ) } {/Control}` ) ;
123+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 400px' } ) ;
124+ expect ( onColumnResize ) . toHaveBeenCalledTimes ( 20 ) ;
125+ } ) ;
126+
127+ test ( 'should use the minWidth if specified resizing using keyboard' , async ( ) => {
128+ const onColumnResize = vi . fn ( ) ;
129+ setup < Row , unknown > ( { columns, rows : [ ] , onColumnResize } ) ;
130+ const grid = getGrid ( ) ;
131+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px' } ) ;
132+ const [ , col2 ] = getHeaderCells ( ) ;
133+ await userEvent . click ( col2 ) ;
134+ await userEvent . keyboard ( `{Control>}${ '{ArrowLeft}' . repeat ( 12 ) } {/Control}` ) ;
135+ await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 100px' } ) ;
136+ expect ( onColumnResize ) . toHaveBeenCalledTimes ( 10 ) ;
137+ } ) ;
138+
96139test ( 'should auto resize column when resize handle is double clicked' , async ( ) => {
97140 const onColumnResize = vi . fn ( ) ;
98141 setup < Row , unknown > ( {
0 commit comments