Skip to content

Commit 27157d7

Browse files
FIX: Handle auxclick event on topic list (#34408)
This commit adds a new `auxclick` event handler to the topic list item, which calls the same `click` handler. The `auxclick` event is triggered by auxiliary mouse buttons, such as the middle mouse button. This fixes an issue where using the middle mouse button on a topic card in Horizon anywhere but the topic title would not open the topic in a new tab. Normal topic list click functionality remains unchanged. c.f. https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event
1 parent 62ceb97 commit 27157d7

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

app/assets/javascripts/discourse/app/components/topic-list/item.gjs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,57 +141,57 @@ export default class Item extends Component {
141141
}
142142

143143
@action
144-
click(e) {
144+
click(event) {
145145
applyBehaviorTransformer(
146146
"topic-list-item-click",
147147
() => {
148148
if (
149-
e.target.classList.contains("raw-topic-link") ||
150-
e.target.classList.contains("post-activity") ||
151-
e.target.classList.contains("badge-posts")
149+
event.target.classList.contains("raw-topic-link") ||
150+
event.target.classList.contains("post-activity") ||
151+
event.target.classList.contains("badge-posts")
152152
) {
153-
if (wantsNewWindow(e)) {
153+
if (wantsNewWindow(event)) {
154154
return;
155155
}
156156

157-
e.preventDefault();
158-
this.navigateToTopic(this.args.topic, e.target.href);
157+
event.preventDefault();
158+
this.navigateToTopic(this.args.topic, event.target.href);
159159
return;
160160
}
161161

162162
// make full row click target on mobile, due to size constraints
163163
if (
164164
this.site.mobileView &&
165-
e.target.matches(
165+
event.target.matches(
166166
".topic-list-data, .main-link, .right, .topic-item-stats, .topic-item-stats__category-tags, .discourse-tags"
167167
)
168168
) {
169-
if (wantsNewWindow(e)) {
169+
if (wantsNewWindow(event)) {
170170
return;
171171
}
172172

173-
e.preventDefault();
173+
event.preventDefault();
174174
this.navigateToTopic(this.args.topic, this.args.topic.lastUnreadUrl);
175175
return;
176176
}
177177
},
178178
{
179+
event,
179180
topic: this.args.topic,
180-
event: e,
181181
navigateToTopic: this.navigateToTopic,
182182
}
183183
);
184184
}
185185

186186
@action
187-
keyDown(e) {
187+
keyDown(event) {
188188
if (
189-
e.key === "Enter" &&
190-
(e.target.classList.contains("post-activity") ||
191-
e.target.classList.contains("badge-posts"))
189+
event.key === "Enter" &&
190+
(event.target.classList.contains("post-activity") ||
191+
event.target.classList.contains("badge-posts"))
192192
) {
193-
e.preventDefault();
194-
this.navigateToTopic(this.args.topic, e.target.href);
193+
event.preventDefault();
194+
this.navigateToTopic(this.args.topic, event.target.href);
195195
}
196196
}
197197

@@ -238,6 +238,7 @@ export default class Item extends Component {
238238
{{this.highlightIfNeeded}}
239239
{{on "keydown" this.keyDown}}
240240
{{on "click" this.click}}
241+
{{on "auxclick" this.click}}
241242
data-topic-id={{@topic.id}}
242243
role={{this.role}}
243244
aria-level={{this.ariaLevel}}

themes/horizon/javascripts/discourse/initializers/topic-list-columns.gjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export default {
117117
metaKey: event.metaKey,
118118
shiftKey: event.shiftKey,
119119
button: event.button,
120+
which: event.which,
120121
bubbles: true,
121122
cancelable: true,
122123
})

0 commit comments

Comments
 (0)