Skip to content

Commit a115309

Browse files
authored
Fix the click behavior for <tr> and <td> with [data-href] (#17388)
1 parent 960c322 commit a115309

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

web_src/js/features/common-global.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,19 @@ export function initGlobalCommon() {
119119
$($(this).data('target')).slideToggle(100);
120120
});
121121

122-
// make table <tr> element clickable like a link
123-
$('tr[data-href]').on('click', function () {
124-
window.location = $(this).data('href');
125-
});
126-
127-
// make table <td> element clickable like a link
128-
$('td[data-href]').click(function () {
129-
window.location = $(this).data('href');
122+
// make table <tr> and <td> elements clickable like a link
123+
$('tr[data-href], td[data-href]').on('click', function (e) {
124+
const href = $(this).data('href');
125+
if (e.target.nodeName === 'A') {
126+
// if a user clicks on <a>, then the <tr> or <td> should not act as a link.
127+
return;
128+
}
129+
if (e.ctrlKey || e.metaKey) {
130+
// ctrl+click or meta+click opens a new window in modern browsers
131+
window.open(href);
132+
} else {
133+
window.location = href;
134+
}
130135
});
131136
}
132137

0 commit comments

Comments
 (0)