@@ -3,12 +3,12 @@ import { useOverlayRegistry } from '@/src/hooks/useOverlayRegistry'
33import { useHightideTranslation } from '@/src/i18n/useHightideTranslation'
44import type { ReactNode } from 'react'
55import { forwardRef , useId , useImperativeHandle , useMemo , useRef , type HTMLAttributes } from 'react'
6- import { createPortal } from 'react-dom'
76import { Visibility } from './Visibility'
8- import { Button } from '../user-interaction/Button'
97import { X } from 'lucide-react'
108import { useTransitionState } from '@/src/hooks/useTransitionState'
119import { PropsUtil } from '@/src/utils/propsUtil'
10+ import { Portal } from '../utils/Portal'
11+ import { IconButton } from '../user-interaction/IconButton'
1212
1313export type DrawerAligment = 'left' | 'right' | 'bottom' | 'top'
1414
@@ -21,6 +21,7 @@ export type DrawerProps = HTMLAttributes<HTMLDivElement> & {
2121 containerClassName ?: string ,
2222 backgroundClassName ?: string ,
2323 onClose : ( ) => void ,
24+ forceMount ?: boolean ,
2425}
2526
2627export const Drawer = forwardRef < HTMLDivElement , DrawerProps > ( function Drawer ( {
@@ -32,6 +33,7 @@ export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer({
3233 containerClassName,
3334 backgroundClassName,
3435 onClose,
36+ forceMount = false ,
3537 ...props
3638} , forwardedRef ) {
3739 const translation = useHightideTranslation ( )
@@ -59,74 +61,76 @@ export const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer({
5961 } )
6062 const depth = tagPositions && tagItemCounts ? ( ( tagItemCounts [ 'drawer' ] ?? 0 ) - ( tagPositions [ 'drawer' ] ?? 0 ) ) : 0
6163
62- if ( ! isVisible ) return
64+ if ( ! isVisible && ! forceMount ) return
6365
64- return createPortal (
65- < div
66- id = { ids . container }
67-
68- data-name = "drawer-container"
69- data-open = { PropsUtil . dataAttributes . bool ( isOpen ) }
70-
71- className = { containerClassName }
72- style = { { zIndex, '--drawer-depth' : depth . toString ( ) } as React . CSSProperties }
73- >
66+ return (
67+ < Portal >
7468 < div
75- id = { ids . background }
69+ id = { ids . container }
7670
77- onClick = { onClose }
71+ data-name = "drawer-container"
72+ data-open = { PropsUtil . dataAttributes . bool ( isOpen ) }
7873
79- data-name = "drawer-background"
80- data-state = { transitionState }
81- data-depth = { depth }
82- data-alignment = { alignment }
74+ hidden = { ! isVisible && forceMount }
8375
84- aria-hidden = { true }
76+ className = { containerClassName }
77+ style = { { zIndex, '--drawer-depth' : depth . toString ( ) } as React . CSSProperties }
78+ >
79+ < div
80+ id = { ids . background }
8581
86- className = { backgroundClassName }
87- />
88- < div
89- { ...props }
90- id = { ids . content }
91- ref = { ref }
82+ onClick = { onClose }
9283
93- onKeyDown = { PropsUtil . aria . close ( close ) }
84+ data-name = "drawer-background"
85+ data-state = { transitionState }
86+ data-depth = { depth }
87+ data-alignment = { alignment }
9488
95- data-name = { PropsUtil . dataAttributes . name ( 'drawer-content' , props ) }
96- data-state = { transitionState }
97- data-depth = { depth }
98- data-alignment = { alignment }
89+ aria-hidden = { true }
9990
100- className = { props . className }
101- >
102- < div className = "typography-title-lg mr-8" >
103- { titleElement }
104- </ div >
105- < Visibility isVisible = { ! ! description } >
106- < div className = "text-description" >
107- { description }
108- </ div >
109- </ Visibility >
91+ className = { backgroundClassName }
92+ />
11093 < div
111- className = "absolute top-0 right-0"
112- style = { {
113- paddingTop : 'inherit' ,
114- paddingRight : 'inherit'
115- } }
94+ { ...props }
95+ id = { ids . content }
96+ ref = { ref }
97+
98+ onKeyDown = { PropsUtil . aria . close ( close ) }
99+
100+ data-name = { PropsUtil . dataAttributes . name ( 'drawer-content' , props ) }
101+ data-state = { transitionState }
102+ data-depth = { depth }
103+ data-alignment = { alignment }
104+
105+ className = { props . className }
116106 >
117- < Button
118- layout = "icon"
119- color = "neutral"
120- size = "xs"
121- aria-label = { translation ( 'close' ) }
122- onClick = { onClose }
107+ < div className = "typography-title-lg mr-8" >
108+ { titleElement }
109+ </ div >
110+ < Visibility isVisible = { ! ! description } >
111+ < div className = "text-description" >
112+ { description }
113+ </ div >
114+ </ Visibility >
115+ < div
116+ className = "absolute top-0 right-0"
117+ style = { {
118+ paddingTop : 'inherit' ,
119+ paddingRight : 'inherit'
120+ } }
123121 >
124- < X />
125- </ Button >
122+ < IconButton
123+ tooltip = { translation ( 'close' ) }
124+ coloringStyle = "text"
125+ color = "neutral"
126+ onClick = { onClose }
127+ >
128+ < X size = { 24 } />
129+ </ IconButton >
130+ </ div >
131+ { children }
126132 </ div >
127- { children }
128133 </ div >
129- </ div >
130- , document . body
134+ </ Portal >
131135 )
132136} )
0 commit comments