diff --git a/app/components/op_primer/flash_component.erb b/app/components/op_primer/flash_component.html.erb similarity index 100% rename from app/components/op_primer/flash_component.erb rename to app/components/op_primer/flash_component.html.erb diff --git a/app/components/op_primer/flash_component.rb b/app/components/op_primer/flash_component.rb index fed84bf511f7..15a445c03316 100644 --- a/app/components/op_primer/flash_component.rb +++ b/app/components/op_primer/flash_component.rb @@ -38,6 +38,8 @@ def initialize(**system_arguments) system_arguments[:test_selector] ||= "op-primer-flash-message" system_arguments[:dismiss_scheme] ||= :remove system_arguments[:dismiss_label] ||= I18n.t(:button_close) + system_arguments[:data] ||= {} + system_arguments[:data]["flash-target"] = "flash" @autohide = system_arguments[:scheme] == :success && system_arguments[:dismiss_scheme] != :none diff --git a/frontend/src/stimulus/controllers/flash.controller.ts b/frontend/src/stimulus/controllers/flash.controller.ts index d09aad6d196d..f97ad77f4d3c 100644 --- a/frontend/src/stimulus/controllers/flash.controller.ts +++ b/frontend/src/stimulus/controllers/flash.controller.ts @@ -11,9 +11,10 @@ export default class FlashController extends ApplicationController { static targets = [ 'item', + 'flash', // only to detect removal ]; - declare readonly itemTargets:HTMLElement; + declare readonly itemTargets:HTMLElement[]; reloadPage() { window.location.reload(); @@ -25,4 +26,12 @@ export default class FlashController extends ApplicationController { setTimeout(() => element.remove(), SUCCESS_AUTOHIDE_TIMEOUT); } } + + flashTargetDisconnected() { + this.itemTargets.forEach((target:HTMLElement) => { + if (target.innerHTML === '') { + target.remove(); + } + }); + } }