@@ -8,7 +8,7 @@ import * as popperJS from "popper.js";
88export interface PopoverProps {
99 referenceElementId : string ;
1010 placement : string ; // TODO: use a union type of allowed values
11-
11+ parentId ?: string ;
1212 content ?: string ;
1313 classNames ?: string [ ] ;
1414 arrowClassNames ?: string [ ] ;
@@ -25,23 +25,21 @@ class PopoverClass extends ComponentBase<{}, PopoverProps> {
2525
2626 handlePopoverLifecycle ( element , isInitialized , context ) {
2727 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 ) ;
3329
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+ }
3840 }
3941
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 ) ;
4543 }
4644
4745 if ( isInitialized ) {
@@ -58,6 +56,36 @@ class PopoverClass extends ComponentBase<{}, PopoverProps> {
5856 } ;
5957 }
6058
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+
6189 render ( ) {
6290 return (
6391 < div config = { this . handlePopoverLifecycle . bind ( this ) } />
0 commit comments