Skip to content

fix: focus newly added table row on drop#9873

Open
LFDanLu wants to merge 6 commits intomainfrom
fix_table_drop_focus
Open

fix: focus newly added table row on drop#9873
LFDanLu wants to merge 6 commits intomainfrom
fix_table_drop_focus

Conversation

@LFDanLu
Copy link
Copy Markdown
Member

@LFDanLu LFDanLu commented Apr 2, 2026

Fixes a regression from #9751 that was found in testing.

✅ 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

📝 Test Instructions:

In the RAC docs, go to the Drag and Drop page -> multiple positions and try dragging and dropping a table row from the first table into the second row. The dropped row should be selected and focused on drop. Check the other collection components drag and drop behavior as well

🧢 Your Project:

RSP

@github-actions github-actions bot added the RAC label Apr 2, 2026
Comment on lines -256 to +259
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)) {
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

@rspbot
Copy link
Copy Markdown

rspbot commented Apr 2, 2026

reidbarber
reidbarber previously approved these changes Apr 3, 2026
@chirokas
Copy link
Copy Markdown
Contributor

chirokas commented Apr 3, 2026

Some behaviors are inconsistent with the previous version, as shown below:

Video.Project.mp4

@LFDanLu
Copy link
Copy Markdown
Member Author

LFDanLu commented Apr 3, 2026

@chirokas thanks for reporting those, they both seem unrelated to the changes here since they reproduce on the latest build on main: https://reactspectrum.blob.core.windows.net/reactspectrum/46be2856add60b1d7e1b91b393b9bfa5f002f807/storybook/index.html?path=/story/react-aria-components-tree--tree-with-drag-and-drop&args=selectionMode:multiple&providerSwitcher-express=false. I'll see if I can dig up the commits that may have changed these behaviors since IMO they both seem like regressions

EDIT: I've added fixes for these, the original issue was the change we pushed in #9751 that your original changes seem to address. The approach I took is slightly different let me know what you think

expect(secondTreeTester.selectedRows).toHaveLength(9);
});

it('should focus the parent row when dropped on if it isnt expanded', async () => {
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.

These two tests actually always pass without the changes in useDroppableCollection, not quite sure why it differs from the observed browser behavior. Also interesting to note is that having Strict Mode on in the storybook locally also will cause the issue to not appear...

Still digging as to why this would be the case

@rspbot
Copy link
Copy Markdown

rspbot commented Apr 3, 2026

@rspbot
Copy link
Copy Markdown

rspbot commented Apr 3, 2026

## API Changes

@react-spectrum/s2

/@react-spectrum/s2:ActionMenu

 ActionMenu <T extends {}> {
   UNSAFE_className?: UnsafeClassName
   UNSAFE_style?: CSSProperties
   align?: 'start' | 'end' = 'start'
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean
   children: ReactNode | (T) => ReactNode
   defaultOpen?: boolean
   direction?: 'bottom' | 'top' | 'left' | 'right' | 'start' | 'end' = 'bottom'
   disabledKeys?: Iterable<Key>
   id?: string
   isDisabled?: boolean
   isOpen?: boolean
   isQuiet?: boolean
   items?: Iterable<T>
   menuSize?: 'S' | 'M' | 'L' | 'XL' = 'M'
   onAction?: (Key) => void
   onOpenChange?: (boolean) => void
-  shouldCloseOnSelect?: boolean
   shouldFlip?: boolean = true
   size?: 'XS' | 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

/@react-spectrum/s2:ActionMenuProps

 ActionMenuProps <T> {
   UNSAFE_className?: UnsafeClassName
   UNSAFE_style?: CSSProperties
   align?: 'start' | 'end' = 'start'
   aria-describedby?: string
   aria-details?: string
   aria-label?: string
   aria-labelledby?: string
   autoFocus?: boolean
   children: ReactNode | (T) => ReactNode
   defaultOpen?: boolean
   direction?: 'bottom' | 'top' | 'left' | 'right' | 'start' | 'end' = 'bottom'
   disabledKeys?: Iterable<Key>
   id?: string
   isDisabled?: boolean
   isOpen?: boolean
   isQuiet?: boolean
   items?: Iterable<T>
   menuSize?: 'S' | 'M' | 'L' | 'XL' = 'M'
   onAction?: (Key) => void
   onOpenChange?: (boolean) => void
-  shouldCloseOnSelect?: boolean
   shouldFlip?: boolean = true
   size?: 'XS' | 'S' | 'M' | 'L' | 'XL' = 'M'
   styles?: StylesProp
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants