Skip to content

Commit

Permalink
fix(components): fix header transition from mobile to header (#4256)
Browse files Browse the repository at this point in the history
Co-authored-by: Philipp Gfeller <[email protected]>
  • Loading branch information
alizedebray and gfellerph authored Dec 13, 2024
1 parent 14b4de9 commit 2cebad2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/components/src/components/post-header/post-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type DEVICE_SIZE = 'mobile' | 'tablet' | 'desktop' | null;
export class PostHeader {
private scrollParent = null;
private mobileMenu: HTMLElement;
private mobileMenuAnimation: Animation;
private throttledScroll = () => this.handleScrollEvent();
private throttledResize = throttle(50, () => this.handleResize());

Expand Down Expand Up @@ -42,13 +43,14 @@ export class PostHeader {
async toggleMobileMenu() {
if (this.device === 'desktop') return;

if (this.mobileMenuExtended) {
await slideUp(this.mobileMenu).finished;
} else {
slideDown(this.mobileMenu);
}
this.mobileMenuAnimation = this.mobileMenuExtended
? slideUp(this.mobileMenu)
: slideDown(this.mobileMenu);

// Toggle menu visibility before it slides down and after it slides back up
if (this.mobileMenuExtended) await this.mobileMenuAnimation.finished;
this.mobileMenuExtended = !this.mobileMenuExtended;
if (!this.mobileMenuExtended) await this.mobileMenuAnimation.finished;
}

private handleScrollEvent() {
Expand Down Expand Up @@ -95,13 +97,22 @@ export class PostHeader {

if (width >= 1024) {
newDevice = 'desktop';
this.mobileMenuExtended = false; // Close any open mobile menu
} else if (width >= 600) {
newDevice = 'tablet';
} else {
newDevice = 'mobile';
}

// Close any open mobile menu
if (newDevice === 'desktop' && this.mobileMenuExtended) {
this.toggleMobileMenu();
this.mobileMenuAnimation.finish(); // no animation


const menuToggler = this.host.querySelector<HTMLPostTogglebuttonElement>('post-togglebutton');
if (menuToggler) menuToggler.toggled = false;
}

// Apply only on change for doing work only when necessary
if (newDevice !== previousDevice) {
this.device = newDevice;
Expand Down

0 comments on commit 2cebad2

Please sign in to comment.