Files
openfoodnetwork/app/webpacker/controllers/popout_controller.js
David Cook 4560e3728c Show popout on click or down key
It looks like a select drop-down, so it can behave like one too.
2023-11-28 10:44:34 +11:00

27 lines
694 B
JavaScript

import { Controller } from "stimulus";
// Allows a form section to "pop out" and show additional options
export default class PopoutController extends Controller {
static targets = ["button", "dialog"];
connect() {
this.first_input = this.dialogTarget.querySelector("input");
// Show when click or down-arrow on button
this.buttonTarget.addEventListener("click", this.show.bind(this));
this.buttonTarget.addEventListener("keydown", this.showIfDownArrow.bind(this));
}
show(e) {
this.dialogTarget.style.display = "block";
this.first_input.focus();
e.preventDefault();
}
showIfDownArrow(e) {
if (e.keyCode == 40) {
this.show(e);
}
}
}