Open provi-dominik opened 1 year ago
Indeed, Grid's focusability is only partially implemented at all: programmatically focusing the Grid is similarly non-functional: https://github.com/vaadin/flow-components/issues/2180.
I think both issues should be fixed together.
One important detail is that the Grid as a whole is not focusable at all. Instead, focus is always on one of the cells.
Some open questions about the desired behavior:
setTabindex(-1)
disable focusing individual cells in the Grid?setTabindex(-1)
disable keyboard-traversal of rows in the Grid? (This will also make selection impossible if so)setTabindex(-1)
disable focusing focusable elements in cells?setTabindex(-1)
disable focusing cells in edit mode in Grid Pro?setTabindex(-1)
disable focusing content in item details panels?setTabIndex(-1)
disable focusing content in an edit-mode row in Flow Grid's inline edit mode?I would desire the following behavior:
Should setTabindex(-1) disable focusing focusable elements in cells? <- No, only the keyboard-traversal through focusable elements in cells should be disabled
Should setTabindex(-1) disable focusing cells in edit mode in Grid Pro? <- No, only the keyboard-traversal through cells in edit mode should be disabled
Should setTabindex(-1) disable focusing content in item details panels? <- No, only the keyboard-traversal through content in item details should be disabled
Should setTabIndex(-1) disable focusing content in an edit-mode row in Flow Grid's inline edit mode? <- No, only the keyboard-traversal through content in an edit-mode row should be disabled
Does this mean that these focusable elements would still be present in the tab-order, so that, tabbing in from the "above" the Grid, keyboard focus would land straight into the first focusable element / cell editor, essentially bypassing the rest of the Grid?
No, I mean that the mentioned elements should not be present in the tab-order (that is what I mean with "disabling the keyboard-traversal"). The elements should be focusable as described in the Javadoc of the Focusable interface: "A negative value (usually tabindex = -1) means that the component should be focusable, but should not be reachable via sequential keyboard navigation."
Right, ok, sorry, I was a bit unclear in my questions: I meant keyboard-focusability in each one.
So, TL;DR: no keyboard-focusability on any element in the Grid, only focusable by mouse?
Yes, this is the behavior I would expect.
The thing is, in HTML setting tabindex
on the element to -1
excludes it from sequential navigation, but not its children.
So if you set tabindex="-1"
on e.g. vaadin-scroller
, elements inside it would be still keyboard focusable.
While some might argue that vaadin-grid
is a single element, it has several internal elements that participate in the Tab order (that in HTML Standard terminology is referred to as being "sequentially focusable") for accessibility reasons.
So I would prefer to not change the current behavior of setTabindex
method. Instead, a new API would make sense:
no-keyboard-focus
attribute to the vaadin-grid
web component,setKeyboardFocusable(false)
method to the Flow counterpart.These would need to be properly documented as not recommended for usage because of accessibility concerns.
I feel inclined to agree with that assessment. I'm also curious to hear the use cases for excluding the Grid tab stop.
Actually, setting tabindex="-1"
on the web component does seem to exclude the grid from keyboard navigation (so we might need to do a research on why Flow API doesn't work). But I still think it would be good to have a dedicated API.
I found out a curious thing. When I am testing Vaadin 23.3.0 using grid.setTabIndex(-1)
seems to work fine.
(Added a few more colorful labels because it's Christmas!)
If I understand the situation correctly:
tabindex="-1"
and Grid.setTabIndex("-1")
does disable keyboard focusing of Grid (or, rather, its cells) in V23.3 (but not in V14.9.2)Grid.focus()
does nothing on the Grid. Since the Grid is not a tab stop itself, it would probably make sense to make it focus the first cell (which would solve https://github.com/vaadin/flow-components/issues/1254).So we need to decide a few things:
Grid.focus()
set focus on the first cell?Just to clarify: setting tabindex="-1"
on the vaadin-grid
excludes it from keyboard navigation sequence when pressing Tab or Shift + Tab (which makes sense if you want the user to just "skip" grid and its content).
But as soon as user clicks a cell - for example an editable cell in vaadin-grid-pro
- they can still navigate cell content with Tab again. Not sure if this is something that people would expect, but it's how the grid is supposed to work.
You can test this in web component by using the following HTML snippet (focus the first <input>
and press Tab):
<input placeholder="Before" />
<vaadin-grid-pro tabindex="-1">
<vaadin-grid-pro-edit-column path="name.first"></vaadin-grid-pro-edit-column>
<vaadin-grid-pro-edit-column path="name.last"></vaadin-grid-pro-edit-column>
</vaadin-grid-pro>
<input placeholder="After" />
<script type="module">
import '@vaadin/grid-pro';
import '@vaadin/grid-pro/vaadin-grid-pro-edit-column.js';
const grid = document.querySelector('vaadin-grid-pro');
grid.items = [
{
name: {
first: 'John',
last: 'Doe',
},
},
{
name: {
first: 'Jane',
last: 'Doe',
},
},
];
</script>
I would still like to hear from @provi-dominik what the use case for disabling keyboard focusing on the Grid is.
@rolfsmeds: This is one use case in our application: We show a dialog to display error messages. In this dialog the user has to interact with some components dependening on these error messages. For example the user has to select an entry in a Select component and confirm the choice. So that the user can process the dialog quickly and is not confused by an unexpected focus in the table, the table should not be in the keyboard navigation sequence. The table is only intended to represent the messages.
Description
If I call setTabIndex(-1) on a grid component, the grid component isn't dropped from the tab focus cycle. The table element in the DOM tree has still the tab index 0:
Expected outcome
The grid component is dropped from the tab focus cycle.
Minimal reproducible example
@Route("/grid") @PageTitle("Grid-Example") public class ExampleGrid extends Div {
}
Steps to reproduce
Environment
Vaadin version(s): 14.9.2 OS: Windows 10 Enterprise (Build 20H2, OS build 19042.1889)
Browsers
Chrome