File tree 1 file changed +12
-2
lines changed
packages/shared-components/src/util/list
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { SortState } from '@navikt/ds-react' ;
2
+ import htmlUtils from '../html/htmlUtils' ;
2
3
3
4
type SortDirection = SortState [ 'direction' ] ;
4
5
6
+ const normalizeString = ( value : string | undefined ) => {
7
+ const textValue = `${ value ?? '' } ` ;
8
+
9
+ if ( htmlUtils . isHtmlString ( textValue ) ) {
10
+ return htmlUtils . extractTextContent ( textValue ) . trim ( ) ;
11
+ }
12
+ return textValue . trim ( ) ;
13
+ } ;
14
+
5
15
const getLocaleComparator =
6
16
( property ?: string , direction ?: SortDirection , reverseDefault : boolean = false ) =>
7
17
( a , b ) => {
8
18
if ( ! property || ! direction ) {
9
19
return reverseDefault ? - 1 : 1 ;
10
20
}
11
- const valueA = ` ${ a [ property ] ?? '' } ` . trim ( ) ;
12
- const valueB = ` ${ b [ property ] ?? '' } ` . trim ( ) ;
21
+ const valueA = normalizeString ( a [ property ] ) ;
22
+ const valueB = normalizeString ( b [ property ] ) ;
13
23
14
24
if ( direction === 'ascending' ) {
15
25
return valueA . localeCompare ( valueB , 'nb-NO' ) ;
You can’t perform that action at this time.
0 commit comments