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(Panel): Add event listener to Panel in order to update the footer's sticky property correctly when content changes dynamically #33520

Merged
merged 3 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
sopranopillow marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "fix: Add event listener to Panel in order to update the footer's sticky property correctly when content changes dynamically.",
"packageName": "@fluentui/react",
"email": "estebanmu@microsoft.com",
"dependentChangeType": "patch"
}
20 changes: 20 additions & 0 deletions packages/react/src/components/Panel/Panel.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class PanelBase extends React.Component<IPanelProps, IPanelState> impleme
private _hasCustomNavigation: boolean = !!(this.props.onRenderNavigation || this.props.onRenderNavigationContent);
private _headerTextId: string | undefined;
private _allowTouchBodyScroll: boolean;
private _resizeObserver: ResizeObserver | null;

public static getDerivedStateFromProps(
nextProps: Readonly<IPanelProps>,
Expand Down Expand Up @@ -149,6 +150,7 @@ export class PanelBase extends React.Component<IPanelProps, IPanelState> impleme
public componentWillUnmount(): void {
this._async.dispose();
this._events.dispose();
this._resizeObserver?.disconnect();
}

public render(): JSX.Element | null {
Expand Down Expand Up @@ -310,9 +312,27 @@ export class PanelBase extends React.Component<IPanelProps, IPanelState> impleme
);
}

private _createResizeObserver(callback: ResizeObserverCallback): ResizeObserver | null {
const doc = getDocumentEx(this.context);
let resizeObserver: ResizeObserver | null = null;

if (doc?.defaultView?.ResizeObserver) {
resizeObserver = new doc.defaultView.ResizeObserver(callback);
}

return resizeObserver;
}

// Allow the user to scroll within the panel but not on the body
private _allowScrollOnPanel = (elt: HTMLDivElement | null): void => {
this._resizeObserver = this._createResizeObserver(entries => {
if (entries.length > 0 && entries[0].target === elt) {
this._updateFooterPosition();
}
});

if (elt) {
this._resizeObserver?.observe(elt);
if (this._allowTouchBodyScroll) {
allowOverscrollOnElement(elt, this._events);
} else {
Expand Down
Loading