Hit esc to navigate back after opening a bubble

This commit is contained in:
Jason Zimdars
2024-12-19 16:22:01 -06:00
parent 53671bb1df
commit 1530b76af8
2 changed files with 18 additions and 1 deletions
@@ -0,0 +1,17 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
click(event) {
if (this.#isClickable && !this.#shouldIgnore(event)) {
this.element.click()
}
}
#shouldIgnore(event) {
return event.defaultPrevented || event.target.closest("input, textarea")
}
get #isClickable() {
return getComputedStyle(this.element).pointerEvents !== "none"
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
<% content_for :header do %>
<nav>
<%= link_to "#", class: "btn flex-item-justify-start", data: { controller: "back-navigation", back_navigation_fallback_destination_value: bubbles_path(bucket_id: @bubble.bucket) } do %>
<%= link_to "#", class: "btn flex-item-justify-start", data: { controller: "hotkey back-navigation", action: "keydown.esc@document->hotkey#click", back_navigation_fallback_destination_value: bubbles_path(bucket_id: @bubble.bucket) } do %>
<%= image_tag "arrow-left.svg", aria: { hidden: true }, size: 24 %>
<span class="for-screen-reader">Back</span>
<% end %>