2022-10-24 16:43:18 +02:00
|
|
|
import { ApplicationController } from './application_controller';
|
|
|
|
import { toggle, toggleExpandIcon } from '@utils';
|
|
|
|
|
|
|
|
export class ExpandController extends ApplicationController {
|
|
|
|
static targets = ['content', 'icon'];
|
|
|
|
|
|
|
|
declare readonly contentTarget: HTMLElement;
|
|
|
|
declare readonly iconTarget: HTMLElement;
|
|
|
|
|
|
|
|
toggle(event: Event) {
|
2023-04-28 10:33:01 +02:00
|
|
|
const target = event.currentTarget as HTMLButtonElement;
|
|
|
|
|
2022-10-24 16:43:18 +02:00
|
|
|
event.preventDefault();
|
|
|
|
toggle(this.contentTarget);
|
|
|
|
toggleExpandIcon(this.iconTarget);
|
2023-04-28 10:33:01 +02:00
|
|
|
if (this.contentTarget.classList.contains('hidden')) {
|
|
|
|
target.setAttribute('aria-expanded', 'false');
|
|
|
|
} else {
|
|
|
|
target.setAttribute('aria-expanded', 'true');
|
|
|
|
}
|
2022-10-24 16:43:18 +02:00
|
|
|
}
|
|
|
|
}
|