Table of Contents

Class MudBaseInput<T>

Namespace
MudBlazor
Assembly
MudBlazor.dll

Represents a base class for designing form input components.

public abstract class MudBaseInput<T> : MudFormComponent<T, string>, IComponent, IHandleEvent, IHandleAfterRender, IMudStateHasChanged, IFormComponent, IAsyncDisposable

Type Parameters

T

The type of item being input.

Inheritance
MudBaseInput<T>
Implements
Derived
Inherited Members
Extension Methods

Constructors

MudBaseInput()

protected MudBaseInput()

Fields

_forceTextUpdate

protected bool _forceTextUpdate

Field Value

bool

_isFocused

protected bool _isFocused

Field Value

bool

Properties

Adornment

The location of the adornment icon or text.

[Parameter]
[Category("Behavior")]
public Adornment Adornment { get; set; }

Property Value

Adornment

Remarks

Defaults to None. When set to Start or End, the AdornmentText will be displayed, or AdornmentIcon if no adornment text is specified.

AdornmentAriaLabel

The aria-label for the adornment.

[Parameter]
[Category("Appearance")]
public string? AdornmentAriaLabel { get; set; }

Property Value

string

Remarks

Defaults to null.

AdornmentColor

The color of AdornmentText or AdornmentIcon.

[Parameter]
[Category("Appearance")]
public Color AdornmentColor { get; set; }

Property Value

Color

Remarks

Defaults to Default. Theme colors are supported.

AdornmentIcon

The icon displayed for the adornment.

[Parameter]
[Category("Behavior")]
public string? AdornmentIcon { get; set; }

Property Value

string

Remarks

Defaults to null. This icon will be displayed when Adornment is Start or End, and no value for AdornmentText is set.

AdornmentText

The text displayed for the adornment.

[Parameter]
[Category("Behavior")]
public string? AdornmentText { get; set; }

Property Value

string

Remarks

Defaults to null. This text will be displayed when Adornment is Start or End. The AdornmentIcon property will be ignored if this property is set.

AutoFocus

Automatically receives focus.

[Parameter]
[Category("Behavior")]
public bool AutoFocus { get; set; }

Property Value

bool

Remarks

Defaults to false. When true, the input will receive focus automatically.

Counter

The optional character count and stop count.

[Parameter]
[Category("Validation")]
public int? Counter { get; set; }

Property Value

int?

Remarks

Defaults to null. When 0, the current character count is displayed. When 1 or greater, the character count and this count are displayed.

Disabled

Allows the component to receive input.

[Parameter]
[Category("Behavior")]
public bool Disabled { get; set; }

Property Value

bool

Remarks

Defaults to false.

Format

The format applied to values.

[Parameter]
[Category("Behavior")]
public string? Format { get; set; }

Property Value

string

Remarks

This property is passed into the ToString() method of the Value property, such as formatting int, float, DateTime and TimeSpan values.

FullWidth

Fills the full width of the parent container.

[Parameter]
[Category("Appearance")]
public bool FullWidth { get; set; }

Property Value

bool

Remarks

Defaults to false.

HelperId

The ID of the helper element, for use by aria-describedby.

[Parameter]
[Category("Validation")]
public string? HelperId { get; set; }

Property Value

string

Remarks

Defaults to null. When set it is appended to the aria-describedby attribute to improve accessibility for users. This ID takes precedence over the helper element rendered when HelperText is provided.

HelperText

The text displayed below the text field.

[Parameter]
[Category("Behavior")]
public string? HelperText { get; set; }

Property Value

string

Remarks

This property is typically used to help the user understand what kind of input is allowed. The HelperTextOnFocus property controls when this text is visible.

HelperTextOnFocus

Displays the HelperText only when this input has focus.

[Parameter]
[Category("Behavior")]
public bool HelperTextOnFocus { get; set; }

Property Value

bool

Remarks

Defaults to false.

IconSize

The size of the icon.

[Parameter]
[Category("Appearance")]
public Size IconSize { get; set; }

Property Value

Size

Remarks

Defaults to Medium.

Immediate

Changes the Value as soon as input is received.

[Parameter]
[Category("Behavior")]
public bool Immediate { get; set; }

Property Value

bool

Remarks

Defaults to false. When true, the Value property will be updated any time user input occurs. Otherwise, Value is updated when the user presses Enter or the input loses focus.

InputElementId

The resolved input element ID.

protected string? InputElementId { get; }

Property Value

string

InputId

The ID of the input element.

[Parameter]
[Category("Behavior")]
public string? InputId { get; set; }

Property Value

string

Remarks

When set takes precedence over any internally generated IDs.

InputMode

The type of input expected.

[Parameter]
[Category("Behavior")]
public virtual InputMode InputMode { get; set; }

Property Value

InputMode

Remarks

Defaults to text.

KeyDownPreventDefault

Allows the default key-down action to occur.

[Parameter]
[Category("Behavior")]
public bool KeyDownPreventDefault { get; set; }

Property Value

bool

Remarks

When true, the browser will not perform its default behavior when a key-down occurs. This is typically used when a key-down needs to override a browser's default behavior.

KeyUpPreventDefault

Prevents the default key-up action.

[Parameter]
[Category("Behavior")]
public bool KeyUpPreventDefault { get; set; }

Property Value

bool

Remarks

When true, the browser will not perform its default behavior when a key-up occurs. This is typically used when a key-up needs to override the browser's default behavior.

Label

The label for this input.

[Parameter]
[Category("Behavior")]
public string? Label { get; set; }

Property Value

string

Remarks

If no Value is specified, the label will be displayed in the input. Otherwise, it will be scaled down to the top of the input.

Lines

A multiline input (textarea) will be shown, if set to more than one line.

[Parameter]
[Category("Behavior")]
public int Lines { get; set; }

Property Value

int

Margin

The amount of vertical spacing for this input.

[Parameter]
[Category("Appearance")]
public Margin Margin { get; set; }

Property Value

Margin

Remarks

Defaults to None in Margin.

MaxLength

The maximum number of characters allowed.

[Parameter]
[Category("Validation")]
public int MaxLength { get; set; }

Property Value

int

Remarks

Defaults to 524288. This value is typically set to a maximum length such as the size of a database column the value will be persisted to.

OnAdornmentClick

Occurs when the adornment text or icon has been clicked.

[Parameter]
public EventCallback<MouseEventArgs> OnAdornmentClick { get; set; }

Property Value

EventCallback<MouseEventArgs>

OnBlur

Occurs when the input loses focus.

[Parameter]
public EventCallback<FocusEventArgs> OnBlur { get; set; }

Property Value

EventCallback<FocusEventArgs>

OnInternalInputChanged

Occurs when the internal text value has changed.

[Parameter]
public EventCallback<ChangeEventArgs> OnInternalInputChanged { get; set; }

Property Value

EventCallback<ChangeEventArgs>

OnKeyDown

Occurs when a key has been pressed down.

[Parameter]
public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }

Property Value

EventCallback<KeyboardEventArgs>

OnKeyUp

Occurs when a pressed key has been released.

[Parameter]
public EventCallback<KeyboardEventArgs> OnKeyUp { get; set; }

Property Value

EventCallback<KeyboardEventArgs>

OnlyValidateIfDirty

Limits validation to when the user changes the Value.

[Parameter]
[Category("Behavior")]
public bool OnlyValidateIfDirty { get; set; }

Property Value

bool

Remarks

Defaults to false. When true, validation only occurs if the user has changed the input value at least once.

Pattern

The regular expression used to validate the Value property.

[Parameter]
[Category("Validation")]
public virtual string? Pattern { get; set; }

Property Value

string

Remarks

Defaults to null. This property is used to validate the input against a regular expression. Not supported if Lines is 2 or greater. Must be a valid JavaScript regular expression.

Placeholder

The text displayed in the input if no Value is specified.

[Parameter]
[Category("Behavior")]
public string? Placeholder { get; set; }

Property Value

string

Remarks

This property is typically used to give the user a hint as to what kind of input is expected.

ReadOnly

Prevents the input from being changed by the user.

[Parameter]
[Category("Behavior")]
public bool ReadOnly { get; set; }

Property Value

bool

Remarks

Defaults to false. When true, the user can copy text in the control, but cannot change the Value.

ShrinkLabel

Shows the label inside the input if no Value is specified.

[Parameter]
[Category("Appearance")]
public bool ShrinkLabel { get; set; }

Property Value

bool

Remarks

Defaults to false in ShrinkLabel. When true, the label will not move into the input when the input is empty.

Text

The text displayed in the input.

[Parameter]
[Category("Data")]
public string? Text { get; set; }

Property Value

string

TextChanged

Occurs when the Text property has changed.

[Parameter]
public EventCallback<string> TextChanged { get; set; }

Property Value

EventCallback<string>

TextUpdateSuppression

Prevents the text from being updated via a bound value.

[Parameter]
[Category("Behavior")]
public bool TextUpdateSuppression { get; set; }

Property Value

bool

Remarks

Defaults to true. Applies only to Blazor Server (BSS) applications. When false, the input's text can be updated programmatically while the input has focus.

Typo

