Skip to content

Commit d4fe36e

Browse files
author
phanendraguptha
committed
fix: ui elements shifting to the right
1 parent febba57 commit d4fe36e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/components/Search.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {IconSearch} from 'components/Icon/IconSearch';
77
import Head from 'next/head';
88
import Link from 'next/link';
99
import Router from 'next/router';
10-
import {useState, useCallback, useEffect} from 'react';
10+
import {useState, useCallback, useEffect, useLayoutEffect} from 'react';
1111
import * as React from 'react';
1212
import {createPortal} from 'react-dom';
1313
import {siteConfig} from 'siteConfig';
@@ -108,6 +108,15 @@ export function Search({
108108
}: SearchProps) {
109109
const [isShowing, setIsShowing] = useState(false);
110110

111+
useLayoutEffect(() => {
112+
const scrollBarWidth = window.innerWidth - document.body.clientWidth;
113+
if (isShowing) {
114+
document.body.style.marginRight = `${scrollBarWidth}px`;
115+
} else if (!isShowing) {
116+
document.body.style.marginRight = '0px';
117+
}
118+
}, [isShowing]);
119+
111120
const importDocSearchModalIfNeeded = useCallback(
112121
function importDocSearchModalIfNeeded() {
113122
if (DocSearchModal) {

0 commit comments

Comments
 (0)