Skip to content

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

FIX: Keyboard shortcuts closing table builder modal (#26278)

Keegan George2129e9e37a97
diff --git a/app/assets/javascripts/discourse/app/components/modal/spreadsheet-editor.gjs b/app/assets/javascripts/discourse/app/components/modal/spreadsheet-editor.gjs
index e746dac3dfc..086a1ea92ea 100644
--- a/app/assets/javascripts/discourse/app/components/modal/spreadsheet-editor.gjs
+++ b/app/assets/javascripts/discourse/app/components/modal/spreadsheet-editor.gjs
@@ -10,6 +10,7 @@ import DModalCancel from "discourse/components/d-modal-cancel";
import TextField from "discourse/components/text-field";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
+import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
import {
arrayToTable,
findTableRegex,
@@ -30,6 +31,12 @@ export default class SpreadsheetEditor extends Component {
constructor() {
super(...arguments);
this.loadJspreadsheet();
+ KeyboardShortcuts.pause();
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ KeyboardShortcuts.unpause();
}
get modalAttributes() {
diff --git a/spec/system/table_builder_spec.rb b/spec/system/table_builder_spec.rb
index 43a68974ebb..8eb2f15133d 100644
--- a/spec/system/table_builder_spec.rb
+++ b/spec/system/table_builder_spec.rb
@@ -142,5 +142,17 @@ describe "Table Builder", type: :system do
expect(page).to have_css(".dialog-container .dialog-content")
end
end
+
+ it "should not accept default Discourse keyboard shortcuts" do
+ # Some default keyboard shortcuts like Shift + S bring up a modal overriding
+ # the table builder modal and therefore should not be accepted
+
+ topic_page.visit_topic(topic)
+ topic_page.find(".btn-edit-table", visible: :all).click
+ insert_table_modal.find_cell(0, 0)
+ insert_table_modal.send_keys(:shift, "s")
+ expect(page).to have_css(".insert-table-modal")
+ expect(page).to have_no_css(".share-topic-modal")
+ end
end
end