Table of Contents

Class TwSlider<T>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a generic slider component that enables users to select a value within a specified range.

public class TwSlider<T> : TwBlazorInputComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent

Type Parameters

T

The type of the value represented by the slider. Must support comparison operations to allow range enforcement.

Inheritance
TwSlider<T>
Implements
Inherited Members

Remarks

This component provides a customizable slider interface for selecting values of type T. It supports two-way data binding and allows precise control over the value selection through configurable minimum, maximum, and step values. The component is suitable for scenarios where users need to select numeric or comparable values within defined bounds.

Constructors

TwSlider()

public TwSlider()

Properties

Color

Gets or sets the color of the slider.

[Parameter]
public Color? Color { get; set; }

Property Value

Color?

Remarks

When specified, applies an accent color class to the slider. If null, no color class is applied.

Max

Gets or sets the maximum allowable value for the parameter of type T.

[Parameter]
public required T Max { get; set; }

Property Value

T

Remarks

This property is required and must be set to a valid value before use. Ensure that the value assigned to Max adheres to any constraints defined by the type T.

Min

Gets or sets the minimum allowed value for the parameter of type T.

[Parameter]
public required T Min { get; set; }

Property Value

T

Remarks

The Min property must be set to a valid value before use. It defines the lower bound for the associated parameter, ensuring that values do not fall below this threshold.

Name

Gets or sets the name associated with the component.

[Parameter]
public string Name { get; set; }

Property Value

string

Remarks

The name is used to identify the component in various contexts, such as when binding data or displaying information to the user.

Step

Gets or sets the step value used to increment or decrement the slider's value.

[Parameter]
public required T Step { get; set; }

Property Value

T

Remarks

The step value must be a positive number. It determines the amount by which the slider's value increases or decreases with each adjustment. Use this property to control the precision of value changes when interacting with the slider.

Value

Gets or sets the current value of the parameter.

[Parameter]
public T Value { get; set; }

Property Value

T

ValueChanged

Gets or sets the callback that is invoked when the value changes.

[Parameter]
public EventCallback<T> ValueChanged { get; set; }

Property Value

EventCallback<T>

Remarks

Use this property to handle value change events in two-way data binding scenarios. The callback is triggered when the component's value is updated, allowing parent components to respond to the change.

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

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.