From 62b6db4d1fde13fd65af8cecd20b0b1f131084ab Mon Sep 17 00:00:00 2001 From: jameswilddev Date: Wed, 1 Dec 2021 08:54:52 +0000 Subject: [PATCH] Fix sorting of numeric strings. --- .../createCreatableSelectChildrenComponent/index.tsx | 2 +- components/createOfflineTableComponent/index.tsx | 4 +++- .../createSearchableMultiSelectChildrenComponent/index.tsx | 2 +- .../createSearchableSelectChildrenComponent/index.tsx | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/createCreatableSelectComponent/createCreatableSelectChildrenComponent/index.tsx b/components/createCreatableSelectComponent/createCreatableSelectChildrenComponent/index.tsx index d83461de..033e202d 100644 --- a/components/createCreatableSelectComponent/createCreatableSelectChildrenComponent/index.tsx +++ b/components/createCreatableSelectComponent/createCreatableSelectChildrenComponent/index.tsx @@ -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; diff --git a/components/createOfflineTableComponent/index.tsx b/components/createOfflineTableComponent/index.tsx index f6206de1..a7568b05 100644 --- a/components/createOfflineTableComponent/index.tsx +++ b/components/createOfflineTableComponent/index.tsx @@ -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, + }); } } diff --git a/components/createSearchableMultiSelectComponent/createSearchableMultiSelectChildrenComponent/index.tsx b/components/createSearchableMultiSelectComponent/createSearchableMultiSelectChildrenComponent/index.tsx index 0f71d1c2..6ba6d992 100644 --- a/components/createSearchableMultiSelectComponent/createSearchableMultiSelectChildrenComponent/index.tsx +++ b/components/createSearchableMultiSelectComponent/createSearchableMultiSelectChildrenComponent/index.tsx @@ -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; diff --git a/components/createSearchableSelectComponent/createSearchableSelectChildrenComponent/index.tsx b/components/createSearchableSelectComponent/createSearchableSelectChildrenComponent/index.tsx index 35a53270..f083fd61 100644 --- a/components/createSearchableSelectComponent/createSearchableSelectChildrenComponent/index.tsx +++ b/components/createSearchableSelectComponent/createSearchableSelectChildrenComponent/index.tsx @@ -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;