npm run serve:ssr funktioniert und Hamburger Menu bug fix
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, HostBinding, Input, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { AfterViewInit, Component, ElementRef, HostBinding, Input, OnDestroy, ViewChild, PLATFORM_ID, inject } from '@angular/core';
|
||||
import { isPlatformBrowser } from '@angular/common';
|
||||
import { createPopper, Instance as PopperInstance } from '@popperjs/core';
|
||||
|
||||
@Component({
|
||||
@@ -23,6 +24,8 @@ export class DropdownComponent implements AfterViewInit, OnDestroy {
|
||||
|
||||
@HostBinding('class.hidden') isHidden: boolean = true;
|
||||
|
||||
private platformId = inject(PLATFORM_ID);
|
||||
private isBrowser = isPlatformBrowser(this.platformId);
|
||||
private popperInstance: PopperInstance | null = null;
|
||||
isVisible: boolean = false;
|
||||
private clickOutsideListener: any;
|
||||
@@ -30,6 +33,8 @@ export class DropdownComponent implements AfterViewInit, OnDestroy {
|
||||
private hoverHideListener: any;
|
||||
|
||||
ngAfterViewInit() {
|
||||
if (!this.isBrowser) return;
|
||||
|
||||
if (!this.triggerEl) {
|
||||
console.error('Trigger element is not provided to the dropdown component.');
|
||||
return;
|
||||
@@ -58,6 +63,8 @@ export class DropdownComponent implements AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
private setupEventListeners() {
|
||||
if (!this.isBrowser) return;
|
||||
|
||||
if (this.triggerType === 'click') {
|
||||
this.triggerEl.addEventListener('click', () => this.toggle());
|
||||
} else if (this.triggerType === 'hover') {
|
||||
@@ -74,6 +81,8 @@ export class DropdownComponent implements AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
private removeEventListeners() {
|
||||
if (!this.isBrowser) return;
|
||||
|
||||
if (this.triggerType === 'click') {
|
||||
this.triggerEl.removeEventListener('click', () => this.toggle());
|
||||
} else if (this.triggerType === 'hover') {
|
||||
@@ -104,7 +113,7 @@ export class DropdownComponent implements AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
private handleClickOutside(event: MouseEvent) {
|
||||
if (!this.isVisible) return;
|
||||
if (!this.isVisible || !this.isBrowser) return;
|
||||
|
||||
const clickedElement = event.target as HTMLElement;
|
||||
if (this.ignoreClickOutsideClass) {
|
||||
|
||||
Reference in New Issue
Block a user