Skip to content

Commit

Permalink
Fix @fluentui/react-portal-compat: to be compatible with React 18 (#…
Browse files Browse the repository at this point in the history
…27577)

* Fix `@fluentui/react-portal-compat`: to be compatible with React 18

* add change

---------

Co-authored-by: Hán Jīn <hanj@microsoft.com>
Co-authored-by: Oleksandr Fediashov <olfedias@microsoft.com>
  • Loading branch information
3 people authored Apr 24, 2023
1 parent 6c236e6 commit 51767fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Class ID detection compatible with React 18",
"packageName": "@fluentui/react-portal-compat",
"email": "hanj@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ describe('PortalCompatProvider', () => {
`);
});

it('during register adds a className from "ThemeClassNameContext" context with a React 18 compatible ID', () => {
const element = document.createElement('div');
const { result } = renderHook(() => usePortalCompat(), {
wrapper: props => (
<ThemeClassNameProvider value="fui-FluentProviderR1a">
<PortalCompatProvider>{props.children}</PortalCompatProvider>
</ThemeClassNameProvider>
),
});

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

it('during unregister remove a className from "ThemeClassNameContext" context', () => {
const element = document.createElement('div');

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}\\d+)`);
const CLASS_NAME_REGEX = new RegExp(`(${fluentProviderClassNames.root}\\w+)`);

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

0 comments on commit 51767fd

Please sign in to comment.