Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/react-aria-components/test/Table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,29 @@ describe('Table', () => {
await user.keyboard('{Escape}');
act(() => jest.runAllTimers());
});

it('should select dropped item', async () => {
const DndTableExample = stories.DndTableExample;
let {getAllByRole} = render(<DndTableExample />);
let tableTester = testUtilUser.createTester('Table', {root: getAllByRole('grid')[1]});
expect(tableTester.rows).toHaveLength(7);
expect(tableTester.selectedRows).toHaveLength(0);
await user.tab();
await user.keyboard('{ArrowRight}');
await user.keyboard('{Enter}');
act(() => jest.runAllTimers());
expect(document.activeElement).toHaveAttribute('aria-label', 'Insert between Adobe Photoshop and Adobe XD');
await user.tab();
expect(document.activeElement).toHaveAttribute('aria-label', 'Drop on');
await user.keyboard('{ArrowDown}');
expect(document.activeElement).toHaveAttribute('aria-label', 'Insert before Pictures');
await user.keyboard('{Enter}');
// run onInsert promise in DnDTableExample first, otherwise updateFocusAfterDrop doesn't run properly
await act(async () => {});
act(() => jest.runAllTimers());
expect(tableTester.rows).toHaveLength(8);
expect(tableTester.selectedRows).toHaveLength(1);
});
});

describe('column resizing', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/react-aria/src/dnd/useDroppableCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,13 @@ export function useDroppableCollection(props: DroppableCollectionOptions, state:
state.selectionManager.isSelectionEqual(prevSelectedKeys)
) {
let newKeys = new Set<Key>();
for (let item of state.collection) {
if (item.type === 'item' && !prevCollection.getItem(item.key)) {
let key = state.collection.getFirstKey();
while (key != null) {
let item = state.collection.getItem(key);
if (item?.type === 'item' && !prevCollection.getItem(item.key)) {
Comment on lines -256 to +259
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Root issue was that using the collection iterator for TableCollection returns just the column header and the body, not the actual rows. Walking the items should be more accurate I believe

newKeys.add(item.key);
}
key = state.collection.getKeyAfter(key);
}

state.selectionManager.setSelectedKeys(newKeys);
Expand Down
Loading