demarches-normaliennes/app/javascript/controllers/hide_target_controller.ts

20 lines
515 B
TypeScript
Raw Normal View History

2024-07-15 23:28:02 +02:00
import { Controller } from '@hotwired/stimulus';
export class HideTargetController extends Controller {
static targets = ['source', 'toHide'];
declare readonly toHideTargets: HTMLDivElement[];
declare readonly sourceTargets: HTMLInputElement[];
connect() {
this.sourceTargets.forEach((source) => {
source.addEventListener('click', this.handleInput.bind(this));
});
}
handleInput() {
this.toHideTargets.forEach((toHide) => {
toHide.classList.toggle('fr-hidden');
});
}
}