a11yist/app/javascript/controllers/hotkey_controller.js
david 016985d2cb
Some checks failed
/ Run tests (push) Failing after 1m44s
/ Run system tests (push) Failing after 1m46s
/ Build, push and deploy image (push) Has been skipped
Add hot keys feature
2024-11-09 03:54:25 +01:00

22 lines
635 B
JavaScript

import { Controller } from "@hotwired/stimulus"
import { install } from '@github/hotkey'
// Connects to data-controller="hotkey"
export default class extends Controller {
connect() {
// Install all the hotkeys on the page
console.log("hotkey connect", this.element)
this.element.addEventListener("turbo:load", this.handleTurboLoad)
for (const el of this.element.parentNode.querySelectorAll('[data-hotkey]')) {
console.log(el)
install(el)
}
}
handleTurboLoad(event) {
for (const el of event.getTarget().querySelectorAll('[data-hotkey]')) {
console.log(el)
install(el)
}
}
}