Skip to content

Commit

Permalink
Fix for if table.body is null which it could be because browser exten…
Browse files Browse the repository at this point in the history
…sion applies table-sort to all tables.
  • Loading branch information
LeeWannacott committed May 21, 2023
1 parent 084f9f1 commit 71cfe1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
return sortableTable.querySelector("tbody");
}
} else {
// if <tr> or <td> exists below <thead> the browser will make <tbody>
return sortableTable.querySelector("tbody");
}
}
Expand Down Expand Up @@ -111,6 +112,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
body: getTableBody(sortableTable),
head: sortableTable.querySelector("thead"),
};
if(table.body == null){ return }
table.headers = table.head.querySelectorAll("th");
table.rows = table.body.querySelectorAll("tr");

Expand Down
4 changes: 2 additions & 2 deletions test/missingTableTags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("test no missing table tags - (user has put <tbody> and <thead>)", () => {
).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]);
});

test("test with missing <tbody> tag - (tbody and thead exist)", () => {
test("test with missing <tbody> tag - thead exist", () => {
expect(
createTestTableMissingBodyTag([
"Echo",
Expand All @@ -37,7 +37,7 @@ test("test with missing <thead> tag)", () => {
).toStrictEqual(["Alpha", "Bravo", "Charlie", "Delta", "Echo"]);
});

test("test with missing <tbody> and <thead> tags - (tbody and thead exist)", () => {
test("test with missing <tbody> and <thead> tags", () => {
expect(
createTestTableMissingBodyAndHeadTag([
"Echo",
Expand Down

0 comments on commit 71cfe1e

Please sign in to comment.