carbon-design-system / carbon-components-svelte

Svelte implementation of the Carbon Design System
https://svelte.carbondesignsystem.com
Apache License 2.0
2.68k stars 261 forks source link

DataTable sort function return type is restricted to -1, 0 or 1 #1934

Closed berndfuhrmann closed 6 months ago

berndfuhrmann commented 6 months ago

The expected return type for sorting rows in a DataTable is currently: https://github.com/carbon-design-system/carbon-components-svelte/blob/21b1d78d8ebda608d78c1ab22833c36138f9ef3c/types/DataTable/DataTable.svelte.d.ts#L12

This restriction isn't used in DataTable.svelte and it wouldn't be a problem to use number as return type instead.

Doing so would give consumers of this library an easier way to write comparison functions, for example when sorting by Date: You could then write something like: (a:Date, b:Date) => a.getTime() - b.getTime() instead of having to write Math.max(Math.min(a.getTime()-b.getTime(), 1), -1). This would also improve performance slightly.

metonym commented 6 months ago

Agreed – the return type should be a primitive, not an enum.

metonym commented 6 months ago

Fixed in v0.84.1