Close list dropdown when clicking outside of it
Some checks failed
CI / Lint (pull_request) Failing after 25s
CI / Test (pull_request) Successful in 34s

This commit is contained in:
2026-03-13 13:40:28 +04:00
parent a8613ab81a
commit b2220b8310
3 changed files with 32 additions and 2 deletions

View File

@@ -49,7 +49,12 @@ export default class PlaceDetails extends Component {
} }
@action @action
toggleLists() { toggleLists(event) {
// Prevent this click from propagating to the document listener
// which handles the "click outside" logic.
if (event) {
event.stopPropagation();
}
this.showLists = !this.showLists; this.showLists = !this.showLists;
} }

View File

@@ -4,6 +4,7 @@ import { action } from '@ember/object';
import { on } from '@ember/modifier'; import { on } from '@ember/modifier';
import { fn } from '@ember/helper'; import { fn } from '@ember/helper';
import Icon from './icon'; import Icon from './icon';
import onClickOutside from '../modifiers/on-click-outside';
export default class PlaceListsManager extends Component { export default class PlaceListsManager extends Component {
@service storage; @service storage;
@@ -58,7 +59,10 @@ export default class PlaceListsManager extends Component {
} }
<template> <template>
<div class="place-lists-manager"> <div
class="place-lists-manager"
{{onClickOutside @onClose}}
>
<div class="list-item master-toggle"> <div class="list-item master-toggle">
<label> <label>
<input <input

View File

@@ -0,0 +1,21 @@
import { modifier } from 'ember-modifier';
export default modifier((element, [callback]) => {
const handler = (event) => {
// Check if the click target is contained within the element
if (element && !element.contains(event.target)) {
callback(event);
}
};
// Delay attaching the listener to avoid catching the opening click
// (using a microtask or setTimeout 0)
const timer = setTimeout(() => {
document.addEventListener('click', handler);
}, 0);
return () => {
clearTimeout(timer);
document.removeEventListener('click', handler);
};
});