feat: #10121 Implemented the Table Column Header Focus - #10369
Conversation
snowystinger
left a comment
There was a problem hiding this comment.
Thanks, this looks pretty good. Will bring it to the team and see how we feel about the prop/name etc
|
Thanks @snowystinger, I'll wait for the team feedback |
There was a problem hiding this comment.
minor point, but do we really want to make this v3 change or is it enough have it available in RAC for now. We could consider exposing it in S2 as well, but only if there is an ask for it
There was a problem hiding this comment.
I'd be ok with restricting the scope and having it only in RAC for now
There was a problem hiding this comment.
I noticed that arrow down doesn't seem to work when you are focused on the columns now, it should move focus to the rows below
There was a problem hiding this comment.
@LFDanLu , now the arrow down is focusing on the columns.
|
@LFDanLu Thanks for the feedback. I have removed the prop and moved those tests into RAC. |
|
@snowystinger Cleaned up the code and made the suggested changes |
| return node.type === 'cell' || node.type === 'rowheader' || node.type === 'column'; | ||
| } | ||
|
|
||
| getFirstKey(fromKey?: Key, global?: boolean): Key | null { |
There was a problem hiding this comment.
@snowystinger brought up a good point that this may affect areas like
react-spectrum/packages/react-aria/src/dnd/useDroppableCollection.ts
Lines 661 to 671 in 14b74f3
and
react-spectrum/packages/react-aria/src/dnd/useDroppableCollection.ts
Lines 739 to 748 in 14b74f3
IMO either those call sites need to be updated accordingly to look for the first row key, or we should change this column case to specifically only trigger for normal keyboard navigation some how
There was a problem hiding this comment.
We should have tests for these as well, or point them out if they already exist, I'm a little surprised none broke but we may not have good coverage on this
There was a problem hiding this comment.
@LFDanLu and @snowystinger Thanks for pointing out the useDroppableCollection issue. Returning the column header from getFirstKey() was affecting DnD keyboard navigation. I added a getFirstItemKey helper to skip non-item elements and find the first row. I also updated the DnD call sites to use it. DnD keyboard navigation now works correctly, and all DnD and Table tests are passing.
| } else { | ||
| // If on the root, go to the item a page below the top. Otherwise a page below the current item. | ||
| let targetKey = keyboardDelegate.getFirstKey?.(); | ||
| let targetKey = getFirstItemKey(keyboardDelegate, localState.state.collection); |
There was a problem hiding this comment.
This is starting to worry me that we're making a breaking change
There was a problem hiding this comment.
Thanks for the feedback. I looked into both points a bit more
I agree that we should avoid a breaking change! The reason I added getFirstItemKey is to make the DnD code use an actual item key. DnD expects drop target to be either item or root, so the column header returned by getFirstKey() shouldn't be passed to it, and this helper function will skip non-item nodes and find the first valid item instead.
So this supports columnheader as the initial focus for Tables without changing the shared APIs or passing an invalid key into the DnD logic.
| * | ||
| * @default 'row' | ||
| */ | ||
| initialFocus?: 'row' | 'columnheader'; |
There was a problem hiding this comment.
Maybe instead of it being global, it should be an optional argument to getFirstKey? I have no idea if that'll be better
There was a problem hiding this comment.
Keeping it on TableKeyboardDelegate is the safer option, and the useSelectableCollection is shared by Lists, Grids, and Trees, so it doesn’t know about initialFocus. Passing it through getFirstKey() would require changes to the shared KeyboardDelegate API and the generic hook. Keeping it as an option on the Table delegate keeps this change limited to Tables.
Closes #10121
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: