Previews

No matching results.

Pages

No matching results.

x
1
<form class="button_to" method="post" action="/lookbook/home/index"><button class="btn" data-controller="hotkey" data-action="keydown.w@document->hotkey#click" data-turbo-confirm="Are you sure?" type="submit">Press w to click</button><input type="hidden" name="authenticity_token" value="K-c_-OVMOJ71f8zIZdzRxHsZCt-VKcl3NsJv3bzcasKkegKIEC1VbIgYhyclRKppnB1ReN0MDTv-bu4qJI1xyg" autocomplete="off" /></form>
1
<%= button_to "Press w to click", nil, class: "btn", data: { controller: "hotkey", action: "keydown.w@document->hotkey#click", turbo_confirm: "Are you sure?" } %>
CSS is not required or multiple files are needed, check the notes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
click(event) {
if (this.#isClickable && !this.#shouldIgnore(event)) {
event.preventDefault(); this.element.click()
}
}
focus(event) {
if (this.#isClickable && !this.#shouldIgnore(event)) {
event.preventDefault(); this.element.focus()
}
}
#shouldIgnore(event) {
return event.defaultPrevented || event.target.closest("input, textarea")
}
get #isClickable() {
return getComputedStyle(this.element).pointerEvents !== "none"
}
}