Skip to content

Commit

Permalink
Merge pull request #993 from GatherPress/fix-dropdown
Browse files Browse the repository at this point in the history
Fix dropdown issue.
  • Loading branch information
mauteri authored Jan 12, 2025
2 parents dbab3dd + c24087e commit b7011ba
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/blocks/dropdown/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '6914dbac1bfbed207524', 'type' => 'module');
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => 'a49f590a6fe2fabb03ff', 'type' => 'module');
2 changes: 1 addition & 1 deletion build/blocks/dropdown/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/blocks/modal-manager/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '66b0f394a1cf075bfc1f', 'type' => 'module');
<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '2e97c0ab749d5158e4db', 'type' => 'module');
2 changes: 1 addition & 1 deletion build/blocks/modal-manager/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/blocks/dropdown/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const { actions } = store('gatherpress', {
// Set up close handlers
element.ref.cleanupCloseHandlers = setupCloseHandlers(
'.wp-block-gatherpress-dropdown__menu',
'.wp-block-gatherpress-dropdown__menu',
null,
(dropdown) => {
// Close the dropdown and clean up
dropdown.classList.remove('gatherpress--is-visible');
Expand Down
21 changes: 13 additions & 8 deletions src/helpers/interactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,19 @@ export function setupCloseHandlers(elementSelector, contentSelector, onClose) {
`${elementSelector}.gatherpress--is-visible`
);
openElements.forEach((element) => {
const content = element.querySelector(contentSelector);

// Close the element if clicked outside its content.
if (
element.contains(event.target) && // Click is inside the element.
!content.contains(event.target) // Click is NOT inside the content.
) {
handleClose(element);
if (contentSelector) {
const content = element.querySelector(contentSelector);
if (
element.contains(event.target) &&
!content.contains(event.target)
) {
handleClose(element);
}
} else {
const parentContainer = element.parentElement;
if (!parentContainer.contains(event.target)) {
handleClose(element);
}
}
});
};
Expand Down

0 comments on commit b7011ba

Please sign in to comment.