File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change 22 HEADER_PADDING ,
33 MAX_COLUMN_WIDTH ,
44 PIXELS_PER_CHARACTER ,
5- SORT_ICON_PADDING ,
5+ SORT_ICON_TO_CHARACTERS ,
66 getColumnWidth ,
77} from '../getColumnWidth' ;
88
@@ -23,7 +23,7 @@ describe('getColumnWidth', () => {
2323 it ( 'calculates correct width for columns with sorting' , ( ) => {
2424 const result = getColumnWidth ( { data : [ ] , name : 'test' , sortable : true } ) ;
2525 expect ( result ) . toBe (
26- HEADER_PADDING + SORT_ICON_PADDING + 'test' . length * PIXELS_PER_CHARACTER ,
26+ HEADER_PADDING + ( 'test' . length + SORT_ICON_TO_CHARACTERS ) * PIXELS_PER_CHARACTER ,
2727 ) ;
2828 } ) ;
2929 it ( 'calculates correct width for columns with sorting and column name wider than header' , ( ) => {
Original file line number Diff line number Diff line change 11export const MAX_COLUMN_WIDTH = 600 ;
22export const HEADER_PADDING = 20 ;
3- export const SORT_ICON_PADDING = 18 ;
3+ export const SORT_ICON_TO_CHARACTERS = 2 ;
44export const PIXELS_PER_CHARACTER = 10 ;
55
66export function getColumnWidth ( {
@@ -16,7 +16,9 @@ export function getColumnWidth({
1616} ) {
1717 const headerContentLength = typeof header === 'string' ? header . length : name . length ;
1818
19- let maxColumnContentLength = headerContentLength ;
19+ let maxColumnContentLength = sortable
20+ ? headerContentLength + SORT_ICON_TO_CHARACTERS
21+ : headerContentLength ;
2022
2123 if ( data ) {
2224 for ( const row of data ) {
@@ -27,20 +29,14 @@ export function getColumnWidth({
2729
2830 maxColumnContentLength = Math . max ( maxColumnContentLength , cellLength ) ;
2931
30- const sortPadding =
31- sortable && maxColumnContentLength <= headerContentLength ? SORT_ICON_PADDING : 0 ;
32-
3332 if (
34- maxColumnContentLength * PIXELS_PER_CHARACTER + HEADER_PADDING + sortPadding >=
33+ maxColumnContentLength * PIXELS_PER_CHARACTER + HEADER_PADDING >=
3534 MAX_COLUMN_WIDTH
3635 ) {
3736 return MAX_COLUMN_WIDTH ;
3837 }
3938 }
4039 }
4140
42- const sortPadding =
43- sortable && maxColumnContentLength <= headerContentLength ? SORT_ICON_PADDING : 0 ;
44-
45- return maxColumnContentLength * PIXELS_PER_CHARACTER + HEADER_PADDING + sortPadding ;
41+ return maxColumnContentLength * PIXELS_PER_CHARACTER + HEADER_PADDING ;
4642}
You can’t perform that action at this time.
0 commit comments