+ protected dropdownOptions: WeakMap<HTMLElement, HandleDropdownParams> = new WeakMap();
+ protected openDropdowns: Set<HTMLElement> = new Set();
+
+ constructor() {
+ this.onMenuMouseOver = this.onMenuMouseOver.bind(this);
+
+ window.addEventListener('click', (event: MouseEvent) => {
+ const target = event.target as HTMLElement;
+ this.closeAllNotContainingElement(target);
+ });
+ }
+
+ protected closeAllNotContainingElement(element: HTMLElement): void {
+ for (const menu of this.openDropdowns) {
+ if (!menu.parentElement?.contains(element)) {
+ this.closeDropdown(menu);
+ }
+ }
+ }
+
+ protected onMenuMouseOver(event: MouseEvent): void {
+ const target = event.target as HTMLElement;
+ this.closeAllNotContainingElement(target);
+ }
+
+ /**
+ * Close all open dropdowns.
+ */
+ public closeAll(): void {
+ for (const menu of this.openDropdowns) {
+ this.closeDropdown(menu);
+ }
+ }
+
+ protected closeDropdown(menu: HTMLElement): void {