Skip to content

A platform for community discussion. Free, open, simple.

UX: Improve meta+click and meta+Enter events for topic list (#37281)

Penar Musaraja0dd97b1623d
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 82226602446..bc48a429411 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -5026,6 +5026,7 @@ en:
back: "%{shortcut} Back"
up_down: "%{shortcut} Move selection ↑ ↓"
open: "%{shortcut} Open selected topic"
+ open_new_window: "%{shortcut} Open selected topic in new tab/window"
next_prev: "%{shortcut} Next/previous section"
go_to_unread_post: "%{shortcut} Go to the first unread post"
application:
diff --git a/frontend/discourse/app/components/modal/keyboard-shortcuts-help.gjs b/frontend/discourse/app/components/modal/keyboard-shortcuts-help.gjs
index e6ad6152a2c..6a20bd75888 100644
--- a/frontend/discourse/app/components/modal/keyboard-shortcuts-help.gjs
+++ b/frontend/discourse/app/components/modal/keyboard-shortcuts-help.gjs
@@ -196,6 +196,9 @@ export default class KeyboardShortcutsHelp extends Component {
keys1: ["o"],
keys2: [ENTER],
}),
+ open_new_window: buildShortcut("navigation.open_new_window", {
+ keys1: [META, ENTER],
+ }),
next_prev: buildShortcut("navigation.next_prev", {
keys1: [SHIFT, "j"],
keys2: [SHIFT, "k"],
diff --git a/frontend/discourse/app/components/topic-list/item.gjs b/frontend/discourse/app/components/topic-list/item.gjs
index d304a15fe27..e3515884a4b 100644
--- a/frontend/discourse/app/components/topic-list/item.gjs
+++ b/frontend/discourse/app/components/topic-list/item.gjs
@@ -162,7 +162,8 @@ export default class Item extends Component {
@action
click(event) {
- if (this.args.bulkSelectEnabled) {
+ // when in bulk select mode, select/unselect the row (except when ctrl/meta+clicking)
+ if (this.args.bulkSelectEnabled && !wantsNewWindow(event)) {
event.preventDefault();
const topicNode = event.target.closest(".topic-list-item");
@@ -219,13 +220,11 @@ export default class Item extends Component {
@action
keyDown(event) {
- if (
- event.key === "Enter" &&
- (event.target.classList.contains("post-activity") ||
- event.target.classList.contains("badge-posts"))
- ) {
+ // We only handle cmd/meta+Enter to open topic in a new window here
+ // Simple Enter event for topic list is handled in keyboard-shortcuts (which triggers click() event)
+ if (event.key === "Enter" && wantsNewWindow(event)) {
event.preventDefault();
- this.navigateToTopic(this.args.topic, event.target.href);
+ window.open(this.args.topic.lastUnreadUrl, "_blank");
}
}
diff --git a/spec/system/page_objects/components/topic_list.rb b/spec/system/page_objects/components/topic_list.rb
index 0bb93ef8e03..7b3fadf9cdb 100644
--- a/spec/system/page_objects/components/topic_list.rb
+++ b/spec/system/page_objects/components/topic_list.rb
@@ -82,6 +82,10 @@ module PageObjects
find("#{topic_list_item_class(topic)} a.badge-posts").send_keys(:return)
end
+ def send_keys_to_topic(topic, *keys)
+ find("#{topic_list_item_class(topic)} a.raw-topic-link").send_keys(*keys)
+ end
+
def topic_list_item_class(topic)
"#{TOPIC_LIST_ITEM_SELECTOR}[data-topic-id='#{topic.id}']"
end
diff --git a/spec/system/topic_bulk_select_spec.rb b/spec/system/topic_bulk_select_spec.rb
index 45dcf0d3006..1b54911421e 100644
--- a/spec/system/topic_bulk_select_spec.rb
+++ b/spec/system/topic_bulk_select_spec.rb
@@ -400,6 +400,22 @@ describe "Topic bulk select", type: :system do
expect(topic_list).to have_checkbox_selected_on_row(1)
end
+
+ it "opens topic in new window when pressing meta+Enter" do
+ sign_in(admin)
+ visit("/latest")
+
+ topic_list_header.click_bulk_select_button
+
+ new_window =
+ window_opened_by do
+ find(".topic-list-item[data-topic-id='#{topics.last.id}'] a.raw-topic-link").send_keys(
+ %i[meta return],
+ )
+ end
+
+ within_window(new_window) { expect(topic_page).to have_topic_title(topics.last.title) }
+ end
end
context "when changing topic notification levels" do
diff --git a/spec/system/topic_list_focus_spec.rb b/spec/system/topic_list_spec.rb
similarity index 90%
rename from spec/system/topic_list_focus_spec.rb
rename to spec/system/topic_list_spec.rb
index 417610ccbec..200579083e3 100644
--- a/spec/system/topic_list_focus_spec.rb
+++ b/spec/system/topic_list_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-describe "Topic list focus", type: :system do
+describe "Topic list", type: :system do
fab!(:topics) { Fabricate.times(10, :post).map(&:topic) }
before_all do
@@ -107,4 +107,14 @@ describe "Topic list focus", type: :system do
expect(page).to have_css("body.navigation-topics")
expect(focussed_topic_id).to eq(oldest_topic.id)
end
+
+ it "opens topic in new window when pressing meta+Enter" do
+ visit("/latest")
+ expect(discovery.topic_list).to have_topics
+
+ new_window =
+ window_opened_by { discovery.topic_list.send_keys_to_topic(topics[5], %i[meta return]) }
+
+ within_window(new_window) { expect(topic).to have_topic_title(topics[5].title) }
+ end
end