Skip to content

Commit

Permalink
remove container of flash message after it is closed, so that it does…
Browse files Browse the repository at this point in the history
…n't become visible with next flash message
  • Loading branch information
toy committed Dec 18, 2024
1 parent 5d4fe3b commit 57a392e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/components/op_primer/flash_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion frontend/src/stimulus/controllers/flash.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
});
}
}

0 comments on commit 57a392e

Please sign in to comment.