Open drwpow opened 6 days ago
I’d be open to raising a PR, but wanted to discuss first whether or not it would be sufficient to remove gridcell
(and friends—row
, rowgroup
, etc.) from the “always non-interactive” list.
I’m inclined to do so because looking at the base grid role docs, we see keyboard interactions suggested even for native <table>
elements. This leads me to believe that even though the base elements aren’t focusable using browser defaults, they are still recommended to be in many usecases. Therefore tabIndex
shouldn’t be discouraged.
However, if we wanted to take a more complex approach, where gridcell
and friends are only interactive under certain conditions (e.g. only if a child of treegrid
), I’d feel less confident opening a PR until we defined that criteria (and whether or not we could lint that if the components were broken up). Either way, open to thoughts!
Environment information
Rule name
lint/a11y/noNoninteractiveTabindex
Playground link
https://biomejs.dev/playground/?code=ZQB4AHAAbwByAHQAIABmAHUAbgBjAHQAaQBvAG4AIABUAHIAZQBlAEcAcgBpAGQAKAApACAAewAKACAAIAByAGUAdAB1AHIAbgAgACgACgAgACAAIAAgADwAZABpAHYAIAByAG8AbABlAD0AIgB0AHIAZQBlAGcAcgBpAGQAIgAgAGEAcgBpAGEALQBhAGMAdABpAHYAZQBkAGUAcwBjAGUAbgBkAGUAbgB0AD0AIgBjAGUAbABsAC0AMQAtADIAIgA%2BAAoAIAAgACAAIAAgACAAPABkAGkAdgAgAHIAbwBsAGUAPQAiAGMAbwBsAHUAbQBuAGcAcgBvAHUAcAAiAD4ACgAgACAAIAAgACAAIAAgACAAPABkAGkAdgAgAHIAbwBsAGUAPQAiAHIAbwB3ACIAPgAKACAAIAAgACAAIAAgACAAIAAgACAAPABkAGkAdgAgAGkAZAA9ACIAYwBvAGwALQAxACIAIAByAG8AbABlAD0AIgBjAG8AbAB1AG0AbgBoAGUAYQBkAGUAcgAiACAAdABhAGIASQBuAGQAZQB4AD0AewAwAH0APgBDAG8AbAB1AG0AbgAgADEAPAAvAGQAaQB2AD4ACgAgACAAIAAgACAAIAAgACAAIAAgADwAZABpAHYAIABpAGQAPQAiAGMAbwBsAC0AMgAiACAAcgBvAGwAZQA9ACIAYwBvAGwAdQBtAG4AaABlAGEA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APQB7ADAAfQA%2BAEMAPAAvAGQAaQB2AD4ACgAgACAAIAAgACAAIAAgACAAPAAvAGQAaQB2AD4ACgAgACAAIAAgACAAIAA8AC8AZABpAHYAPgAKACAAIAAgACAAPAAvAGQAaQB2AD4ACgAgACAAKQA7AAoAfQA%3D
Expected result
Both treegrid and grid are described to work like spreadsheets on the web, where data can be edited and individual cells can be focused within and navigated using arrow keys.
Treegrid takes it one step further and allows expanding/collapsing of rows and columns like a tree.
So when trying to implement focus behavior, this throws an error when it shouldn’t:
This conflicts with the recommended behavior of treegrid children:
In other words, a gridcell MUST be focusable when inside a treegrid if it’s expandable (via
tabIndex
), and also MUST be able to receive other keyboard commands.lint/a11y/noNoninteractiveTabindex
is correct in other instances, so it seems this is only a problem with grid and treegrid children.Other notes
useSemanticElements
rule does apply to this example but is irrelevant; noNoninteractiveTabindex still raises the same errorstabIndex={0}
and everything else getstabIndex={-1}
), but also doesn’t affect the outcomeCode of Conduct