Skip to content

Commit

Permalink
Use more explicit name for disablePortal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-medvedev-vk committed Oct 31, 2024
1 parent 28a2512 commit 8437d88
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/vkui/src/components/AppRoot/AppRootPortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ export const AppRootPortal = ({
usePortal,
className,
}: AppRootPortalProps): React.ReactNode => {
const { setPortalRoot, appRoot, mode, disablePortal } = React.useContext(AppRootContext);
const {
setPortalRoot,
appRoot,
mode,
disablePortal: disableCreatePortalInGlobalPortalRoot,
} = React.useContext(AppRootContext);
const colorScheme = useColorScheme();

const canUsePortal = shouldUsePortal(usePortal, mode, Boolean(disablePortal));
const canUsePortal = shouldUsePortal(
usePortal,
mode,
Boolean(disableCreatePortalInGlobalPortalRoot),
);
const portalContainer = usePortalContainer(usePortal);

useIsomorphicLayoutEffect(
Expand Down Expand Up @@ -67,17 +76,17 @@ export const AppRootPortal = ({
function shouldUsePortal(
usePortal: AppRootPortalProps['usePortal'],
mode: AppRootContextInterface['mode'],
disablePortal: boolean,
disableCreatePortalInGlobalPortalRoot: boolean,
) {
if (usePortal === undefined) {
return disablePortal === false && mode !== 'full';
return disableCreatePortalInGlobalPortalRoot === false && mode !== 'full';
}

if (typeof usePortal !== 'boolean') {
return true;
}

return disablePortal === false && usePortal === true;
return disableCreatePortalInGlobalPortalRoot === false && usePortal === true;
}

function usePortalContainer(usePortal: AppRootPortalProps['usePortal']): HTMLElement | null {
Expand Down

0 comments on commit 8437d88

Please sign in to comment.