Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(components): fix header transition from mobile to header #4256

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading