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(PortalCompatProvider): support custom ID prefixes in themeClassName #28551

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 @@
{
"type": "patch",
"comment": "fix(PortalCompatProvider): support custom ID prefixes in themeClassName",
"packageName": "@fluentui/react-portal-compat",
"email": "alinazaieva@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThemeClassNameProvider_unstable as ThemeClassNameProvider } from '@fluentui/react-shared-contexts';
import { usePortalCompat } from '@fluentui/react-portal-compat-context';
import { FluentProvider } from '@fluentui/react-provider';
import { resetIdsForTests } from '@fluentui/react-utilities';
import { IdPrefixProvider, resetIdsForTests } from '@fluentui/react-utilities';
import { renderHook } from '@testing-library/react-hooks';
import * as React from 'react';

Expand Down Expand Up @@ -41,6 +41,26 @@ describe('PortalCompatProvider', () => {
`);
});

it('during register adds a className from "ThemeClassNameContext" context with custom ID prefix', () => {
const element = document.createElement('div');
const { result } = renderHook(() => usePortalCompat(), {
wrapper: props => (
<IdPrefixProvider value="custom1-">
<FluentProvider theme={{ colorNeutralBackground1: '#ccc' }}>
<PortalCompatProvider>{props.children}</PortalCompatProvider>
</FluentProvider>
</IdPrefixProvider>
),
});

expect(result.current(element)).toBeInstanceOf(Function);
expect(element.classList).toMatchInlineSnapshot(`
DOMTokenList {
"0": "custom1-fui-FluentProvider1",
}
`);
});

it('during register adds a className from "ThemeClassNameContext" context with a React 18 compatible ID', () => {
const element = document.createElement('div');
const { result } = renderHook(() => usePortalCompat(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { applyFocusVisiblePolyfill } from '@fluentui/react-tabster';

import type { RegisterPortalFn } from '@fluentui/react-portal-compat-context';

const CLASS_NAME_REGEX = new RegExp(`(${fluentProviderClassNames.root}\\w+)`);
const CLASS_NAME_REGEX = new RegExp(`([^\\s]*${fluentProviderClassNames.root}\\w+)`);

export const PortalCompatProvider: React.FC<{ children?: React.ReactNode }> = props => {
const { children } = props;
Expand Down