Class TwRangeSlider<T>
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
A slider with two handles for choosing a lower and an upper value within a range.
public class TwRangeSlider<T> : TwBlazorInputComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable
Type Parameters
- Inheritance
-
TwRangeSlider<T>
- Implements
- Inherited Members
Remarks
Built the same way as TwSlider<T>: each handle is a native range input that is invisible but still handles pointer, touch, keyboard and screen reader interaction, with the track, fill and thumbs drawn separately for full styling control. The handles cannot pass each other, and MinDistance can keep a gap between them.
Constructors
TwRangeSlider()
public TwRangeSlider()
Properties
Color
Gets or sets the color of the filled range between the handles. Defaults to the primary color.
[Parameter]
public Color? Color { get; set; }
Property Value
LowerValue
Gets or sets the lower value, set by the first handle.
[Parameter]
public T LowerValue { get; set; }
Property Value
- T
LowerValueChanged
Gets or sets the callback invoked when the lower value changes. Used by @bind-LowerValue.
[Parameter]
public EventCallback<T> LowerValueChanged { get; set; }
Property Value
LowerValueExpression
Gets or sets the expression that identifies the bound lower value. Set automatically by
@bind-LowerValue, it lets an enclosing EditForm or TwForm validate the property.
[Parameter]
public Expression<Func<T>>? LowerValueExpression { get; set; }
Property Value
- Expression<Func<T>>
Max
Gets or sets the highest value either handle can take.
[Parameter]
public required T Max { get; set; }
Property Value
- T
Min
Gets or sets the lowest value either handle can take.
[Parameter]
public required T Min { get; set; }
Property Value
- T
MinDistance
Gets or sets the smallest gap allowed between the lower and upper values. Defaults to zero, which lets both handles sit on the same value.
[Parameter]
public T MinDistance { get; set; }
Property Value
- T
Name
Gets or sets the form field name. The lower input is submitted as {Name}-lower and the upper input
as {Name}-upper.
[Parameter]
public string Name { get; set; }
Property Value
Step
Gets or sets the amount a handle moves with each step. Must be positive.
[Parameter]
public required T Step { get; set; }
Property Value
- T
UpperValue
Gets or sets the upper value, set by the second handle.
[Parameter]
public T UpperValue { get; set; }
Property Value
- T
UpperValueChanged
Gets or sets the callback invoked when the upper value changes. Used by @bind-UpperValue.
[Parameter]
public EventCallback<T> UpperValueChanged { get; set; }
Property Value
UpperValueExpression
Gets or sets the expression that identifies the bound upper value. Set automatically by
@bind-UpperValue. It is used for validation when LowerValueExpression is not set.
[Parameter]
public Expression<Func<T>>? UpperValueExpression { get; set; }
Property Value
- Expression<Func<T>>
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
CreateFieldIdentifier()
Creates the identifier of the model property the field's value is bound to. Input components override
this to build it from their value expression (supplied by @bind-Value).
protected override FieldIdentifier? CreateFieldIdentifier()
Returns
- FieldIdentifier?
The field identifier, or null when the value is not bound to a property.
OnAfterRenderAsync(bool)
Method invoked after each time the component has been rendered interactively and the UI has finished updating (for example, after elements have been added to the browser DOM). Any ElementReference fields will be populated by the time this runs.
This method is not invoked during prerendering or server-side rendering, because those processes are not attached to any live browser DOM and are already complete before the DOM is updated.
Note that the component does not automatically re-render after the completion of any returned Task, because that would cause an infinite render loop.
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRenderboolSet to
trueif this is the first time OnAfterRender(bool) has been invoked on this component instance; otherwisefalse.
Returns
Remarks
The OnAfterRender(bool) and OnAfterRenderAsync(bool) lifecycle methods
are useful for performing interop, or interacting with values received from @ref.
Use the firstRender parameter to ensure that initialization work is only performed
once.
OnParametersSet()
Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.
protected override void OnParametersSet()
Remarks
If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.