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(AppRoot): add disableParentTransformForPositionFixedElements prop #5692

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
6 changes: 6 additions & 0 deletions packages/vkui/src/components/AppRoot/AppRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ describe('AppRoot', () => {
render(<AppRoot mode="embedded" />).unmount();
expect(document.body).toContainElement(portalRoot1 as HTMLElement);
});
it('should disable CSS transform on parent for mode="embedded"', () => {
const { rerender, container } = render(<AppRoot mode="embedded" />);
expect(container.style.transform).toBe('translate3d(0, 0, 0)');
rerender(<AppRoot mode="embedded" disableParentTransformForPositionFixedElements />);
expect(container.style.transform).toBe('');
});
it('Accepts custom portal root', () => {
const customPortalRoot = document.createElement('div');
let portalRoot: HTMLElement | undefined | null;
Expand Down
28 changes: 24 additions & 4 deletions packages/vkui/src/components/AppRoot/AppRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,17 @@ export interface AppRootProps extends React.HTMLAttributes<HTMLDivElement> {
* Кастомный root-элемент портала
*/
portalRoot?: HTMLElement | React.RefObject<HTMLElement> | null;
/** Disable portal for components */
/**
* Отключает рендер всплывающих компонентов в отдельном контейнере
*/
disablePortal?: boolean;
/**
* По умолчанию, mode="embedded" переносит систему координат элементов с `position: fixed` на
* свой контейнер через `transform: translate3d(0, 0, 0)`.
*
* Это поведение можно отключить с помощью этого параметра.
*/
disableParentTransformForPositionFixedElements?: boolean;
}

/**
Expand All @@ -56,6 +65,7 @@ export const AppRoot = ({
scroll = 'global',
portalRoot: portalRootProp = null,
disablePortal,
disableParentTransformForPositionFixedElements,
className,
safeAreaInsets,
...props
Expand Down Expand Up @@ -107,12 +117,22 @@ export const AppRoot = ({

const parent = rootRef.current?.parentElement;
const classes = ['vkui__root'].concat(mode === 'embedded' ? 'vkui__root--embedded' : []);
parent?.classList.add(...classes);
if (parent) {
if (!disableParentTransformForPositionFixedElements) {
parent.style.transform = 'translate3d(0, 0, 0)';
}
parent.classList.add(...classes);
}

return () => {
parent?.classList.remove(...classes);
if (parent) {
if (!disableParentTransformForPositionFixedElements) {
parent.style.transform = '';
}
parent.classList.remove(...classes);
}
};
}, []);
}, [disableParentTransformForPositionFixedElements]);

useIsomorphicLayoutEffect(() => {
if (mode === 'full') {
Expand Down
1 change: 0 additions & 1 deletion packages/vkui/src/styles/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
}

.vkui__root--embedded {
transform: translate3d(0, 0, 0);
overflow-x: hidden;
}

Expand Down