Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/ui-kit/experimental/aria/abstract-grid/abstract-row.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ describe("AbstractRow", () => {
]);
});

it("populates rowheaders and columnheaders with their respective cells", () => {
const row = buildRow([
{ role: "columnheader", key: "col" },
{ role: "rowheader", key: "row" },
{ role: "gridcell", key: "a" },
{ role: "gridcell", key: "b" },
]);

const abstractRow = new AbstractRow(row);

expect(abstractRow.rowheaders.map((c) => c.key)).toEqual(["row"]);
expect(abstractRow.columnheaders.map((c) => c.key)).toEqual(["col"]);
});

it("reuses the same AbstractCell instances in rowheaders/columnheaders as in cells", () => {
const row = buildRow([
{ role: "columnheader", key: "col" },
{ role: "rowheader", key: "row" },
{ role: "gridcell", key: "a" },
]);

const abstractRow = new AbstractRow(row);

const rowheaderInCells = abstractRow.cells.find((c) => c.key === "row");
const columnheaderInCells = abstractRow.cells.find((c) => c.key === "col");

expect(abstractRow.rowheaders[0]).toBe(rowheaderInCells);
expect(abstractRow.columnheaders[0]).toBe(columnheaderInCells);
});

it("addCell appends a cell to the cells collection", () => {
const row = buildRow([{ role: "gridcell", key: "a" }]);
const abstractRow = new AbstractRow(row);
Expand Down
6 changes: 3 additions & 3 deletions src/ui-kit/experimental/aria/abstract-grid/abstract-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AbstractRow {

this._setRowHeaders(cells, role);

return accumulator.concat(this._getCellsByRole(node, role));
return accumulator.concat(cells);
}, []);
}

Expand All @@ -43,9 +43,9 @@ export class AbstractRow {

private _setRowHeaders(cells: AbstractCell[], role: CellRole): void {
if (role === "rowheader") {
this.rowheaders.concat(cells);
this.rowheaders = this.rowheaders.concat(cells);
} else if (role === "columnheader") {
this.columnheaders.concat(cells);
this.columnheaders = this.columnheaders.concat(cells);
Comment thread
fpigeonjr marked this conversation as resolved.
} else {
return;
}
Expand Down
Loading