Blazor Input Color

Provides a user interface element that lets a user specify a color.

Features:

JavaScript Independence: This component operates seamlessly without requiring JavaScript, offering a lightweight and straightforward solution.

Appearance customization: Customizable styles and themes.

Rendering options: Render your component as various HTML tags for maximum flexibility and integration.

Learn about core component featuresLearn about input component features

Simple input color

Selected color code:
<BlazorLabel>
    Select a color
    <BlazorInputColor @bind-Value="MyColorCode" />
</BlazorLabel>
<div>Selected color code: @MyColorCode</div>

@code {
    public string MyColorCode { get; set; }
}

Input color with textbox

Selected color code: #ff0000
Message:
<BlazorLabel>
    Select a color
    <BlazorInputText @bind-Value="MyColorCode2" UpdateOnHtmlEvent="oninput" ParseValueHandler="BlazorInputColor.Parse" ValueParsed="OnParsed" />
    <BlazorInputColor @bind-Value="MyColorCode2" />
</BlazorLabel>
<div>Selected color code: @MyColorCode2</div>
<div>Message: @Message</div>

@code {
    public string MyColorCode2 { get; set; } = "#ff0000";
    public string Message { get; set; } = "";

    public void OnParsed(ParseEventArgs parseEventArgs)
    {
        Message = parseEventArgs.ParseSuccess ? "" : $"The value {parseEventArgs.UserInputValue} is not a valid color code.";
    }
}

Disabled input:

<BlazorLabel>
    Select a color
    <BlazorInputColor @bind-Value="..." @bind-disabled="Disabled" />
</BlazorLabel>
<BlazorButton type="button" @onclick="_ => Disabled = !Disabled" Variants="Disabled?new[] {BaseVariants.Success}:new[] {BaseVariants.Danger}">@(Disabled ? "Enable" : "Disable")</BlazorButton>

@code {
    public bool Disabled { get; set; } = true;
}

Appearance Customization

Learn about Theme Feature
Component & Variants CSS class
BlazorFormControl form-control
BlazorFormControl.invalid border-danger
BlazorFormControl.valid border-success
BlazorFormControl.color form-control-color

Parameters

BlazorInputColor

Name Type Description
RenderAs string Specifies the HTML tag to be used for rendering the component. This can be any valid HTML tag, such as div, span, button, or other suitable tags.
Variants string[] Specifies the variant of the component.
Value string The value of the input.
UpdateOnHtmlEvent string This parameter allows you to specify which HTML event should trigger a re-render or update of the component. When the specified event occurs on the input element, the component will initiate the parsing process, updating its internal value to reflect the UI input. Default event is onchange.
ValueParsed EventCallback<ParseEventArgs> Specify an action or method to be executed when the component parses a value, whether the parsing operation succeeds or fails.
FieldState FieldState Represents the state of a field or input element within the component. Can be used to track and manage the state of the field and display relevant messages to the user.
ParseValueHandler Func<string?, TValue?> Implement specialized parsing logic for the component, such as handling user input, converting strings to specific data types, which corresponds to the type of the Value parameter in the component and performing validation during the parsing process.

Methods

BlazorInputColor

Name Description
Parse(string? colorCode) This method is used with another input to parse the colorCode to a valid color code.
An error has occurred. This application may no longer respond until reloaded. Reload 🗙