focus is not maintained in 'x-for' loop when using 'key' attribute #4772
Replies: 1 comment 1 reply
-
|
This is intended, because the key when you don't provide it is just the index, so you reordering things, it just changes everything to match, not actually moving elements.. Currently, with the logic, it uses apis that basically cause the element to be removed and readded when reordered (the relevant moved ones). There are newer apis that should help retain that behavior but their support isn't fantastic (well, it's good enough for most, but is a newer api). I might make a PR since I was interesting in that approach, but I don't know for sure if it would solve it anyway. Should even be possible to have it gracefully fall back on older browsers, but then you'd still have this issue there... You could keep track of the focus in your space and ensure it's maintained, but that could also be pretty tricky. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When using an 'x-for' loop without a 'key' attribute, the focus in a list is retained but not in the correct location:
Screen.Recording.2026-03-16.000820.mp4
This is expected behavior and should be solvable by adding the 'key' attribute. However if you add the key attribute, every update to the list causes loss of focus, and when you press tab the placement of the focus is wrong:
Screen.Recording.2026-03-16.000659.mp4
This is problematic for accessibility reasons.
Beta Was this translation helpful? Give feedback.
All reactions