Duplicated
Last Updated: 24 Jan 2023 15:08 by Yazan
Tyler
Created on: 15 Jul 2020 13:03
Category: Tooltip
Type: Feature Request
12
Close tooltip via Method

I would like to be able to do something like the following - cause the tooltip to close from my code:

<TelerikTooltip TargetSelector="#tooltip1" ShowOn="@TooltipShowEvent.Click" @ref="@TooltipRef">     
            <Template>
                 Content Here
                <button type="button" class="btn btn-primary" @onclick="tipClose">Save</button>                
            </Template>
</TelerikTooltip>

<a href="#" id="tooltip1" class="btn btn-secondary">open</a>

@code{
 Telerik.Blazor.Components.TelerikTooltip TooltipRef { get; set; }

void tipClose()
    {
       // TooltipRef ?
    }


}

Duplicated
This item is a duplicate of an already existing item. You can find the original item here:
3 comments
Yazan
Posted on: 24 Jan 2023 15:08

Solution for hiding tooltip after 2 seconds with Telerik Version 3.7.0

 

<TelerikTooltip Id="@Id"
@ref="TelerikTooltipRef"
Class="clipboard-tooltip"
TargetSelector="@("#" + Id + ".copy-button")"
ShowOn="TooltipShowEvent.Click">

 

<div class="copy-button" id="@Id" @onclick="CopyTextToClipboard">
</div>

@code {

[Parameter, EditorRequired] 
public string Id { get; set; }

private TelerikTooltip TelerikTooltipRef { get; set; }

private async Task CopyTextToClipboard()
{
await JSRuntime.InvokeVoidAsync("ShowElement", ".clipboard-tooltip", "#" + TelerikTooltipRef.Id);
await JSRuntime.InvokeVoidAsync("window.clipboardCopy.copyText", TextToCopy);
await Task.Delay(2000);
await JSRuntime.InvokeVoidAsync("HideElement", ".clipboard-tooltip", "#" + TelerikTooltipRef.Id);
}

}

<script suppress-error="BL9992">
function HideElement(className, id) {
let inputs = document.querySelectorAll(className);
inputs.forEach(element => {
if (element.querySelector(id) !== null) {
debugger;
element.style.display = "none"
}
});
}

function ShowElement(className, id) {
let inputs = document.querySelectorAll(className);
inputs.forEach(element => {
if (element.querySelector(id) !== null && element.style.display === "none") {
element.style.display = "block"
}
});
}
</script>
Yazan
Posted on: 23 Jan 2023 21:24
would be nice to have this feature obv when using the Show on click
Giuseppe
Posted on: 20 Jan 2021 12:59

I would also be in need of having the possibility to close the tooltip via code.