Skip to content

Commit

Permalink
feature: Control element is now optional
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zipper committed Nov 1, 2023
1 parent 631b28c commit 99adefb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/CollapsableExtLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class CollapsableExtLink {
this.extLink.addEventListener('click', this.listener)
}

public toggleClass(): void {
public toggleState(): void {
const { options } = this.collapsable

this.extLink.classList.toggle(options.classNames.externalLinkActive, this.collapsableItem.isExpanded)
Expand Down
4 changes: 2 additions & 2 deletions src/CollapsableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class CollapsableItem {
const controlElements = element.querySelectorAll<HTMLElement>(collapsable.options.control)
const boxElements = element.querySelectorAll<HTMLElement>(collapsable.options.box)

if (!controlElements.length || !boxElements.length) {
if (!boxElements.length) {
throw new Error(`Collapsable: Missing control or box element.'`)
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class CollapsableItem {
this._isExpanded = action === 'expand'

const extLinks = this.collapsable.getExtLinkById(this.id)
extLinks.forEach((extLink) => extLink.toggleClass())
extLinks.forEach((extLink) => extLink.toggleState())

this.controlInteractiveElements.forEach((link) => link.setAttribute('aria-expanded', String(action === 'expand')))
this.boxElements.forEach((box) => {
Expand Down

0 comments on commit 99adefb

Please sign in to comment.