-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Add ability to set parent container #296
Comments
Can you give me an example where you'd nest it inside another element? |
hi - I think this would have solved a similar use case where I define custom CSS variables (i.e. theme color) so that all components can be styled with the same tailwind classes (i.e. Since Radix's DialogPortal accepts a container, my workaround was to allow DrawerContent to take in an additional container prop and then pass that to DrawerPortal. |
Do you have the code of the workaround by any chance? |
I have something like this: const DrawerContent = React.forwardRef<
React.ElementRef<DrawerContentPrimitive>,
React.ComponentPropsWithoutRef<DrawerContentPrimitive>
>(({ className, children, placement, theme, container, ...props }, ref) => (
<DrawerPortal container={container}>
...
</DrawerPortal>
))
DrawerContent.displayName = 'DrawerContent' I wrap my app in a context provider that provides and sets the CSS variable in the container and then pass the element to places I want to use the drawer: export function CustomStyledRadixContextProvider(props: {
children: React.ReactNode
}) {
const divRef = useRef<HTMLDivElement>(null)
const [initialValue, setInitialValue] = useState<HTMLElement | undefined>()
useLayoutEffect(() => {
if (divRef.current) {
setInitialValue(divRef.current)
}
}, [])
const customStyles = {
'--theme-color': color,
} as React.CSSProperties
return (
<div style={customStyles} className="h-full w-full">
<CustomStyledRadixContext.Provider value={initialValue}>
{props.children}
</CustomStyledRadixContext.Provider>
<div ref={divRef} />
</div>
)
} export function CustomStyledDrawerContent(props: {
children: React.ReactNode
[key: string]: any
}) {
const radixStyleMountDiv = useContext(CustomStyledRadixContext)
return (
<DrawerContent
container={radixStyleMountDiv}
className="z-[100]"
{...props}
>
{props.children}
</DrawerContent>
)
} |
Hi @emilkowalski, just wanted to followup on whether there's any sort of way I could reduce the calculations of vaul to be in a parent container's size. This is currently a pretty big bottleneck for me on desktop breakpoints where at the moment Im keeping the size of the app to be within a phone sized container. |
The drawer dimensions are currently determined based on the viewport size. However, it would be beneficial to allow the specification of a container element for these calculations. This would enable the drawer to be used within a specific containing element, rather than occupying the entire screen.
The text was updated successfully, but these errors were encountered: