Blazor Popup Overview

The Blazor Popup component helps you easily display a popup for a target element (anchor) in your application. You can use the Telerik UI for Blazor Popup to display additional information. This article explains how to start using the component and describes its features.

ninja-iconThe Popup component is part of Telerik UI for Blazor, a professional grade UI library with 110+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.Start Free Trial

Creating Blazor Popup

  1. Add the <TelerikPopup> tag to a Razor file.
  2. Set the AnchorSelector parameter to a CSS selector, which points to the HTML element that the Popup will align with.
  3. Obtain the component reference to show and hide the Popover programmatically.
  4. (optional) Set the Popup Width and Height, or configure animations.

Basic configuration of the Telerik Popup for Blazor

<TelerikPopup @ref="@PopupRef"
              AnchorSelector=".popup-target"
              AnimationType="@AnimationType.SlideDown"
              AnimationDuration="200"
              Width="200px"
              Height="100px">
    <div style="text-align: center;">
        <p>Telerik Popup for Blazor</p>
        <TelerikButton OnClick="@( () => PopupRef?.Hide() )"
                       Icon="@SvgIcon.XCircle">Close</TelerikButton>
    </div>

</TelerikPopup>

<TelerikButton OnClick="@( () => PopupRef?.Show() )"
               Class="popup-target">Show Popup</TelerikButton>

@code {
    private TelerikPopup? PopupRef { get; set; }
}

Use the available positioning and collision settings to customize how the Popup positions and reacts to insufficient space in the viewport. Read more about the Blazor Popup Positioning and Collision...

Use the available parameters to customize the animation type and its duration. Read more about the Blazor Popup animations....

The Blazor Popup provides parameters to configure the component. Also check the Popup API Reference for a full list of properties, methods and events.

ParameterTypeDescription
AnchorHorizontalAlignPopupAnchorHorizontalAlign enum
(Left)
Defines how the anchor aligns with the Popup component on the horizontal plane. Read more about Popup Positioning.
AnchorSelectorstringThe CSS selector for the anchor element of the Popup.
AnchorVerticalAlignPopupAnchorVerticalAlign enum
(Bottom)
Defines how the anchor aligns with the Popup on the vertical plane. Read more about Popup Positioning..
AnimationDurationintThe duration of the animation in milliseconds. Read more about Popup animations.
AnimationTypeAnimationType enum
(SlideDown)
The type of animation when the component displays and hides. Read more about Popup animations.
HorizontalAlignPopupHorizontalAlign enum
(Left)
Determines if the left or the right side of the Popup will touch its anchor. Read more about Popup Positioning.
HorizontalCollisionPopupCollision enum
(Fit)
Sets the behavior of the Popup when it doesn't fit in the viewport based on the horizontal plane. Read more about Popup collision behavior.
HorizontalOffsetdoubleThe horizontal space between the Popup and its anchor in pixels.
VerticalAlignPopupVerticalAlign enum
(Top)
Determines if the Popup will touch the anchor with its top, bottom, or center. Read more about Popup Positioning.
VerticalCollisionPopupCollision enum
(Flip)
Defines the behavior of the Popup when it doesn't fit in the viewport based on the vertical plane. Read more about Popup collision behavior.
VerticalOffsetdoubleThe vertical space between the Popup and its anchor in pixels.

Styling and Appearance

The following parameters enable you to customize the appearance of the Blazor Popup:

ParameterTypeDescription
ClassstringThe custom CSS class to be rendered on the <div> element, which wraps the component ChildContent. Use for styling customizations.
HeightstringThe height of the Popup.
WidthstringThe width of the Popup. If not set, the component width will match the anchor width.

To execute Popup methods, obtain a reference to the component instance with @ref.

MethodDescription
RefreshRe-renders the Popup.
The Popup renders as a child of the TelerikRootComponent, instead of where it is declared. As a result, it doesn't automatically refresh when its content is updated. In such cases, the Refresh method ensures that the Popup content is up-to-date.
ShowDisplays the Popup.
HideCloses the Popup.
<TelerikButton OnClick="@TogglePopup"
               Class="popup-target">Toggle Popup</TelerikButton>

<TelerikPopup @ref="@PopupRef"
              AnchorSelector=".popup-target">
    Telerik Popup for Blazor
</TelerikPopup>

@code {
    private TelerikPopup? PopupRef { get; set; }

    private bool PopupVisible { get; set; }

    private void TogglePopup()
    {
        if (!PopupVisible)
        {
            PopupVisible = true;
            PopupRef?.Show();
        }
        else
        {
            PopupVisible = false;
            PopupRef?.Hide();
        }
    }
}

Next Steps

See Also