Skip to content

Commit

Permalink
fix: Expand/Collapse events triggered only on state change
Browse files Browse the repository at this point in the history
Expand and collapse events are now dispatched only when the action is actually performed. For example, if an item is already expanded, calling the expand method will not dispatch `expand.collapsable` or `expanded.collapsable` events, since no action occurred. Previously, these events were dispatched regardless of the state. The same behavior change has been applied to collapse-related events.
  • Loading branch information
zipper committed Oct 23, 2024
1 parent b2c35c9 commit 77c16a3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/CollapsableItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ export class CollapsableItem {
}

public expand(collapsableEvent: any, data: any, force: boolean): boolean {
// If the item is already expanded return
if (this.isExpanded) {
return false
}

const { options } = this.collapsable
const expandedItem = this.collapsable.getExpanded()

Expand Down Expand Up @@ -223,9 +228,12 @@ export class CollapsableItem {
public collapse(collapsableEvent: any, data: any, force: boolean): boolean {
const { options } = this.collapsable

// If we can't collapse all & we are not promised to open something & there is only one opened box, we can't
// continue
if (!options.collapsableAll && !this.collapsable.promiseOpen && this.collapsable.getExpanded().length < 2) {
// If the item is not expanded, or if we can't collapse all & we are not promised to open something & there is
// only one opened box, we can't continue
if (
!this.isExpanded ||
(!options.collapsableAll && !this.collapsable.promiseOpen && this.collapsable.getExpanded().length < 2)
) {
return false
}

Expand Down

0 comments on commit 77c16a3

Please sign in to comment.