Skip to content

Commit 856022e

Browse files
niklasmohrinjooooosef
authored andcommitted
Dispatch a click event on an off-DOM <a> element when clicking on .table-seamless-links rows (e-valuation#2349)
This brings the interaction closer to clicking on an actual `a` tag and enables Ctrl-Click again. Having an `a` in there is still not feasible, because we cannot have any elements between `tr` and `td`.
1 parent d78948a commit 856022e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

evap/evaluation/templates/base.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,13 @@
181181

182182
// activate clickable hover tables
183183
document.querySelectorAll(".table-seamless-links [data-url]").forEach(row => {
184-
row.addEventListener("click", () => {
185-
window.location.assign(row.dataset.url);
184+
row.addEventListener("click", event => {
185+
// We navigate via the <a> tag to enable browser behavior for Ctrl-Click. We cannot insert an actual
186+
// <a> tag, because there cannot be any non-table tags between for example <tbody> and <tr>.
187+
const anchor = document.createElement("a");
188+
anchor.href = row.dataset.url;
189+
// As `event` is bound to `row`, we need to clone it.
190+
anchor.dispatchEvent(new event.constructor(event.type, event));
186191
});
187192
});
188193

evap/static/scss/components/_tables.scss

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ $table-colors: (
3535
padding-bottom: 0.4rem;
3636
}
3737

38-
.table-seamless-links td {
39-
overflow: hidden;
38+
.table-seamless-links {
39+
// Disable outline on cell after Ctrl-Click.
40+
-moz-user-select: none;
41+
td {
42+
overflow: hidden;
43+
}
4044
}
4145

4246
// Hoverable rows

0 commit comments

Comments
 (0)