Commit a3c3764 1 parent 06cf768 commit a3c3764 Copy full SHA for a3c3764
File tree 4 files changed +53
-5
lines changed
4 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,12 @@ function HeaderCell<Entry>({
146
146
className = { style . sortableButton }
147
147
>
148
148
{ column . header }
149
+ { Boolean ( column . sorter ) && (
150
+ < span
151
+ data-cy = "sortIcon"
152
+ className = { cx ( style . sortable ( order ) , "sortIcon" ) }
153
+ />
154
+ ) }
149
155
</ ResetButton >
150
156
) : (
151
157
column . header
@@ -155,7 +161,7 @@ function HeaderCell<Entry>({
155
161
< div
156
162
className = { cx ( style . headerCell ( column . textAlign ) , {
157
163
[ style . makeSpaceForSortIndicator ] : Boolean ( column . sorter ) ,
158
- [ style . sortable ( order ) ] : Boolean ( column . sorter ) ,
164
+ [ style . headerHover ] : Boolean ( column . sorter ) ,
159
165
[ style . rowScrollShadow ] : showScrollShadow
160
166
} ) }
161
167
id = { id }
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ exports[`Table v2 rendering renders default 1`] = `
12
12
>
13
13
<div
14
14
aria-sort = " none"
15
- class = " css-1kf7gto "
15
+ class = " css-1il2bhb "
16
16
id = " name"
17
17
role = " columnheader"
18
18
>
@@ -27,6 +27,10 @@ exports[`Table v2 rendering renders default 1`] = `
27
27
<div >
28
28
Name
29
29
</div >
30
+ <span
31
+ class = " css-123nj8f sortIcon"
32
+ data-cy = " sortIcon"
33
+ />
30
34
</div >
31
35
</button >
32
36
<div
@@ -966,7 +970,7 @@ exports[`Table v2 rendering renders without a sticky first column 1`] = `
966
970
>
967
971
<div
968
972
aria-sort = " none"
969
- class = " css-kzvdt0 "
973
+ class = " css-1me0nmx "
970
974
id = " name"
971
975
role = " columnheader"
972
976
>
@@ -981,6 +985,10 @@ exports[`Table v2 rendering renders without a sticky first column 1`] = `
981
985
<div >
982
986
Name
983
987
</div >
988
+ <span
989
+ class = " css-123nj8f sortIcon"
990
+ data-cy = " sortIcon"
991
+ />
984
992
</div >
985
993
</button >
986
994
<div
Original file line number Diff line number Diff line change @@ -79,9 +79,14 @@ export const sortable = (dir: "asc" | "desc" | null) => css`
79
79
"currentColor"
80
80
) } ;
81
81
}
82
+ ` ;
83
+
84
+ export const headerHover = css `
82
85
& : hover {
83
- & : after {
84
- display : inline-block;
86
+ .sortIcon {
87
+ : after {
88
+ display : inline-block;
89
+ }
85
90
}
86
91
}
87
92
` ;
Original file line number Diff line number Diff line change @@ -265,6 +265,35 @@ describe("Table v2", () => {
265
265
266
266
expect ( sorterFn ) . toHaveBeenCalledWith ( "desc" , - 1 ) ;
267
267
} ) ;
268
+ it ( "calls the function passed to the 'sorter' prop when clicking the arrow besides heading" , ( ) => {
269
+ const sorterFn = jest . fn ( ) ;
270
+ const { getByTestId } = render (
271
+ < Table
272
+ data = { mockData }
273
+ toId = { el => el . id . toString ( ) }
274
+ columns = { [
275
+ {
276
+ id : "name" ,
277
+ header : < div > Name</ div > ,
278
+ textAlign : "left" ,
279
+ render : x => (
280
+ < a href = { `http://google.com/?q=${ encodeURIComponent ( x . name ) } ` } >
281
+ { x . name }
282
+ </ a >
283
+ ) ,
284
+ initialWidth : "300px" ,
285
+ sorter : sorterFn
286
+ }
287
+ ] }
288
+ initialSorter = { { by : "name" , order : "asc" } }
289
+ />
290
+ ) ;
291
+
292
+ expect ( sorterFn ) . toHaveBeenCalledWith ( "asc" , 1 ) ;
293
+ const sortIcon = getByTestId ( "sortIcon" ) ;
294
+ sortIcon . click ( ) ;
295
+ expect ( sorterFn ) . toHaveBeenLastCalledWith ( "desc" , - 1 ) ;
296
+ } ) ;
268
297
it ( "sorts strings with Sorter.string" , ( ) => {
269
298
const nameSort = Sorter . string ( "name" ) ;
270
299
const ascSort = nameSort ( "asc" , - 1 ) ;
You can’t perform that action at this time.
0 commit comments