adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.12k stars 1.06k forks source link

Removing a Tag in a TagGroup with disabled Tags crashes the page #6616

Closed kraine93 closed 4 days ago

kraine93 commented 5 days ago

Provide a general summary of the issue here

When combining two features of TagGroup - disabledKeys and onRemove - it's possible to crash the browser tab when removing a Tag.

This only seems to happen when there are at least two disabled Tags in the collection.

I'm able to reproduce in at least two ways:

  1. Remove all non-disabled Tags from a collection (ctrl-a + backspace), leaving only disabled Tags remaining.
  2. Remove the last Tag from the end of a collection where the (at least) two previous Tags are disabled.

It works fine when:

๐Ÿค” Expected Behavior?

The page should not crash and the next or previous non-disabled Tag should receive focus. If there are no remaining focusable Tags, the TagGroup or TagList should receive focus.

๐Ÿ˜ฏ Current Behavior

The page crashes.

๐Ÿ’ Possible Solution

At a guess, I would say that perhaps the TagGroup is struggling to find a valid target to move focus to when the element is removed.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://codesandbox.io/p/sandbox/exciting-hooks-6lhjcm

Delete the final tag 'Watermelon' to crash the tab.

Version

react-aria-components 1.2.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Windows

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

snowystinger commented 5 days ago

Yep, found the issue, I've created a PR to fix it. Thanks for reporting it

kraine93 commented 5 days ago

Amazing! Thanks for the quick fix ๐Ÿš€