Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix ARIA grid role hierarchy in DataGrid for accessibility compliance (#70978)

Anderson1fbe726c0858
diff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
index c7d5466ccf2..62374be4167 100644
--- a/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-question-theming.cy.spec.tsx
@@ -174,8 +174,10 @@ describe(
});
cy.findByTestId("table-body")
+ .findByTestId("center-center-quadrant")
.findAllByRole("gridcell")
- .first()
+ .eq(1)
+ .findByTestId("body-cell-container")
.should(($el) => {
assertBackgroundColorEqual($el, CELL_COLOR);
});
diff --git a/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js b/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
index 028f9e3f1ef..0c4288691f1 100644
--- a/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
@@ -2928,7 +2928,7 @@ const testChangingBackToDefaultBehavior = () => {
const getTableCell = (index) => {
// eslint-disable-next-line metabase/no-unsafe-element-filtering
- return cy
+ return H.tableInteractiveBody()
.findAllByRole("row")
.eq(POINT_INDEX)
.findAllByTestId("cell-data")
diff --git a/e2e/test/scenarios/dashboard-filters-2/shared/dashboard-filters-query-stages.ts b/e2e/test/scenarios/dashboard-filters-2/shared/dashboard-filters-query-stages.ts
index 7e287022cc5..77c20d1cd4b 100644
--- a/e2e/test/scenarios/dashboard-filters-2/shared/dashboard-filters-query-stages.ts
+++ b/e2e/test/scenarios/dashboard-filters-2/shared/dashboard-filters-query-stages.ts
@@ -838,8 +838,10 @@ export function verifyDashcardCellValues({
// eslint-disable-next-line metabase/no-unsafe-element-filtering
H.getDashboardCard(dashcardIndex)
- .findByRole("row")
- .findAllByRole("gridcell")
+ .findByTestId("table-body")
+ .findAllByRole("row")
+ .first()
+ .findAllByTestId("cell-data")
.eq(valueIndex)
.should("have.text", value);
}
@@ -853,6 +855,9 @@ export function verifyDashcardCellValues({
const value = values[valueIndex];
// eslint-disable-next-line metabase/no-unsafe-element-filtering
- cy.findAllByRole("gridcell").eq(valueIndex).should("have.text", value);
+ H.tableInteractiveBody()
+ .findAllByTestId("cell-data")
+ .eq(valueIndex)
+ .should("have.text", value);
}
}
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
index 26791f66b79..20301cf0f65 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-auto-wiring.cy.spec.js
@@ -802,7 +802,8 @@ function getTableCell(columnName, rowIndex) {
.toArray()
.findIndex(($columnHeader) => $columnHeader.textContent === columnName);
// eslint-disable-next-line metabase/no-unsafe-element-filtering
- cy.findAllByRole("row")
+ H.tableInteractiveBody()
+ .findAllByRole("row")
.eq(rowIndex)
.findAllByTestId("cell-data")
.eq(columnHeaderIndex)
diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-sql-number.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-sql-number.cy.spec.js
index 7cc21c6487d..f71798ffda3 100644
--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-sql-number.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-sql-number.cy.spec.js
@@ -171,7 +171,8 @@ describe("scenarios > dashboard > filters > SQL > number", () => {
cy.findByPlaceholderText("Price").type("95").blur();
cy.findByPlaceholderText("Rating").type("3.8").blur();
- cy.findAllByRole("row")
+ cy.findByTestId("table-body")
+ .findAllByRole("row")
.should("have.length", 2)
// first line price
.and("contain", "98.82")
diff --git a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
index 5ecdb8d4502..78bff968a7d 100644
--- a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js
@@ -496,7 +496,7 @@ describe("scenarios > dashboard > parameters", () => {
"eq",
"?category=Widget&title=Awesome+Concrete+Shoes&vendor=McClure-Lockman",
);
- cy.findAllByRole("row").should("have.length", 1);
+ H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
// It should not reset previously defined filters when exiting 'edit' mode without making any changes (metabase#5332, metabase#17139)
H.editDashboard();
@@ -509,7 +509,7 @@ describe("scenarios > dashboard > parameters", () => {
"eq",
"?category=Widget&title=Awesome+Concrete+Shoes&vendor=McClure-Lockman",
);
- cy.findAllByRole("row").should("have.length", 1);
+ H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
});
describe("when the user does not have self-service data permissions", () => {
diff --git a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
index 3d766f6034c..868acf8394b 100644
--- a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js
@@ -752,7 +752,10 @@ describe("issue 29076", () => {
H.visitDashboard(ORDERS_DASHBOARD_ID);
cy.wait("@cardQuery");
// test that user is sandboxed - normal users has over 2000 rows
- H.getDashboardCard().findAllByRole("row").should("have.length", 1);
+ H.getDashboardCard()
+ .findByTestId("table-body")
+ .findAllByRole("row")
+ .should("have.length", 1);
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("Orders").click();
@@ -1062,7 +1065,7 @@ describe("issue 34382", () => {
H.getDashboardCard().within(() => {
// only products with category "Gizmo" are filtered
- cy.findAllByRole("row")
+ cy.findByTestId("table-body")
.findAllByRole("gridcell")
.eq(3)
.should("contain", "Gizmo");
diff --git a/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js b/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js
index 33e223b9987..4f754a56ebd 100644
--- a/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js
+++ b/e2e/test/scenarios/embedding/embedding-linked-filters.cy.spec.js
@@ -339,7 +339,10 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
cy.location("search").should("eq", "?category=Gizmo&id_filter=1");
- cy.findAllByRole("row").should("have.length", 1).and("contain", "Gizmo");
+ H.tableInteractiveBody()
+ .findAllByRole("row")
+ .should("have.length", 1)
+ .and("contain", "Gizmo");
});
it("works when main filter's value is set through URL", () => {
@@ -367,7 +370,8 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
cy.location("search").should("eq", "?category=Doohickey&id_filter=4");
- cy.findAllByRole("row")
+ H.tableInteractiveBody()
+ .findAllByRole("row")
.should("have.length", 1)
.and("contain", "Doohickey");
@@ -382,14 +386,16 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
.and("contain", "2 selections")
.and("contain", "Widget");
- cy.findAllByRole("row")
+ H.tableInteractiveBody()
+ .findAllByRole("row")
.should("have.length", 1)
.and("contain", "Widget")
.and("contain", "Durable Steel Toucan");
removeValueForFilter("Category");
- cy.findAllByRole("row")
+ H.tableInteractiveBody()
+ .findAllByRole("row")
.should("have.length", 2)
.and("contain", "Widget")
.and("contain", "Doohickey")
@@ -402,7 +408,8 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
cy.button("Update filter").click();
- cy.findAllByRole("row")
+ H.tableInteractiveBody()
+ .findAllByRole("row")
.should("have.length", 1)
.and("contain", "Doohickey");
@@ -431,7 +438,10 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
});
});
- cy.findAllByRole("row").should("have.length", 1).and("contain", "Gizmo");
+ H.tableInteractiveBody()
+ .findAllByRole("row")
+ .should("have.length", 1)
+ .and("contain", "Gizmo");
H.filterWidget()
.should("have.length", 1)
@@ -463,7 +473,10 @@ describe("scenarios > embedding > dashboard > linked filters (metabase#13639, me
H.visitEmbeddedPage(payload);
});
- cy.findAllByRole("row").should("have.length", 1).and("contain", "Gizmo");
+ H.tableInteractiveBody()
+ .findAllByRole("row")
+ .should("have.length", 1)
+ .and("contain", "Gizmo");
H.filterWidget()
.should("have.length", 1)
diff --git a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js b/e2e/test/scenarios/embedding/embedding-native.cy.spec.js
index e39c9e7f1df..477f043148a 100644
--- a/e2e/test/scenarios/embedding/embedding-native.cy.spec.js
+++ b/e2e/test/scenarios/embedding/embedding-native.cy.spec.js
@@ -134,7 +134,7 @@ describe("scenarios > embedding > native questions", () => {
cy.findByPlaceholderText("Enter an ID").type("926");
cy.button("Add filter").click();
- cy.findAllByRole("row").should("have.length", 1);
+ H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("December 29, 2024, 4:54 AM");
@@ -245,7 +245,7 @@ describe("scenarios > embedding > native questions", () => {
},
});
- cy.findAllByRole("row").should("have.length", 1);
+ H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
cy.findByText("92");
H.filterWidget().should("not.exist");
@@ -325,7 +325,7 @@ describe("scenarios > embedding > native questions", () => {
H.visitEmbeddedPage(payload);
- cy.findAllByRole("row").should("have.length", 1);
+ H.tableInteractiveBody().findAllByRole("row").should("have.length", 1);
cy.findByText("66.8");
H.filterWidget().should("not.exist");
diff --git a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.js b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.js
index dc96099a220..aa39f8ec8fb 100644
--- a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.js
+++ b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.js
@@ -1820,7 +1820,10 @@ describe("issue 25374", () => {
H.saveDashboard();
cy.location("search").should("eq", "?equal_to=1%2C2%2C3");
- H.getDashboardCard().findByRole("gridcell").should("have.text", "3");
+ H.getDashboardCard()
+ .findByTestId("table-body")
+ .findByTestId("cell-data")
+ .should("have.text", "3");
cy.button("Clear").click();
cy.wait("@dashcardQuery");
@@ -1832,7 +1835,10 @@ describe("issue 25374", () => {
cy.button("Reset filter to default state").click();
cy.wait("@dashcardQuery");
- H.getDashboardCard().findByRole("gridcell").should("have.text", "3");
+ H.getDashboardCard()
+ .findByTestId("table-body")
+ .findByTestId("cell-data")
+ .should("have.text", "3");
cy.location("search").should("eq", "?equal_to=1%2C2%2C3");
// Drill-through and go to the question
@@ -1856,7 +1862,10 @@ describe("issue 25374", () => {
.type("1,2,3");
H.saveDashboard();
cy.location("search").should("eq", "?equal_to=1%2C2%2C3");
- H.getDashboardCard().findByRole("gridcell").should("have.text", "3");
+ H.getDashboardCard()
+ .findByTestId("table-body")
+ .findByTestId("cell-data")
+ .should("have.text", "3");
cy.button("Clear").click();
cy.wait("@dashcardQuery");
@@ -1871,14 +1880,17 @@ describe("issue 25374", () => {
cy.wait("@dashcardQuery");
cy.location("search").should("eq", "?equal_to=1%2C2%2C3");
cy.location("search").should("eq", "?equal_to=1%2C2%2C3");
- H.getDashboardCard().findByRole("gridcell").should("have.text", "3");
+ H.getDashboardCard()
+ .findByTestId("table-body")
+ .findByTestId("cell-data")
+ .should("have.text", "3");
// Drill-through and go to the question
H.getDashboardCard(0).findByText(questionDetails.name).click();
cy.wait("@cardQuery");
H.tableHeaderColumn("COUNT(*)");
- H.tableInteractiveBody().findByRole("gridcell").should("have.text", "3");
+ H.tableInteractiveBody().findByTestId("cell-data").should("have.text", "3");
cy.location("search").should("eq", "?num=1%2C2%2C3");
});
@@ -1944,7 +1956,9 @@ describe("issue 25908", () => {
// Note the capital first letter
cy.visit(`/dashboard/${dashboard_id}?text_contains=Li`);
cy.wait("@dashcardQuery");
- cy.findAllByRole("row").should("have.length", CASE_INSENSITIVE_ROWS);
+ H.tableInteractiveBody()
+ .findAllByRole("row")
+ .should("have.length", CASE_INSENSITIVE_ROWS);
},
);
});
diff --git a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
index d5527e32816..3e1ed532885 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
+++ b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
@@ -563,6 +563,7 @@ describe(
it("should be possible to filter by Mongo _id column (metabase#40770, metabase#42010)", () => {
H.tableInteractiveBody()
+ .findByTestId("center-center-quadrant")
.findAllByRole("gridcell")
.first()
.then(($cell) => {
diff --git a/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts b/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
index 63908e5d573..68513ede6dc 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
@@ -1275,48 +1275,39 @@ SELECT 2 AS ID, 3 AS USER_ID
{ wrapId: true, visitQuestion: true },
);
});
+ const findDataRows = () => {
+ return H.tableInteractiveBody()
+ .findByTestId("center-center-quadrant")
+ .findAllByRole("row");
+ };
+ const findUserIdCell = (rowIndex: number) => {
+ return findDataRows()
+ .should("have.length.gt", 0)
+ .eq(rowIndex)
+ .find("[data-column-id='USER_ID']")
+ .first();
+ };
- cy.findByTestId("table-body")
- .find("[data-column-id='USER_ID']")
- .eq(0)
- .click();
+ findUserIdCell(0).click();
H.popover().within(() => {
cy.findByText("View Models with no User").should("be.visible").click();
});
- cy.findByTestId("table-body").within(() => {
- /**
- * each row is rendered twice, that's why we need to assert 2 instead of 1
- */
- cy.findAllByRole("row").should("have.length", 2);
- cy.get("[data-column-id='USER_ID']")
- .first()
- .find("[data-testid=cell-data]")
- .should("not.exist");
- });
+ findDataRows().should("have.length", 1);
+
+ findUserIdCell(0).find("[data-testid=cell-data]").should("not.exist");
H.visitQuestion("@questionId");
- cy.findByTestId("table-body")
- .find("[data-column-id='USER_ID']")
- .eq(1)
- .click();
+ findUserIdCell(1).click();
H.popover().within(() => {
cy.findByText("View this User's Models").should("be.visible").click();
});
- cy.findByTestId("table-body").within(() => {
- /**
- * each row is rendered twice, that's why we need to assert 2 instead of 1
- */
- cy.findAllByRole("row").should("have.length", 2);
- cy.get("[data-column-id='USER_ID']")
- .first()
- .find("[data-testid=cell-data]")
- .should("have.text", "3");
- });
+ findDataRows().should("have.length", 1);
+ findUserIdCell(0).should("have.text", "3");
});
});
diff --git a/e2e/test/scenarios/question/nulls.cy.spec.js b/e2e/test/scenarios/question/nulls.cy.spec.js
index e438b213ee1..203df8ad7fe 100644
--- a/e2e/test/scenarios/question/nulls.cy.spec.js
+++ b/e2e/test/scenarios/question/nulls.cy.spec.js
@@ -132,12 +132,11 @@ describe("scenarios > question > null", () => {
it("should filter by clicking on the row with `null` value (metabase#18386)", () => {
H.openOrdersTable();
+ const findGridcell = (text) =>
+ cy.findByRole("grid").findByRole("gridcell", { name: text });
// Total of "39.72", and the next cell is the `discount` (which is empty)
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("39.72")
- .closest("[role=gridcell]")
- .parent()
+ findGridcell("39.72")
.next()
.find("div")
.should("be.empty")
@@ -146,11 +145,9 @@ describe("scenarios > question > null", () => {
H.popover().contains("=").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("39.72");
+ findGridcell("39.72").should("be.visible");
// This row ([id] 3) had the `discount` column value and should be filtered out now
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("49.21").should("not.exist");
+ findGridcell("49.21").should("not.exist");
});
describe("aggregations with null values", () => {
diff --git a/e2e/test/scenarios/question/offset.cy.spec.ts b/e2e/test/scenarios/question/offset.cy.spec.ts
index 853effda3b9..6a104fded71 100644
--- a/e2e/test/scenarios/question/offset.cy.spec.ts
+++ b/e2e/test/scenarios/question/offset.cy.spec.ts
@@ -1330,9 +1330,9 @@ function verifyLineChart({
}
}
-function verifyTableContent(rows: string[][]) {
- const columnsCount = rows[0].length;
- const pairs = rows.flatMap((row, rowIndex) => {
+function verifyTableContent(dataRows: string[][]) {
+ const columnsCount = dataRows[0].length;
+ const pairs = dataRows.flatMap((row, rowIndex) => {
return row.map((text, cellIndex) => {
const index = rowIndex * columnsCount + cellIndex;
return { index, text };
@@ -1340,13 +1340,19 @@ function verifyTableContent(rows: string[][]) {
});
for (const { index, text } of pairs) {
+ cy.log("index", index);
+ cy.log("text", text);
verifyTableCellContent(index, text);
}
}
function verifyTableCellContent(index: number, text: string) {
// eslint-disable-next-line metabase/no-unsafe-element-filtering
- cy.findAllByRole("gridcell").eq(index).should("have.text", text);
+ H.tableInteractiveBody()
+ .findByTestId("center-center-quadrant")
+ .findAllByRole("gridcell")
+ .eq(index)
+ .should("have.text", text);
}
function verifyNoQuestionError() {
diff --git a/e2e/test/scenarios/table-editing/table-editing.cy.spec.ts b/e2e/test/scenarios/table-editing/table-editing.cy.spec.ts
index 5975341fe62..edd781b1148 100644
--- a/e2e/test/scenarios/table-editing/table-editing.cy.spec.ts
+++ b/e2e/test/scenarios/table-editing/table-editing.cy.spec.ts
@@ -307,7 +307,7 @@ describe("scenarios > table-editing", () => {
cases.forEach(({ dataType, column, value }) => {
it(`should allow to edit a cell with type ${dataType}`, () => {
// Locate the table and the specific cell to edit
- cy.findByTestId("table-body")
+ H.tableInteractiveBody()
.find(`[data-column-id='${column}']`)
.eq(1) // Select the second row (index 1)
.as("targetCell")
@@ -350,7 +350,7 @@ describe("scenarios > table-editing", () => {
});
it("should allow to edit a cell with date type", () => {
- cy.findByTestId("table-body")
+ H.tableInteractiveBody()
.find("[data-column-id='date']")
.eq(1)
.as("targetCell")
@@ -375,11 +375,15 @@ describe("scenarios > table-editing", () => {
});
it("should allow to edit a cell with datetime type", () => {
- cy.findByTestId("table-body")
- .find("[data-column-id='datetime']")
+ H.tableInteractiveBody()
+ .findByTestId("center-center-quadrant")
+ .findAllByRole("row")
.eq(1)
- .as("targetCell")
- .click({ scrollBehavior: false });
+ .within(() => {
+ cy.get("[data-column-id='datetime']").as("targetCell").click({
+ scrollBehavior: false,
+ });
+ });
const day = Math.floor(Math.random() * 10) + 10; // 10-20
const hour = Math.floor(Math.random() * 12);
@@ -416,7 +420,7 @@ describe("scenarios > table-editing", () => {
});
it("should allow to edit a cell with select type", () => {
- cy.findByTestId("table-body")
+ H.tableInteractiveBody()
.find("[data-column-id='boolean']")
.eq(1)
.as("targetCell")
@@ -435,7 +439,7 @@ describe("scenarios > table-editing", () => {
});
it("should not allow to edit PK cells", () => {
- cy.findByTestId("table-body")
+ H.tableInteractiveBody()
.find("[data-column-id='id']")
.eq(1)
.as("targetCell")
@@ -445,7 +449,7 @@ describe("scenarios > table-editing", () => {
});
it("should handle errors", () => {
- cy.findByTestId("table-body")
+ H.tableInteractiveBody()
.find("[data-column-id='tinyint']")
.eq(1)
.as("targetCell")
diff --git a/e2e/test/scenarios/visualizations-tabular/drillthroughs/table_drills.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/drillthroughs/table_drills.cy.spec.js
index abba9c622d3..95f002c8d47 100644
--- a/e2e/test/scenarios/visualizations-tabular/drillthroughs/table_drills.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/drillthroughs/table_drills.cy.spec.js
@@ -492,7 +492,7 @@ describe("scenarios > visualizations > drillthroughs > table_drills > nulls", ()
});
it("should display proper drills on a datetime cell click when there is no value (metabase#44101)", () => {
- const CANCELLED_AT_INDEX = 9;
+ const CANCELLED_AT_INDEX = 10;
H.openTable({ table: ACCOUNTS_ID, limit: 1 });
// eslint-disable-next-line metabase/no-unsafe-element-filtering
diff --git a/e2e/test/scenarios/visualizations-tabular/table.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/table.cy.spec.js
index 6de5ab68831..9efe308aef1 100644
--- a/e2e/test/scenarios/visualizations-tabular/table.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/table.cy.spec.js
@@ -788,7 +788,7 @@ describe("scenarios > visualizations > table > dashboards context", () => {
H.tableHeaderClick("Rating");
// Verify rows don't overlap by checking their bounding rects
- H.tableInteractive()
+ H.tableInteractiveBody()
.find("[role=row]")
.then(($rows) => {
const rects = $rows
@@ -798,14 +798,14 @@ describe("scenarios > visualizations > table > dashboards context", () => {
// Each row's top should equal the previous row's bottom (no overlap)
for (let i = 1; i < rects.length; i++) {
- expect(rects[i].top).to.equal(rects[i - 1].bottom);
+ expect(rects[i].top).to.be.closeTo(rects[i - 1].bottom, 0.001);
}
});
// Sort again (descending) to verify heights update on subsequent sorts
H.tableHeaderClick("Rating");
- H.tableInteractive()
+ H.tableInteractiveBody()
.find("[role=row]")
.then(($rows) => {
const rects = $rows
@@ -814,7 +814,7 @@ describe("scenarios > visualizations > table > dashboards context", () => {
.sort((a, b) => a.top - b.top);
for (let i = 1; i < rects.length; i++) {
- expect(rects[i].top).to.equal(rects[i - 1].bottom);
+ expect(rects[i].top).to.be.closeTo(rects[i - 1].bottom, 0.001);
}
});
});
@@ -1167,11 +1167,10 @@ describe("scenarios > visualizations > table > conditional formatting", () => {
"is true",
);
- cy.findByRole("gridcell", { name: "true" }).should(
- "have.css",
- "background-color",
- "rgba(80, 158, 227, 0.65)",
- );
+ H.tableInteractiveBody()
+ .findByRole("gridcell", { name: "true" })
+ .findByTestId("body-cell-container")
+ .should("have.css", "background-color", "rgba(80, 158, 227, 0.65)");
});
});
});
@@ -1213,7 +1212,7 @@ describe("scenarios > visualizations > table > time formatting (#11398)", () =>
});
// And you should find the result
- cy.findByRole("gridcell").findByText("18:34:00");
+ cy.findByRole("gridcell", { name: "18:34:00" });
cy.findByTestId("column-formatting-settings").within(() => {
// Add millisecond display and change back to 12 hours
@@ -1222,7 +1221,7 @@ describe("scenarios > visualizations > table > time formatting (#11398)", () =>
});
// And you should find the result
- cy.findByRole("gridcell").findByText("6:34:00.000 PM");
+ cy.findByRole("gridcell", { name: "6:34:00.000 PM" });
});
});
diff --git a/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.tsx b/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.tsx
index 248e3e7ae6b..48ff4872c10 100644
--- a/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.tsx
+++ b/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.tsx
@@ -64,13 +64,13 @@ export const BodyCell = memo(function BodyCell<TValue>({
return (
<BaseCell
- role="gridcell"
align={align}
isSelected={isSelected}
className={cx(S.root, className, {
[S.pill]: variant === "pill",
})}
backgroundColor={backgroundColor}
+ data-testid="body-cell-container"
>
{formattedValue != null ? (
<div
diff --git a/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.tsx b/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.tsx
index c8dbafc7ff0..474bff3d78c 100644
--- a/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.tsx
+++ b/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.tsx
@@ -257,6 +257,7 @@ export const DataGrid = function DataGrid<TData>({
<div
ref={headerRef}
data-testid="table-header"
+ role="rowgroup"
className={cx(S.headerContainer, classNames?.headerContainer)}
style={{
backgroundColor: stickyElementsBackgroundColor,
@@ -286,6 +287,7 @@ export const DataGrid = function DataGrid<TData>({
) : (
<div
data-testid="table-body"
+ role="rowgroup"
className={cx(
S.bodyContainer,
{
diff --git a/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.unit.spec.tsx b/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.unit.spec.tsx
index 2d70d12cbd7..29ab97f8141 100644
--- a/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.unit.spec.tsx
+++ b/frontend/src/metabase/data-grid/components/DataGrid/DataGrid.unit.spec.tsx
@@ -6,6 +6,7 @@ import {
mockGetBoundingClientRect,
renderWithProviders,
screen,
+ within,
} from "__support__/ui";
import {
type ColumnOptions,
@@ -436,4 +437,22 @@ describe("DataGrid", () => {
expect(lines[1]).toBe("Item 1\tElectronics");
expect(lines[2]).toBe("Item 2\tClothing");
});
+
+ it("uses correct ARIA roles for grid structure (#70547)", () => {
+ renderWithProviders(<TestDataGrid />);
+
+ const rows = within(screen.getByRole("grid")).getAllByRole("row");
+ expect(rows.length).toBeGreaterThan(1);
+
+ const headerRow = rows[0];
+ const bodyRows = rows.slice(1);
+
+ const columnHeaders = within(headerRow).getAllByRole("columnheader");
+ expect(columnHeaders.length).toBeGreaterThan(0);
+
+ bodyRows.forEach((row) => {
+ const cells = within(row).getAllByRole("gridcell");
+ expect(cells.length).toBeGreaterThan(0);
+ });
+ });
});
diff --git a/frontend/src/metabase/data-grid/components/DataGridHeader/DataGridHeader.tsx b/frontend/src/metabase/data-grid/components/DataGridHeader/DataGridHeader.tsx
index 19b6abc1b79..e7b1a5ed1b2 100644
--- a/frontend/src/metabase/data-grid/components/DataGridHeader/DataGridHeader.tsx
+++ b/frontend/src/metabase/data-grid/components/DataGridHeader/DataGridHeader.tsx
@@ -35,6 +35,7 @@ export const DataGridHeader = <TData,>({
return (
<div
className={cx(S.row, classNames?.row)}
+ role="row"
style={{
backgroundColor,
paddingLeft,
@@ -69,6 +70,7 @@ export const DataGridHeader = <TData,>({
return (
<div
key={header.id}
+ role="columnheader"
style={columnPositionStyles}
data-header-id={header.id}
>
diff --git a/frontend/src/metabase/data-grid/components/DataGridRow/DataGridRow.tsx b/frontend/src/metabase/data-grid/components/DataGridRow/DataGridRow.tsx
index 1a2ce339a7b..1677a752881 100644
--- a/frontend/src/metabase/data-grid/components/DataGridRow/DataGridRow.tsx
+++ b/frontend/src/metabase/data-grid/components/DataGridRow/DataGridRow.tsx
@@ -88,6 +88,7 @@ export const DataGridRow = <TData,>({
return (
<div
key={cell.id}
+ role="gridcell"
aria-selected={selection.isCellSelected(cell)}
data-column-id={column.origin.id}
data-selectable-cell={isSelectable ? "" : undefined}
diff --git a/frontend/src/metabase/data-grid/components/HeaderCell/HeaderCell.tsx b/frontend/src/metabase/data-grid/components/HeaderCell/HeaderCell.tsx
index 1e82bc9196b..3f0b902d982 100644
--- a/frontend/src/metabase/data-grid/components/HeaderCell/HeaderCell.tsx
+++ b/frontend/src/metabase/data-grid/components/HeaderCell/HeaderCell.tsx
@@ -67,7 +67,6 @@ export const HeaderCellWrapper = ({
})}
hasHover={false}
align={align}
- role="columnheader"
data-testid="header-cell"
>
{children}