From 056e380f720d3138ac98f8e71fbbdcf3167f7317 Mon Sep 17 00:00:00 2001 From: ishikawa999 <14245262+ishikawa999@users.noreply.github.com> Date: Tue, 4 Aug 2026 10:03:28 +0900 Subject: [PATCH] Close the actions dropdown after copying a link --- app/helpers/application_helper.rb | 3 ++- app/javascript/controllers/clipboard_controller.js | 9 +++------ app/javascript/controllers/dropdown_controller.js | 4 ++++ test/system/copy_to_clipboard_test.rb | 6 ++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8566ce026..41f23b881 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -905,7 +905,8 @@ module ApplicationHelper :data => {:action => "click->dropdown#toggle"}) items = content_tag('span', content, :class => 'dropdown-items') content = content_tag('span', items, :class => 'dropdown-content hidden', :data => {:dropdown_target => "content"}) - content_tag('span', trigger + content, :class => 'dropdown', :data => {:controller => "dropdown"}) + content_tag('span', trigger + content, :class => 'dropdown', + :data => {:controller => "dropdown", :action => "clipboard:copied->dropdown#hide"}) end end diff --git a/app/javascript/controllers/clipboard_controller.js b/app/javascript/controllers/clipboard_controller.js index 1ea07c446..f20dc87a5 100644 --- a/app/javascript/controllers/clipboard_controller.js +++ b/app/javascript/controllers/clipboard_controller.js @@ -23,12 +23,9 @@ export default class extends Controller { copyText(e) { e.preventDefault(); - this.copy(e.currentTarget.dataset.clipboardText); - - const element = e.currentTarget.closest('.drdn.expanded'); - if (element !== null) { - element.classList.remove('expanded'); - } + this.copy(e.currentTarget.dataset.clipboardText).then(() => { + this.dispatch('copied', { bubbles: true }); + }); } copy(text) { diff --git a/app/javascript/controllers/dropdown_controller.js b/app/javascript/controllers/dropdown_controller.js index 9a3ff0aed..f60d984aa 100644 --- a/app/javascript/controllers/dropdown_controller.js +++ b/app/javascript/controllers/dropdown_controller.js @@ -30,6 +30,10 @@ export default class extends Controller { return } + this.hide() + } + + hide() { this.contentTarget.classList.add("hidden") document.removeEventListener("click", this.closeBinding) document.removeEventListener("keydown", this.closeBinding) diff --git a/test/system/copy_to_clipboard_test.rb b/test/system/copy_to_clipboard_test.rb index b56490b2b..fea524ea6 100644 --- a/test/system/copy_to_clipboard_test.rb +++ b/test/system/copy_to_clipboard_test.rb @@ -28,6 +28,9 @@ class CopyToClipboardSystemTest < ApplicationSystemTestCase first('.contextual span.icon-actions').click find('.contextual .dropdown-items a.icon-copy-link').click + # The dropdown should be closed after copying + assert_no_selector '.contextual .dropdown-items' + # Paste the value copied to the clipboard into the textarea to get and test first('.icon-edit').click find('textarea#issue_notes').send_keys([modifier_key, 'v']) @@ -42,6 +45,9 @@ class CopyToClipboardSystemTest < ApplicationSystemTestCase first('#note-2 .icon-actions').click first('#note-2 .dropdown-items a.icon-copy-link').click + # The dropdown should be closed after copying + assert_no_selector '#note-2 .dropdown-items' + # Paste the value copied to the clipboard into the textarea to get and test first('.icon-edit').click find('textarea#issue_notes').send_keys([modifier_key, 'v']) -- 2.55.0