Typography for the input text.

[Parameter]
[Category("Appearance")]
public Typo Typo { get; set; }

Property Value

Typo

Underline

Displays an underline for the input.

[Parameter]
[Category("Appearance")]
public bool Underline { get; set; }

Property Value

bool

Remarks

Defaults to true.

Value

The value for this input.

[Parameter]
[Category("Data")]
public T? Value { get; set; }

Property Value

T

Remarks

This property represents the strongly typed value for the input. It is typically the result of parsing raw input via the Text property.

ValueChanged

Occurs when the Value property has changed.

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

Property Value

EventCallback<T>

Variant

The appearance variation to use.

[Parameter]
[Category("Appearance")]
public Variant Variant { get; set; }

Property Value

Variant

Remarks

Defaults to Text in Variant.

Methods

BlurAsync()

When overridden, releases focus from this input.

public virtual ValueTask BlurAsync()

Returns

ValueTask

A ValueTask object.

FocusAsync()

When overridden, obtains focus for this input.

public virtual ValueTask FocusAsync()

Returns

ValueTask

A ValueTask object.

ForceRender(bool)

Causes this input to be rerendered.

public virtual void ForceRender(bool forceTextUpdate)

Parameters

forceTextUpdate bool

When true, the Text property will be updated before rendering.

ForceUpdate()

Sets the value, values, and text, and calls validation.

public virtual Task ForceUpdate()

Returns

Task

A Task object.

Remarks

This method is typically called when the user has changed the Value or Text programmatically.

GetAriaDescribedByString()

protected string? GetAriaDescribedByString()

Returns

string

GetDisabledState()

protected bool GetDisabledState()

Returns

bool

GetHelperId()

protected string? GetHelperId()

Returns

string

GetReadOnlyState()

protected bool GetReadOnlyState()

Returns

bool

InvokeKeyDownAsync(KeyboardEventArgs)

protected virtual Task InvokeKeyDownAsync(KeyboardEventArgs obj)

Parameters

obj KeyboardEventArgs

Returns

Task

InvokeKeyUpAsync(KeyboardEventArgs)

protected virtual Task InvokeKeyUpAsync(KeyboardEventArgs obj)

Parameters

obj KeyboardEventArgs

Returns

Task

OnAfterRenderAsync(bool)

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnBlurredAsync(FocusEventArgs)

protected virtual Task OnBlurredAsync(FocusEventArgs obj)

Parameters

obj FocusEventArgs

Returns

Task

OnInitializedAsync()

protected override Task OnInitializedAsync()

Returns

Task

OnParametersSet()

protected override void OnParametersSet()

ResetValueAsync()

protected override Task ResetValueAsync()

Returns

Task

SelectAsync()

When overridden, selects this input.

public virtual ValueTask SelectAsync()

Returns

ValueTask

A ValueTask object.

SelectRangeAsync(int, int)

When overridden, selects a portion of the input.

public virtual ValueTask SelectRangeAsync(int pos1, int pos2)

Parameters

pos1 int

The index of the first character to select.

pos2 int

The index of the last character to select.

Returns

ValueTask

A ValueTask object.

SetConverter(Converter<T, string>)

protected override bool SetConverter(Converter<T, string> value)

Parameters

value Converter<T, string>

Returns

bool

SetCulture(CultureInfo)

protected override bool SetCulture(CultureInfo value)

Parameters

value CultureInfo

Returns

bool

SetFormat(string?)

protected virtual bool SetFormat(string? value)

Parameters

value string

Returns

bool

SetParametersAsync(ParameterView)

public override Task SetParametersAsync(ParameterView parameters)

Parameters

parameters ParameterView

Returns

Task

SetTextAsync(string?, bool)

protected virtual Task SetTextAsync(string? text, bool updateValue = true)

Parameters

text string
updateValue bool

Returns

Task

SetValueAsync(T?, bool, bool)

protected virtual Task SetValueAsync(T? value, bool updateText = true, bool force = false)

Parameters

value T
updateText bool
force bool

Returns

Task

UpdateTextPropertyAsync(bool)

Occurs when the value has changed internally.

protected virtual Task UpdateTextPropertyAsync(bool updateValue)

Parameters

updateValue bool

Returns

Task

Remarks

This method is called when the Text property needs to be refreshed from current Value.

UpdateValuePropertyAsync(bool)

Occurs when the value has changed internally.

protected virtual Task UpdateValuePropertyAsync(bool updateText)

Parameters

updateText bool

Returns

Task

Remarks

This method is called when the Value property needs to be refreshed from current Text.

ValidateValue()

protected override Task ValidateValue()

Returns

Task