Files
wallabag-mirror/assets/controllers/materialize/collapsible_controller.js
Yassine Guedidi bd6127b852 fixup! Convert reader action controls to buttons - prevent duplicate Enter activation
Stop Materialize keydown handling for native button collapsible headers while preserving native activation. Limit interception to the owning collapsible and remove the listener on disconnect.

This compatibility correction belongs to Convert reader action controls to buttons because native Enter activation would otherwise duplicate Materialize handling.
2026-11-16 16:32:44 +01:00

34 lines
922 B
JavaScript

import { Controller } from '@hotwired/stimulus';
import M from '@materializecss/materialize';
export default class extends Controller {
static values = {
accordion: { type: Boolean, default: true },
};
connect() {
this.instance = M.Collapsible.init(this.element, { accordion: this.accordionValue });
this.boundHandleKeydown = this.handleKeydown.bind(this);
this.element.addEventListener('keydown', this.boundHandleKeydown, true);
}
handleKeydown(event) {
if (event.key !== 'Enter' || !(event.target instanceof Element)) {
return;
}
const buttonHeader = event.target.closest('button.collapsible-header');
if (!buttonHeader || buttonHeader.closest('.collapsible') !== this.element) {
return;
}
event.stopPropagation();
}
disconnect() {
this.element.removeEventListener('keydown', this.boundHandleKeydown, true);
this.instance.destroy();
}
}