-
I'm seeing strange behavior as illustrated in this video. When a modal is opened, the width of my page container is changing. Can anyone think of anything off the top of their head that might cause this or point me in a direction to debug? import React, { useLayoutEffect, useState } from 'react';
import { useUID } from '@twilio-paste/core/uid-library';
import { Box } from '@twilio-paste/core/box';
import { Button } from '@twilio-paste/core/button';
import { Modal, ModalBody } from '@twilio-paste/core/modal';
import { SearchIcon } from '@twilio-paste/icons/esm/SearchIcon';
export default function PagefindSearchButton(): JSX.Element {
const [isOpen, setIsOpen] = useState(false);
const handleOpen = () => setIsOpen(true);
const handleClose = () => setIsOpen(false);
const searchElementID = `search${useUID()}`;
const searchElementRef = React.useRef<HTMLDivElement>(null);
const noop = (): void => {
// Empty cleanup function
};
useLayoutEffect(() => {
if (!isOpen) return noop;
const timeoutId = setTimeout(() => {
// eslint-disable-next-line no-new
new PagefindUI({
element: `#${searchElementID}`,
showImages: false,
resetStyles: false,
showEmptyFilters: false,
bundlePath: '/client-scripts/', // use our custom API wrapper
});
});
return () => clearTimeout(timeoutId);
}, [isOpen, searchElementID, searchElementRef]);
return (
<>
<Box
display="flex"
alignItems="flex-end"
columnGap="space50"
marginLeft="space100"
>
<Button
variant="secondary"
disabled={false}
onClick={handleOpen}
>
<SearchIcon
decorative={true}
title="Search"
/>
Search...
</Button>
</Box>
<Modal
ariaLabelledby={searchElementID}
isOpen={isOpen}
onDismiss={handleClose}
size="wide"
>
<ModalBody>
<div
id={searchElementID}
ref={searchElementRef}
/>
</ModalBody>
</Modal>
</>
);
}
PagefindSearchButton.displayName = 'PagefindSearchButton'; |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
Beta Was this translation helpful? Give feedback.
-
More information: I have |
Beta Was this translation helpful? Give feedback.
-
Answer from @TheSisb: Hi @dprothero , our Modal is based on reach/Modal which hides the scrollbar when the modal is visible. This can sometimes cause these kinds of side effects when you have your own styles on the
That seems to fix the issue in my inspector. Hope this helps! |
Beta Was this translation helpful? Give feedback.
Answer from @TheSisb:
Hi @dprothero , our Modal is based on reach/Modal which hides the scrollbar when the modal is visible. This can sometimes cause these kinds of side effects when you have your own styles on the
body
tag. I'd generally recommend moving some styles around to fix the issue:max-width: 1600px
into the child of the body element. In this case you can add it to#__docusaurus
or even its child under that.margin: 0 auto
That seems to fix the issue in my inspector. Hope this helps!