-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SortableList - Pass from and to indexes of changed item #3153
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, added a small comment
@@ -16,8 +16,8 @@ | |||
}, | |||
{ | |||
"name": "onOrderChange", | |||
"type": "(data: ItemT[]) => void", | |||
"description": "A callback to get the new order (or swapped items).", | |||
"type": "(data: ItemT[], from: number, to: number) => void", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider wrapping from
and to
in an object, just in case we'll have to pass more info in the future, we don't want to have lots of arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have wanted to combine all the arguments to one object (like they do in RN draggable) but that would create a migration. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it would require a migration and also combining all not necessarily the right solution
I personally like to have a main argument (the data) separated from the extra arguments that do grouped as an object
anyway there's no right or wrong, but we don't want to go into a migration just for that, so I think we can settle an adding the new info/data as an object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. I've added an info object to the callback that contains the from to values.
src/components/sortableList/types.ts
Outdated
@@ -21,7 +21,7 @@ export interface SortableListProps<ItemT extends SortableListItemProps> | |||
/** | |||
* A callback to get the new order (or swapped items). | |||
*/ | |||
onOrderChange: (data: ItemT[] /* TODO: add more data? */) => void; | |||
onOrderChange: (data: ItemT[], from: number, to: number /* TODO: add more data? */) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment on the API
Description
Adding option for onChange to send the indexes the item moved from and to.
Changelog
SortableList - onOrderChange now sends the old and new index of the changed item.
Additional info
MADS-4312