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

feat(react-drawer): add support for mountNode with className #33226

Merged
Show file tree
Hide file tree
Changes from 2 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 @@
{
marcosmoura marked this conversation as resolved.
Show resolved Hide resolved
"type": "minor",
"comment": "add support for mountNode with className",
"packageName": "@fluentui/react-drawer",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ export type OverlayDrawerSlots = {
};

// @public
export type OverlayDrawerState = ComponentState<OverlayDrawerInternalSlots> & Required<DrawerBaseState> & Pick<OverlayDrawerProps, 'mountNode'>;
export type OverlayDrawerState = ComponentState<OverlayDrawerInternalSlots> & Required<DrawerBaseState> & Pick<OverlayDrawerProps, 'mountNode'> & {
hasMountNodeElement?: boolean;
};

// @public
export const renderDrawer_unstable: (state: DrawerState, contextValue: DrawerContextValue) => JSX.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@fluentui/react-dialog": "^9.11.18",
"@fluentui/react-jsx-runtime": "^9.0.45",
"@fluentui/react-motion": "^9.6.0",
"@fluentui/react-portal": "^9.4.37",
"@fluentui/react-shared-contexts": "^9.20.2",
"@fluentui/react-tabster": "^9.22.9",
"@fluentui/react-theme": "^9.1.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ describe('OverlayDrawer', () => {
const result = mountNode.querySelector('#drawer');
expect(result).toBeTruthy();
});

it('accept mountNode as object with className', () => {
const customClassName = 'CustomMountNode';

const { baseElement } = render(
<OverlayDrawer id="drawer" mountNode={{ className: customClassName }} open={true}>
Default OverlayDrawer
</OverlayDrawer>,
);

const mountNodeElement = baseElement.querySelector(`.${customClassName}`);
const drawerInsideMountNode = mountNodeElement?.querySelector('#drawer');

expect(mountNodeElement).toBeTruthy();
expect(drawerInsideMountNode).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ export type OverlayDrawerProps = ComponentProps<OverlayDrawerSlots> &
*/
export type OverlayDrawerState = ComponentState<OverlayDrawerInternalSlots> &
Required<DrawerBaseState> &
Pick<OverlayDrawerProps, 'mountNode'>;
Pick<OverlayDrawerProps, 'mountNode'> & {
hasMountNodeElement?: boolean;
marcosmoura marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { Dialog } from '@fluentui/react-dialog';
import { slot } from '@fluentui/react-utilities';
import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
import { toMountNodeProps } from '@fluentui/react-portal';

import { OverlayDrawerMotion, OverlaySurfaceBackdropMotion } from '../../shared/drawerMotions';
import { useDrawerDefaultProps } from '../../shared/useDrawerDefaultProps';
Expand Down Expand Up @@ -31,7 +32,9 @@ export const useOverlayDrawer_unstable = (
): OverlayDrawerState => {
const { open, size, position } = useDrawerDefaultProps(props);
const { backdropMotion, modalType = 'modal', inertTrapFocus, onOpenChange, surfaceMotion, mountNode } = props;
const { dir } = useFluent();
const { dir, targetDocument } = useFluent();
const { element: mountNodeElement } = toMountNodeProps(mountNode);
const hasMountNodeElement = Boolean(mountNodeElement && targetDocument?.body !== mountNodeElement);

const backdropProps = slot.resolveShorthand(props.backdrop);
const hasCustomBackdrop = modalType !== 'non-modal' && backdropProps !== null;
Expand Down Expand Up @@ -82,6 +85,9 @@ export const useOverlayDrawer_unstable = (
open,
size,
position,
hasMountNodeElement,

// Deprecated props
mountNode,
motion: STATIC_MOTION,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useOverlayDrawerStyles_unstable = (state: OverlayDrawerState): Over
const resetStyles = useDrawerResetStyles();
const rootStyles = useDrawerRootStyles();

const absoluteStyles = !!state.mountNode && rootStyles.absolute;
const absoluteStyles = !!state.hasMountNodeElement && rootStyles.absolute;
marcosmoura marked this conversation as resolved.
Show resolved Hide resolved
const backdrop = state.root.backdrop as React.HTMLAttributes<HTMLDivElement> | undefined;

state.root.className = mergeClasses(
Expand Down
Loading