File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -283,6 +283,11 @@ export default class IgcTooltipComponent extends EventEmitterMixin<
283283 } ) ;
284284 } ;
285285
286+ /** Toggles the tooltip between shown/hidden state after the appropriate delay. */
287+ public toggle = async ( ) : Promise < boolean > => {
288+ return this . open ? this . hide ( ) : this . show ( ) ;
289+ } ;
290+
286291 public showWithEvent = async ( ) => {
287292 clearTimeout ( this . _timeoutId ) ;
288293 if ( this . toBeHidden ) {
Original file line number Diff line number Diff line change @@ -279,3 +279,33 @@ export const Triggers: Story = {
279279 </ igc-tooltip >
280280 ` ,
281281} ;
282+
283+ export const Toggle : Story = {
284+ render : ( ) => {
285+ // Use a template ref id to target the tooltip instance
286+ const tooltipId = 'toggle-tooltip' ;
287+ const buttonId = 'toggle-button' ;
288+
289+ // Hook into the rendered DOM to attach click listener
290+ setTimeout ( ( ) => {
291+ const tooltip = document . getElementById ( tooltipId ) as IgcTooltipComponent ;
292+ const button = document . getElementById ( buttonId ) as HTMLButtonElement ;
293+
294+ if ( tooltip && button ) {
295+ button . addEventListener ( 'click' , ( ) => tooltip . toggle ( ) ) ;
296+ }
297+ } ) ;
298+
299+ return html `
300+ < igc-button id =${ buttonId } > Toggle Tooltip</ igc-button >
301+ < igc-tooltip
302+ id =${ tooltipId }
303+ placement ="bottom"
304+ show-delay="500"
305+ hide-delay="500"
306+ >
307+ This tooltip toggles on button click!
308+ </ igc-tooltip >
309+ ` ;
310+ } ,
311+ } ;
You can’t perform that action at this time.
0 commit comments