vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
460 stars 83 forks source link

Recurring focussed cell when scrolling in tables with many entries #7614

Closed 19rainer98 closed 3 days ago

19rainer98 commented 2 months ago

Description

We are using the Vaadin Grid with focusable cells. In tables with a lot of entries, we have noticed that if you start scrolling after focussing a cell, a focussed cell appears again and again, even though the actual focussed cell is not in the visible area. We suspect this is happening because the infinite scrolling logic is basically reusing the rows when you scroll around, and something in that logic isn't clearing away the focused-cell part name when it should.

Important: You must use the mouse wheel to scroll, not the scrollbar, otherwise the cell will lose focus.

Expected outcome

The focus ring should remain on the effectively focussed cell and not be visible on the reused components.

Minimal reproducible example

Can be reproduced on the documentary page of Vaadin: here

Steps to reproduce

  1. Focus a cell
  2. Start scrolling using the mouse wheel

Environment

Vaadin version(s): 24.4 and older OS: Issue is not OS related

Browsers

Issue is not browser related

vursen commented 1 week ago

The issue is only observable in the mentioned "Cell Focus" docs example and doesn't occur with a plain grid. The recurrence is connected to a custom stylesheet that comes with that docs example:

vaadin-grid.force-focus-outline::part(focused-cell)::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    box-shadow: inset 0 0 0 2px var(--lumo-primary-color-50pct);
}

This CSS seems to be there to enforce the focus outline when a cell is clicked, not just when it's focused with the keyboard. However, mouse interactions don't trigger the navigating attribute, so this case falls outside the default grid logic that prevents recurrence when scrolling after keyboard navigation (and could also help prevent it in the docs example with some CSS tweaks if the attribute was added):

https://github.com/vaadin/web-components/blob/17fe56888855e88b8571e202333b186f9341a66c/packages/grid/src/vaadin-grid-keyboard-navigation-mixin.js#L946-L961

https://github.com/vaadin/web-components/blob/17fe56888855e88b8571e202333b186f9341a66c/packages/grid/theme/lumo/vaadin-grid-styles.js#L79-L86