react-spectrum
react-spectrum copied to clipboard
make ListCollection and TreeCollection satisfy the Collection interface
Currently, ListCollection and TreeCollection does not satisfy the Collection interface, because getKeyBefore() and getKeyAfter() could return undefined. The details are as follows.
Collection interface:
ListCollection:
node.prevKeyandnode.nextKeycan beundefinedListCollection.getKeyBefore()andListCollection.getKeyAfter()can returnundefined
TreeCollection:
node.prevKeyandnode.nextKeycan beundefinedTreeCollection.getKeyBefore()andTreeCollection.getKeyAfter()can returnundefiend
For example, if we replace state.collection.getKeyAfter(item.key) == null in useDraggableCollection() docs with state.collection.getKeyAfter(item.key) === null, things does not work as expected (according to the type definition this is valid).
✅ Pull Request Checklist:
- [ ] Included link to corresponding React Spectrum GitHub Issue.
- [ ] Added/updated unit tests and storybook for this change (for new code or code which already has tests).
- [ ] Filled out test instructions.
- [ ] Updated documentation (if it already exists for this component).
- [ ] Looked at the Accessibility Practices for this feature - Aria Practices