Skip to content

Grid aria-rowindex is inconsistent when Grid is initially hidden #7448

Description

@HerbertsVaadin

Description

When grid is visible from the start,
the table header row is marked with aria-rowindex="1"
the first row of the table body starts with aria-rowindex="2"
Image

When grid is hidden, and then revealed,
the table header row is marked with aria-rowindex="1"
the first row of the table body starts with aria-rowindex="1"
there is no row with aria-rowindex="4" it skips directly to aria-rowindex="5"
if you have scroll, and scroll to the bottom, back to the top, the first row of the table body aria-rowindex="2", and the second row is also aria-rowindex="2"
Image

Expected outcome

Table header row is marked with aria-rowindex="1"
First row of the table body starts with aria-rowindex="2"
It doesn't skip aria-rowindex="4"

Minimal reproducible example

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Menu;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import org.vaadin.lineawesome.LineAwesomeIconUrl;

import java.util.List;

@PageTitle("Two Grids")
@Route("two-grids")
@Menu(order = 4, icon = LineAwesomeIconUrl.TABLE_SOLID)
@PermitAll
@Uses(Icon.class)
public class TwoGrids extends VerticalLayout {

    private Grid<String> grid1;
    private Grid<String> grid2;

    public TwoGrids() {
        grid1 = createRegularGrid();
        grid2 = createRegularGrid();
        grid2.setVisible(false);

        var button = new Button("Toggle grid 2");
        button.addClickListener(event -> grid2.setVisible(!grid2.isVisible()));

        add(grid1, button, grid2);
    }


    private Grid<String> createRegularGrid() {
        var grid = new Grid<String>();
        grid.addColumn(String::toString)
                .setHeader("Regular");

        grid.setItems(exampleValues());

        return grid;
    }


    private List<String> exampleValues() {
        return List.of("One", "Two", "Three", "Four", "Five");
    }

}

Steps to reproduce

  1. Create two identical grids.
  2. Hide one of them initially.
  3. After view has been loaded, reveal the grid that was hidden.
  4. Verify in the revealed grids shadowdom its aria-rowindex situation.
  5. Compare it with the grid that was initially visible to see the inconsistency.

Environment

Vaadin version(s): 24.7.3
OS: Linux Mint

Browsers

Firefox, Chrome

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions