@@ -57,7 +57,7 @@ const columns: readonly Column<Row>[] = [
57
57
}
58
58
] ;
59
59
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' , ( ) => {
61
61
setup < Row , unknown > ( { columns, rows : [ ] } ) ;
62
62
const [ col1 ] = getHeaderCells ( ) ;
63
63
expect ( queryResizeHandle ( col1 ) ) . not . toBeInTheDocument ( ) ;
@@ -75,7 +75,7 @@ test('should resize column when dragging the handle', async () => {
75
75
expect ( onColumnResize ) . toHaveBeenCalledExactlyOnceWith ( expect . objectContaining ( columns [ 1 ] ) , 150 ) ;
76
76
} ) ;
77
77
78
- test ( 'should use the maxWidth if specified' , async ( ) => {
78
+ test ( 'should use the maxWidth if specified when dragging the handle ' , async ( ) => {
79
79
setup < Row , unknown > ( { columns, rows : [ ] } ) ;
80
80
const grid = getGrid ( ) ;
81
81
await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px ' } ) ;
@@ -84,7 +84,7 @@ test('should use the maxWidth if specified', async () => {
84
84
await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 400px' } ) ;
85
85
} ) ;
86
86
87
- test ( 'should use the minWidth if specified' , async ( ) => {
87
+ test ( 'should use the minWidth if specified when dragging the handle ' , async ( ) => {
88
88
setup < Row , unknown > ( { columns, rows : [ ] } ) ;
89
89
const grid = getGrid ( ) ;
90
90
await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 200px' } ) ;
@@ -93,6 +93,49 @@ test('should use the minWidth if specified', async () => {
93
93
await expect . element ( grid ) . toHaveStyle ( { gridTemplateColumns : '100px 100px' } ) ;
94
94
} ) ;
95
95
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
+
96
139
test ( 'should auto resize column when resize handle is double clicked' , async ( ) => {
97
140
const onColumnResize = vi . fn ( ) ;
98
141
setup < Row , unknown > ( {
0 commit comments