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

Added missing useInertPolyfill() calls #2224

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/silver-items-refuse.md
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

`Carousel.Slide` adds polyfill for `inert`.
22 changes: 1 addition & 21 deletions packages/itwinui-react/src/core/Overlay/Overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import { Box, isUnitTest, polymorphic } from '../../utils/index.js';
import { Box, polymorphic } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';

type OverlayComponentProps = {
Expand Down Expand Up @@ -39,7 +39,6 @@ if (process.env.NODE_ENV === 'development') {

const OverlayHiddenContent = React.forwardRef((props, ref) => {
const { children, ...rest } = props;
useInertPolyfill();
return (
<Box {...{ inert: '' }} ref={ref} {...rest}>
{children}
Expand Down Expand Up @@ -104,22 +103,3 @@ export const Overlay = Object.assign(OverlayComponent, {
*/
Overlay: OverlayOverlay,
});

const useInertPolyfill = () => {
const loaded = React.useRef(false);
const modulePath =
'https://cdn.jsdelivr.net/npm/wicg-inert@3.1.2/dist/inert.min.js';

React.useEffect(() => {
(async () => {
if (
!HTMLElement.prototype.hasOwnProperty('inert') &&
!loaded.current &&
!isUnitTest
) {
await new Function('url', 'return import(url)')(modulePath);
loaded.current = true;
}
})();
}, []);
};
23 changes: 23 additions & 0 deletions packages/itwinui-react/src/core/ThemeProvider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export const ThemeProvider = React.forwardRef((props, forwardedRef) => {
...rest
} = props;

useInertPolyfill();

const [rootElement, setRootElement] = React.useState<HTMLElement | null>(
null,
);
Expand Down Expand Up @@ -486,3 +488,24 @@ const useIuiDebugRef = () => {

_globalThis.__iui.versions.add(JSON.stringify(meta));
};

// ----------------------------------------------------------------------------

const useInertPolyfill = () => {
const loaded = React.useRef(false);
const modulePath =
'https://cdn.jsdelivr.net/npm/wicg-inert@3.1.2/dist/inert.min.js';

React.useEffect(() => {
(async () => {
if (
!HTMLElement.prototype.hasOwnProperty('inert') &&
!loaded.current &&
!isUnitTest
) {
await new Function('url', 'return import(url)')(modulePath);
loaded.current = true;
}
})();
}, []);
};
Loading