@@ -8,7 +8,7 @@ import * as popperJS from "popper.js";
8
8
export interface PopoverProps {
9
9
referenceElementId : string ;
10
10
placement : string ; // TODO: use a union type of allowed values
11
-
11
+ parentId ?: string ;
12
12
content ?: string ;
13
13
classNames ?: string [ ] ;
14
14
arrowClassNames ?: string [ ] ;
@@ -25,23 +25,21 @@ class PopoverClass extends ComponentBase<{}, PopoverProps> {
25
25
26
26
handlePopoverLifecycle ( element , isInitialized , context ) {
27
27
if ( ! isInitialized ) {
28
- let popoverObj : any = {
29
- content : this . props . content ,
30
- classNames : this . props . classNames ,
31
- arrowClassNames : this . props . arrowClassNames
32
- } ;
28
+ let popperElement = this . generatePopperElement ( this . props . parentId ) ;
33
29
34
- let mainControllerElem = document . getElementById ( Constants . Ids . mainController ) ;
35
- if ( mainControllerElem ) {
36
- // We want to set the parent lower in the HTML hierarchy to avoid z-index issues relating to stacking contexts
37
- popoverObj . parent = mainControllerElem ;
30
+ // TODO temporarily typed this way until definitions is updated for popperJS.PopperOptions
31
+ let popperOptions : any = {
32
+ placement : this . props . placement ,
33
+ removeOnDestroy : this . props . removeOnDestroy ,
34
+ modifiers : { }
35
+ } ;
36
+ if ( this . props . modifiersIgnored ) {
37
+ for ( let i = 0 ; i < this . props . modifiersIgnored . length ; i ++ ) {
38
+ popperOptions . modifiers [ this . props . modifiersIgnored [ i ] ] = { enabled : false } ;
39
+ }
38
40
}
39
41
40
- this . refToPopper = new popperJS ( document . getElementById ( this . props . referenceElementId ) , popoverObj , {
41
- placement : this . props . placement ,
42
- modifiersIgnored : this . props . modifiersIgnored ,
43
- removeOnDestroy : this . props . removeOnDestroy
44
- } ) ;
42
+ this . refToPopper = new popperJS ( document . getElementById ( this . props . referenceElementId ) , popperElement , popperOptions ) ;
45
43
}
46
44
47
45
if ( isInitialized ) {
@@ -58,6 +56,36 @@ class PopoverClass extends ComponentBase<{}, PopoverProps> {
58
56
} ;
59
57
}
60
58
59
+ private generatePopperElement ( parentId : string ) : HTMLDivElement {
60
+ let popperElement = document . createElement ( "div" ) as HTMLDivElement ;
61
+ popperElement . innerText = this . props . content ;
62
+
63
+ if ( this . props . classNames ) {
64
+ for ( let i = 0 ; i < this . props . classNames . length ; i ++ ) {
65
+ popperElement . classList . add ( this . props . classNames [ i ] ) ;
66
+ }
67
+ }
68
+
69
+ if ( this . props . arrowClassNames ) {
70
+ let arrowElement = document . createElement ( "div" ) ;
71
+ for ( let i = 0 ; i < this . props . arrowClassNames . length ; i ++ ) {
72
+ arrowElement . classList . add ( this . props . arrowClassNames [ i ] ) ;
73
+ }
74
+ arrowElement . setAttribute ( "x-arrow" , "" ) ;
75
+ popperElement . appendChild ( arrowElement ) ;
76
+ }
77
+
78
+ let parent = parentId ? document . getElementById ( parentId ) : undefined ;
79
+ if ( parent ) {
80
+ // We want to set the parent lower in the HTML hierarchy to avoid z-index issues relating to stacking contexts
81
+ parent . appendChild ( popperElement ) ;
82
+ } else {
83
+ document . body . appendChild ( popperElement ) ;
84
+ }
85
+
86
+ return popperElement ;
87
+ }
88
+
61
89
render ( ) {
62
90
return (
63
91
< div config = { this . handlePopoverLifecycle . bind ( this ) } />
0 commit comments