Skip to content

Commit acba470

Browse files
Fix number order condition (#627)
1 parent acb7b76 commit acba470

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@terraware/web-components",
3-
"version": "3.1.1",
3+
"version": "3.1.2-rc.0",
44
"author": "Terraformation Inc.",
55
"license": "Apache-2.0",
66
"repository": {

src/components/table/sort.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ test('compare equal string fields', () => {
2828

2929
test('compare unequal number fields with same whole number digits', () => {
3030
const cmp = descendingComparator(rowA, rowB, 'number1', 'desc');
31-
expect(Math.sign(cmp)).toEqual(1);
31+
expect(Math.sign(cmp)).toEqual(-1);
3232
});
3333

3434
test('compare unequal number fields with differing whole number digits', () => {
3535
const cmp = descendingComparator(rowA, rowB, 'number2', 'desc');
36-
expect(Math.sign(cmp)).toEqual(-1);
36+
expect(Math.sign(cmp)).toEqual(1);
3737
});
3838

3939
test('compare equal number fields', () => {

src/components/table/sort.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ export function descendingComparator<T>(a: T, b: T, orderBy: keyof T, order: Sor
22
// first attempt to parse into a numeric value and compare
33
const numCompare = descendingNumComparator(a, b, orderBy);
44
if (numCompare !== null) {
5-
return order === 'desc' ? numCompare : numCompare * -1;
5+
if (numCompare === 0) {
6+
return numCompare;
7+
} else {
8+
return order === 'desc' ? numCompare * -1 : numCompare;
9+
}
610
}
711

812
// if non-numeric, compare using the javascript built-in compare for this type

0 commit comments

Comments
 (0)