Skip to content

fix(module:affix): restore width element after hidden state #7445

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions components/affix/affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy, On
private destroy$ = new Subject<void>();
private timeout?: number;
private document: Document;
private lastVisibleElementOffsetSize: SimpleRect | null = null;

private get target(): Element | Window {
const el = this.nzTarget;
Expand Down Expand Up @@ -252,6 +253,11 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy, On
top: false,
bottom: false
};

if (elemOffset.height !== 0 && elemOffset.width !== 0) {
this.lastVisibleElementOffsetSize = elemOffset;
}

// Default to `offsetTop=0`.
if (typeof offsetTop !== 'number' && typeof this.nzOffsetBottom !== 'number') {
offsetMode.top = true;
Expand All @@ -263,7 +269,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy, On
const targetRect = getTargetRect(targetNode as Window);
const targetInnerHeight = (targetNode as Window).innerHeight || (targetNode as HTMLElement).clientHeight;
if (scrollTop >= elemOffset.top - (offsetTop as number) && offsetMode.top) {
const width = elemOffset.width;
const width = elemOffset.width || this.lastVisibleElementOffsetSize?.width;
const top = targetRect.top + (offsetTop as number);
this.setAffixStyle(e, {
position: 'fixed',
Expand All @@ -280,7 +286,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy, On
offsetMode.bottom
) {
const targetBottomOffset = targetNode === window ? 0 : window.innerHeight - targetRect.bottom!;
const width = elemOffset.width;
const width = elemOffset.width || this.lastVisibleElementOffsetSize?.width;
this.setAffixStyle(e, {
position: 'fixed',
bottom: targetBottomOffset + (this.nzOffsetBottom as number),
Expand Down