Render Blazor Range Slider Inside Dialog Popup

25 Aug 20231 minute to read

The Blazor Slider component will be created before the Dialog popup is opened, and the Slider component will not be adapted to the parent element during dynamic rendering. As a result, the Slider does not render with the accurate initial value. To address this case, you must invoke the Slider’s RepositionAsync method when the Dialog component is opened, utilizing the Opened event.

@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.Buttons

<SfButton Content="Open Dialog" OnClick="ToggleDialog"></SfButton>

<SfDialog Width="400px" IsModal="true" @bind-Visible="@IsVisible" ShowCloseIcon="true">
    <DialogEvents Opened="Opened"></DialogEvents>
        <Header>Slider in Dialog Popup</Header>
            <SfSlider @ref="sliderObj" Value=@RangeValue Type="SliderType.Range"></SfSlider>

@code {
    SfSlider<int[]>? sliderObj;
    public bool IsVisible { get; set; } = false;
    public int[] RangeValue = { 30, 70 };
    public void Opened()
    protected void ToggleDialog()
        IsVisible = !IsVisible;