File tree Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Expand file tree Collapse file tree 1 file changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -12,18 +12,16 @@ const ClayPortalContext = React.createContext<React.RefObject<Element | null> |
12
12
13
13
ClayPortalContext . displayName = 'ClayPortalContext' ;
14
14
15
- const createElement = (
16
- nodeName : string ,
17
- attributes : Record < string , string >
18
- ) => {
19
- const element = document . createElement ( nodeName ) ;
20
-
21
- Object . keys ( attributes ) . forEach ( ( key ) => {
22
- element . setAttribute (
23
- key === 'className' ? 'class' : key ,
24
- attributes [ key ]
25
- ) ;
26
- } ) ;
15
+ const createDivElement = ( className ?: string , id ?: string ) => {
16
+ const element = document . createElement ( 'div' ) ;
17
+
18
+ if ( className ) {
19
+ element . setAttribute ( 'class' , className ) ;
20
+ }
21
+
22
+ if ( id ) {
23
+ element . setAttribute ( 'id' , id ) ;
24
+ }
27
25
28
26
return element ;
29
27
} ;
@@ -54,16 +52,15 @@ interface IProps {
54
52
55
53
export const ClayPortal : React . FunctionComponent < IProps > = ( {
56
54
children,
55
+ className,
57
56
containerRef,
57
+ id,
58
58
subPortalRef,
59
- ...otherProps
60
59
} ) => {
61
60
const parentPortalRef = React . useContext ( ClayPortalContext ) ;
62
61
63
62
const portalRef = React . useRef (
64
- typeof document !== 'undefined'
65
- ? createElement ( 'div' , otherProps as Record < string , string > )
66
- : null
63
+ typeof document !== 'undefined' ? createDivElement ( className , id ) : null
67
64
) ;
68
65
69
66
React . useEffect ( ( ) => {
You can’t perform that action at this time.
0 commit comments