# TooltipService Class

A service for displaying tooltips programmatically on UI elements or at specific positions. TooltipService provides methods to show tooltips with text or custom HTML content, with configurable positioning, delays, and durations. To use this service, add it as a scoped service in your application's service collection and place a RadzenTooltip component in your main layout. Manages tooltip lifecycle, automatically closing tooltips on navigation and providing various positioning options (top, bottom, left, right). Tooltips can be shown on mouse enter/leave events or on demand, with configurable delays before showing and auto-close durations.

Namespace: [Radzen](https://blazor.radzen.com/docs/api/Radzen.md)

Assembly: Radzen.Blazor.dll

## Inheritance

- Object
- TooltipService

## Syntax

```csharp
public class TooltipService
```

## Examples

Show a simple text tooltip:

```razor
@inject TooltipService TooltipService
<RadzenButton Text="Hover me" MouseEnter="@(args => TooltipService.Open(args, "This is a tooltip"))" />
```

Show a tooltip with HTML content and custom options:

```razor
@inject TooltipService TooltipService
<RadzenButton Text="Show tooltip" MouseEnter="@(args => ShowTooltipWithHtml(args))" />
@code {
    void ShowTooltipWithHtml(ElementReference element) => TooltipService.Open(element, ts =>
        @<div>
            <b>Bold</b> and <i>italic</i> content
        </div>, 
        new TooltipOptions { Position = TooltipPosition.Top, Duration = 5000 });
}
```

## Constructors

| Constructor | Description |
|-------------|-------------|
| `public TooltipService(NavigationManager uriHelper)` | Initializes a new instance of the [TooltipService](https://blazor.radzen.com/docs/api/Radzen.TooltipService.md) class. Parameters: `uriHelper`: The URI helper. |

## Methods

| Method | Returns | Description |
|------|---------|-------------|
| `Close()` | `void` | Closes this instance. |
| `Dispose()` | `void` | Disposes this instance. |
| `Open(ElementReference element, RenderFragment<TooltipService> childContent, TooltipOptions options)` | `void` | Opens a tooltip with custom HTML content near the specified element. The tooltip will be positioned according to the options and can contain any Blazor markup. Parameters: `element`: The HTML element reference near which the tooltip will be displayed. `childContent`: A render fragment that defines the custom HTML content of the tooltip. Receives the TooltipService as context. `options`: Optional tooltip configuration including position, duration, delay, and styling. If null, default options are used. |
| `Open(ElementReference element, string text, TooltipOptions options)` | `void` | Opens a tooltip with custom HTML content near the specified element. The tooltip will be positioned according to the options and can contain any Blazor markup. Parameters: `element`: The HTML element reference near which the tooltip will be displayed. `options`: Optional tooltip configuration including position, duration, delay, and styling. If null, default options are used. |
| `OpenOnTheBottom(ElementReference element, string text, TooltipOptions o)` | `void` | Opens the specified element on the bottom position. Parameters: `element`: The element. `text`: The text. `o`: The o. |
| `OpenOnTheLeft(ElementReference element, string text, TooltipOptions o)` | `void` | Opens the specified element on the left position. Parameters: `element`: The element. `text`: The text. `o`: The o. |
| `OpenOnTheRight(ElementReference element, string text, TooltipOptions o)` | `void` | Opens the specified element on the right position. Parameters: `element`: The element. `text`: The text. `o`: The o. |
| `OpenOnTheTop(ElementReference element, string text, TooltipOptions options)` | `void` | Opens a tooltip with text content positioned above the specified element. This is a convenience method equivalent to calling Open() with TooltipPosition.Top. Parameters: `element`: The HTML element reference above which the tooltip will be displayed. `text`: The text content to display in the tooltip. `options`: Optional additional tooltip configuration. The Position will be set to Top regardless of the value in options. |

## Events

| Event | Type | Description |
|------|------|-------------|
| OnClose | `Action` | Raises the Close event. |
| OnNavigate | `Action` | Occurs when [on navigate]. |
| OnOpen | `Action<ElementReference, Type, TooltipOptions>` | Occurs when [on open]. |

