@@ -6,6 +6,8 @@ import { property } from 'lit/decorators/property.js';
66import { styleMap } from 'lit/directives/style-map.js' ;
77import { classMap } from 'lit/directives/class-map.js' ;
88
9+ import { observes } from '@patternfly/pfe-core/decorators/observes.js' ;
10+
911import {
1012 FloatingDOMController ,
1113 type Placement ,
@@ -66,7 +68,10 @@ const EXIT_EVENTS: readonly string[] = ['focusout', 'mouseleave'];
6668export class PfV6Tooltip extends LitElement {
6769 static readonly styles : CSSStyleSheet [ ] = [ styles ] ;
6870
69- /** Position of the tooltip relative to the trigger element */
71+ /** When true, the tooltip is displayed. */
72+ @property ( { type : Boolean } ) visible = false ;
73+
74+ /** Position of the tooltip relative to the trigger element. */
7075 @property ( ) position : Placement = 'top' ;
7176
7277 /** Tooltip content text. Overridden by the content slot. */
@@ -190,27 +195,35 @@ export class PfV6Tooltip extends LitElement {
190195
191196 /** Show the tooltip programmatically */
192197 async show ( ) : Promise < void > {
198+ this . visible = true ;
193199 await this . updateComplete ;
194200 const placement = this . position ;
195201 const offset =
196- ! placement ?. match ( / t o p | b o t t o m / ) ? 15
197- : { mainAxis : 15 , alignmentAxis : - 4 } ;
198- await this . #float. show ( {
199- offset,
200- placement,
201- flip : ! this . noFlip ,
202- fallbackPlacements : this . flipBehavior ,
203- } ) ;
202+ ! placement ?. match ( / t o p | b o t t o m / ) ? 15
203+ : { mainAxis : 15 , alignmentAxis : - 4 } ;
204+ const flip = ! this . noFlip ;
205+ const fallbackPlacements = this . flipBehavior ;
206+ await this . #float. show ( { offset, placement, flip, fallbackPlacements } ) ;
204207 this . #setAriaDescribedBy( true ) ;
205208 }
206209
207210 /** Hide the tooltip programmatically */
208211 async hide ( ) : Promise < void > {
212+ this . visible = false ;
209213 this . #clearTimers( ) ;
210214 this . #setAriaDescribedBy( false ) ;
211215 await this . #float. hide ( ) ;
212216 }
213217
218+ @observes ( 'visible' )
219+ protected _visibleChanged ( ) : void {
220+ if ( this . visible ) {
221+ this . show ( ) ;
222+ } else {
223+ this . hide ( ) ;
224+ }
225+ }
226+
214227 #setAriaDescribedBy( add : boolean ) : void {
215228 const trigger = this . #invokerElement;
216229 const content = this . shadowRoot ?. querySelector ( '#content' ) ?? null ;
0 commit comments