From 631b28c32605f5a67a534d7dd27c2811e13fe243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0er=C3=BD?= Date: Wed, 1 Nov 2023 14:05:55 +0100 Subject: [PATCH 1/2] feature: Add `CollapsableEvent`s to `DocumentEventMap` as well --- src/CollapsableItem.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CollapsableItem.ts b/src/CollapsableItem.ts index 6a08324..dbac440 100644 --- a/src/CollapsableItem.ts +++ b/src/CollapsableItem.ts @@ -295,4 +295,12 @@ declare global { 'collapsed.collapsable': CollapsableEvent 'destroy.collapsable': CustomEvent } + + interface DocumentEventMap { + 'expand.collapsable': CollapsableEvent + 'expanded.collapsable': CollapsableEvent + 'collapse.collapsable': CollapsableEvent + 'collapsed.collapsable': CollapsableEvent + 'destroy.collapsable': CustomEvent + } } From e5b7303b1a688afcf5b9b1cbda265dc141e7217e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0er=C3=BD?= Date: Wed, 1 Nov 2023 14:07:37 +0100 Subject: [PATCH 2/2] feature: Control element is now optional The control element for `CollapsableItem` is now optional. If there is no control element, you can either expand / collapse the item programmatically from JS, or you can use an external link. --- src/CollapsableItem.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CollapsableItem.ts b/src/CollapsableItem.ts index dbac440..0073a43 100644 --- a/src/CollapsableItem.ts +++ b/src/CollapsableItem.ts @@ -41,7 +41,7 @@ export class CollapsableItem { const controlElements = element.querySelectorAll(collapsable.options.control) const boxElements = element.querySelectorAll(collapsable.options.box) - if (!controlElements.length || !boxElements.length) { + if (!boxElements.length) { throw new Error(`Collapsable: Missing control or box element.'`) }