File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ function TableHeaderCell({
4848 isSortedDesc = false ,
4949 headerClassName,
5050} : TableHeaderCellProps ) {
51- const headerProps = getHeaderProps ( ) ;
51+ const { key , ... headerProps } = getHeaderProps ( ) ;
5252 const toggleProps = canSort && getSortByToggleProps ? getSortByToggleProps ( ) : { } ;
5353 // Per WAI-ARIA APG sortable table guidance, only the actively sorted header should expose aria-sort.
5454 let ariaSort : React . AriaAttributes [ 'aria-sort' ] ;
@@ -59,6 +59,7 @@ function TableHeaderCell({
5959
6060 return (
6161 < th
62+ key = { key }
6263 { ...headerProps }
6364 scope = "col"
6465 aria-sort = { ariaSort }
@@ -73,12 +74,13 @@ function TableHeaderCell({
7374 type = "button"
7475 className = { classNames (
7576 'pgn__data-table-sort-button' ,
76- headerContentClassName ,
7777 toggleProps . className ,
7878 ) }
7979 >
80- < span > { render ( 'Header' ) } </ span >
81- < SortIndicator isSorted = { isSorted } isSortedDesc = { isSortedDesc || false } />
80+ < span className = { headerContentClassName } >
81+ < span > { render ( 'Header' ) } </ span >
82+ < SortIndicator isSorted = { isSorted } isSortedDesc = { isSortedDesc || false } />
83+ </ span >
8284 </ button >
8385 ) : (
8486 < span className = { headerContentClassName } >
Original file line number Diff line number Diff line change @@ -90,6 +90,13 @@ describe('<TableHeaderCell />', () => {
9090 expect ( button ) . toHaveClass ( 'pgn__data-table-sort-button' ) ;
9191 } ) ;
9292
93+ it ( 'adds headerClassName to sortable header content' , ( ) => {
94+ render ( < FakeTable { ...props } canSort /> ) ;
95+ const button = screen . getByRole ( 'button' , { name : 'Title' } ) ;
96+ expect ( button ) . not . toHaveClass ( props . headerClassName ) ;
97+ expect ( button . firstChild ) . toHaveClass ( props . headerClassName ) ;
98+ } ) ;
99+
93100 it ( 'adds ascending sort state to the header cell when sorted ascending' , ( ) => {
94101 render ( < FakeTable { ...props } canSort isSorted /> ) ;
95102 const cell = screen . getByRole ( 'columnheader' ) ;
You can’t perform that action at this time.
0 commit comments