Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 5-group-checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkarpieszuk committed Nov 15, 2023
2 parents eb46644 + 619ee62 commit 22027c1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/wpforms-multiselect-checkboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@
const handleInputClick = ( { target: input } ) => {
const isOpen = this.list.classList.toggle( 'open' );
input.setAttribute( 'aria-expanded', isOpen );
dispatchToggleEvent( isOpen );

if ( ! isOpen ) {
maybeFlushSearchInput();
Expand Down Expand Up @@ -561,6 +562,7 @@
maybeFlushSearchInput();
this.list.classList.remove( 'open', 'open-up' );
this.input.setAttribute( 'aria-expanded', false );
dispatchToggleEvent( false );
};

// Callback function to flush the search input.
Expand All @@ -573,6 +575,15 @@
this.search.dispatchEvent( new Event( 'input' ) );
};

// Dispatch a custom event to indicate whether the dropdown is open or not.
const dispatchToggleEvent = ( isOpen ) => {
const toggleEvent = new CustomEvent( 'wpforms_multiselect_checkbox_list_toggle', {
bubbles: true,
detail: { isOpen },
} );
element.dispatchEvent( toggleEvent );
};

// Bind event listeners.
this.input.addEventListener( 'click', handleInputClick );
this.input.addEventListener( 'keydown', handleInputFocus );
Expand Down

0 comments on commit 22027c1

Please sign in to comment.