Skip to content

Commit

Permalink
Fix sorting of numeric strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswilddev committed Dec 1, 2021
1 parent b24257c commit 62b6db4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const createCreatableSelectChildrenComponent = <
const normalizedFilter = normalize(filter);

const sortedOptions = [...options].sort(({ label: a }, { label: b }) =>
a.localeCompare(b)
a.localeCompare(b, [], { numeric: true })
);

let filteredOptions;
Expand Down
4 changes: 3 additions & 1 deletion components/createOfflineTableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ export const createOfflineTableComponent = <
} else if ((fromB as unknown as boolean) === false) {
comparisonResult = 1;
} else {
comparisonResult = String(fromA).localeCompare(String(fromB));
comparisonResult = String(fromA).localeCompare(String(fromB), [], {
numeric: true,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const createSearchableMultiSelectChildrenComponent = <
const normalizedFilter = normalize(filter);

const sortedOptions = [...options].sort(({ label: a }, { label: b }) =>
a.localeCompare(b)
a.localeCompare(b, [], { numeric: true })
);

let filteredOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const createSearchableSelectChildrenComponent = <
const normalizedFilter = normalize(filter);

const sortedOptions = [...options].sort(({ label: a }, { label: b }) =>
a.localeCompare(b)
a.localeCompare(b, [], { numeric: true })
);

let filteredOptions;
Expand Down

0 comments on commit 62b6db4

Please sign in to comment.