Accent color
# TextField **Also known as:** TextInput ## Description Text fields give people a way to enter and edit text. They’re used in forms, modal dialogs, tables, and other surfaces where text input is required. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Accent | `BitColor?` | null | The general color of the text field used when focused. | | AutoHeight | `bool` | false | Automatically adjust the height of the input in Multiline mode. | | Background | `BitColorKind?` | null | The color kind of the text field background. | | Border | `BitColorKind?` | null | The color kind of the text field border. | | CanRevealPassword | `bool` | false | Whether to show the reveal password button for input type 'password'. | | Classes | `BitTextFieldClassStyles?` | null | Custom CSS classes for different parts of the BitTextField. | | ClearButtonIcon | `BitIconInfo?` | null | The icon to display inside the clear button. Takes precedence over ClearButtonIconName when both are set. | | ClearButtonIconName | `string?` | Cancel | Gets or sets the name of the icon to display on the clear button from the built-in Fluent UI icons. | | Description | `string?` | null | Description displayed below the text field to provide additional details about what text to enter. | | DescriptionTemplate | `RenderFragment?` | null | Shows the custom description for text field. | | FullWidth | `bool` | false | Forces the text field fill 100% of its container width. | | GhostText | `string?` | null | The ghost/suggestion text displayed inline after the current cursor position. Update this value from outside (e.g. from an AI or autocomplete suggestion) to show a faded inline suggestion. The user can accept it by pressing Tab or Enter, or clicking/touching the ghost text. | | HidePasswordIcon | `BitIconInfo?` | null | Gets or sets the icon for the reveal password button when password is shown using custom CSS classes for external icon libraries. | | HidePasswordIconName | `string?` | null | The icon name for the reveal password button when password is shown from the built-in Fluent UI icons. | | Icon | `BitIconInfo?` | null | Gets or sets the icon to display using custom CSS classes for external icon libraries. Takes precedence over IconName when both are set. | | IconName | `string?` | null | The icon name for the icon shown in the far right end of the text field from the built-in Fluent UI icons. | | InputMode | `BitInputMode?` | null | Sets the inputmode html attribute of the input element. | | Label | `string?` | null | Label displayed above the text field and read by screen readers. | | LabelTemplate | `RenderFragment?` | null | Shows the custom label for text field. | | MaxLength | `int` | -1 | Specifies the maximum number of characters allowed in the input. | | Multiline | `bool` | false | Whether or not the text field is a Multiline text field. | | NoBorder | `bool` | false | Removes the border of the text input. | | OnClear | `EventCallback` | | Callback executed when the user clears the text field by clicking the clear button. | | OnClick | `EventCallback<MouseEventArgs>` | | Callback for when the input clicked. | | OnEnter | `EventCallback<KeyboardEventArgs>` | | Callback for when the Enter key is pressed while input has focus. | | OnFocus | `EventCallback<FocusEventArgs>` | | Callback for when focus moves into the input. | | OnFocusIn | `EventCallback<FocusEventArgs>` | | Callback for when focus moves into the input. | | OnFocusOut | `EventCallback<FocusEventArgs>` | | Callback for when focus moves out of the input. | | OnGhostTextAccepted | `EventCallback<string?>` | | Callback invoked when the ghost text is accepted via Tab or Enter key, or click/touch. The accepted ghost text string is passed as the argument. | | OnKeyDown | `EventCallback<KeyboardEventArgs>` | | Callback for when a keyboard key is pressed. | | OnKeyUp | `EventCallback<KeyboardEventArgs>` | | Callback for When a keyboard key is released. | | PermanentGhost | `bool` | false | Enables permanent ghost mode that forces the scrollbar-gutter to always be present, preventing layout shift of the ghost text rendering. | | Placeholder | `string?` | null | Input placeholder text. | | Prefix | `string?` | null | Prefix displayed before the text field contents. This is not included in the value. Ensure a descriptive label is present to assist screen readers, as the value does not include the prefix. | | PrefixTemplate | `RenderFragment?` | null | Shows the custom prefix for text field. | | PreventEnter | `bool` | false | Prevents the enter to add new line character into the input in the Multiline mode. | | Resizable | `bool` | false | For multiline text fields, whether or not the field is resizable. | | RevealPasswordAriaLabel | `string?` | null | Aria label for the reveal password button. | | RevealPasswordIcon | `BitIconInfo?` | null | Gets or sets the icon for the reveal password button when password is hidden using custom CSS classes for external icon libraries. | | RevealPasswordIconName | `string?` | null | The icon name for the reveal password button when password is hidden from the built-in Fluent UI icons. | | Rows | `int?` | null | For multiline text, Number of rows. | | ShowClearButton | `bool` | false | Whether to show the clear button when the text field has a value. | | Styles | `BitTextFieldClassStyles?` | null | Custom CSS styles for different parts of the BitTextField. | | Suffix | `string?` | null | Suffix displayed after the text field contents. This is not included in the value. Ensure a descriptive label is present to assist screen readers, as the value does not include the suffix. | | SuffixTemplate | `RenderFragment?` | null | Shows the custom suffix for text field. | | Trim | `bool` | false | Specifies whether to remove any leading or trailing whitespace from the value. | | Type | `BitInputType?` | null | Input type. | | Underlined | `bool` | false | Whether or not the text field is underlined. | | AutoComplete | `string?` | null | Specifies the value of the autocomplete attribute of the input component. | | AutoFocus | `bool` | false | Determines if the text input is auto focused on first render. | | DebounceTime | `int` | 0 | The debounce time in milliseconds. | | Immediate | `bool` | false | Change the content of the input field when the user write text (based on 'oninput' HTML event). | | ThrottleTime | `int` | 0 | The throttle time in milliseconds. | | DefaultValue | `TValue?` | null | The default value of the input to be used in uncontrolled mode (i.e. when the Value is not bound), typically used alongside the OnChange callback. | | DisplayName | `string?` | null | Gets or sets the display name for this field. | | InputHtmlAttributes | `IReadOnlyDictionary<string, object>?` | null | Gets or sets a collection of additional attributes that will be applied to the created element. | | Name | `string?` | null | Gets or sets the name of the element. Allows access by name from the associated form. | | NoValidate | `bool` | false | Disables the validation of the input. | | OnChange | `EventCallback<TValue?>` | | Callback for when the input value changes. | | ReadOnly | `bool` | false | Makes the input read-only. | | Required | `bool` | false | Makes the input required. | | Value | `TValue?` | null | Gets or sets the value of the input. This should be used with two-way binding. | | AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. | | Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. | | Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. | | ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. | | HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. | | Id | `string?` | null | Gets or sets the unique identifier for the component's root element. | | IsEnabled | `bool` | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. | | Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. | | TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. | | Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. | ## Public Members | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | InputElement | `ElementReference` | | The ElementReference to the input element of the BitTextField. | | FocusAsync | `ValueTask` | | Gives focus to the input element of the BitTextField. | | InputElement | `ElementReference` | | The ElementReference of the input element. | | FocusAsync() | `() => ValueTask` | | Gives focus to the input element. | | FocusAsync(bool preventScroll) | `(bool preventScroll) => ValueTask` | | Gives focus to the input element. | | UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. | | RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. | ## Enums ### BitColor Enum | Name | Value | Description | | :--- | :--- | :---------- | | Primary | 0 | Info Primary general color. | | Secondary | 1 | Secondary general color. | | Tertiary | 2 | Tertiary general color. | | Info | 3 | Info general color. | | Success | 4 | Success general color. | | Warning | 5 | Warning general color. | | SevereWarning | 6 | SevereWarning general color. | | Error | 7 | Error general color. | | PrimaryBackground | 8 | Primary background color. | | SecondaryBackground | 9 | Secondary background color. | | TertiaryBackground | 10 | Tertiary background color. | | PrimaryForeground | 11 | Primary foreground color. | | SecondaryForeground | 12 | Secondary foreground color. | | TertiaryForeground | 13 | Tertiary foreground color. | | PrimaryBorder | 14 | Primary border color. | | SecondaryBorder | 15 | Secondary border color. | | TertiaryBorder | 16 | Tertiary border color. | ### BitColorKind Enum | Name | Value | Description | | :--- | :--- | :---------- | | Primary | 0 | The primary color kind. | | Secondary | 1 | The secondary color kind. | | Tertiary | 2 | The tertiary color kind. | | Transparent | 3 | The transparent color kind. | ### BitInputType Enum | Name | Value | Description | | :--- | :--- | :---------- | | Text | 0 | The input expects text characters. | | Password | 1 | The input expects password characters. | | Number | 2 | The input expects number characters. | | Email | 3 | The input expects email characters. | | Tel | 4 | The input expects tel characters. | | Url | 5 | The input expects url characters. | ### BitInputMode Enum | Name | Value | Description | | :--- | :--- | :---------- | | None | 0 | The input expects text characters. | | Text | 1 | Standard input keyboard for the user's current locale. | | Decimal | 2 | Fractional numeric input keyboard containing the digits and decimal separator for the user's locale. | | Numeric | 3 | Numeric input keyboard, but only requires the digits 0–9. | | Tel | 4 | A telephone keypad input, including the digits 0–9, the asterisk (*), and the pound (#) key | | Search | 5 | A virtual keyboard optimized for search input. | | Email | 6 | A virtual keyboard optimized for entering email addresses. | | Url | 7 | A keypad optimized for entering URLs. | ### BitVisibility Enum | Name | Value | Description | | :--- | :--- | :---------- | | Visible | 0 | The content of the component is visible. | | Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). | | Collapsed | 2 | The component is hidden (display:none). | ### BitDir Enum | Name | Value | Description | | :--- | :--- | :---------- | | Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). | | Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). | | Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. | ## Sub Classes ### BitTextFieldClassStyles Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Root | `string?` | null | Custom CSS classes/styles for the BitTextField's root element. | | Focused | `string?` | null | Custom CSS classes/styles of the root element in focus state. | | InputWrapper | `string?` | null | Custom CSS classes/styles for the wrapper of label and input in the BitTextField. | | Label | `string?` | null | Custom CSS classes/styles for the BitTextField's label. | | FieldGroup | `string?` | null | Custom CSS classes/styles for the BitTextField's field group. | | PrefixContainer | `string?` | null | Custom CSS classes/styles for the BitTextField's prefix container. | | Prefix | `string?` | null | Custom CSS classes/styles for the BitTextField's prefix. | | Input | `string?` | null | Custom CSS classes/styles for the BitTextField's input. | | RevealPassword | `string?` | null | Custom CSS classes/styles for the BitTextField's reveal password. | | RevealPasswordIconContainer | `string?` | null | Custom CSS classes/styles for the BitTextField's reveal password icon container. | | RevealPasswordIcon | `string?` | null | Custom CSS classes/styles for the BitTextField's reveal password icon. | | ClearButton | `string?` | null | Custom CSS classes/styles for the BitTextField's clear button. | | ClearButtonIcon | `string?` | null | Custom CSS classes/styles for the BitTextField's clear button icon. | | Icon | `string?` | null | Custom CSS classes/styles for the BitTextField's icon. | | SuffixContainer | `string?` | null | Custom CSS classes/styles for the BitTextField's suffix container. | | Suffix | `string?` | null | Custom CSS classes/styles for the BitTextField's suffix. | | DescriptionContainer | `string?` | null | Custom CSS classes/styles for the BitTextField's description container. | | Description | `string?` | null | Custom CSS classes/styles for the BitTextField's description. | | GhostTextWrapper | `string?` | null | Custom CSS classes/styles for the BitTextField's ghost text wrapper element. | | GhostTextOverlay | `string?` | null | Custom CSS classes/styles for the BitTextField's ghost text overlay container. | ### BitIconInfo Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Name | `string?` | null | Gets or sets the name of the icon. | | BaseClass | `string?` | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. | | Prefix | `string?` | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. | ## Examples \n**Basics**: ```razor ``` \n**Underlined**: ```razor ``` \n**No border**: ```razor ``` \n**Multiline**: ```razor ``` \n**Icon**: ```razor ``` \n**Prefix & Suffix**: ```razor ``` \n**Templates**: ```razor Custom Label Description Prefix Suffix ``` \n**Password**: ```razor ``` \n**ShowClearButton**: ```razor ``` \n**Binding**: ```razor
Value: [@oneWayValue]
Value: [@twoWayValue]
Value: [@onChangeValue]
Value: [@immediateValue]
Value: [@debounceValue]
Value: [@throttleValue]
``` ```csharp private string oneWayValue; private string twoWayValue; private string onChangeValue; private string? immediateValue; private string? debounceValue; private string? throttleValue; ``` \n**GhostText**: ```razor
Value: [@ghostBasicTextValue]
Value: [@ghostBasicMultilineValue]
Value: [@ghostTextValue]
Value: [@ghostMultilineValue]
``` ```csharp private string? ghostBasicTextValue; private string? ghostBasicSuggestion; private string? ghostBasicMultilineValue; private string? ghostBasicMultilineSuggestion; private string? ghostTextValue; private string? ghostSuggestion; private string? ghostMultilineValue; private string? ghostMultilineSuggestion; private CancellationTokenSource? _ghostSuggestionCts; private CancellationTokenSource? _ghostMultilineSuggestionCts; private static readonly string[] _suggestions = [ "application form", "banana smoothie", "car repair manual", "dog training guide" ]; private static string? GetGhostSuggestion(string? value) { if (string.IsNullOrEmpty(value)) return null; if (char.IsWhiteSpace(value[^1])) return null; var lastWord = value.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).LastOrDefault(); if (string.IsNullOrEmpty(lastWord)) return null; var match = _suggestions.FirstOrDefault(s => s.StartsWith(lastWord, StringComparison.OrdinalIgnoreCase)); return match?[lastWord.Length..]; } private async Task SetGhostSuggestionAsync(string? value, bool isMultiline) { var cts = new CancellationTokenSource(); if (isMultiline) { CancelAndDispose(ref _ghostMultilineSuggestionCts); _ghostMultilineSuggestionCts = cts; ghostMultilineSuggestion = null; } else { CancelAndDispose(ref _ghostSuggestionCts); _ghostSuggestionCts = cts; ghostSuggestion = null; } try { var suggestion = await GetGhostSuggestionAsync(value, cts.Token); if (cts.IsCancellationRequested) return; if (isMultiline) { ghostMultilineSuggestion = suggestion; } else { ghostSuggestion = suggestion; } } catch (OperationCanceledException) { } } private void ClearGhostSuggestion(bool isMultiline) { if (isMultiline) { CancelAndDispose(ref _ghostMultilineSuggestionCts); ghostMultilineSuggestion = null; } else { CancelAndDispose(ref _ghostSuggestionCts); ghostSuggestion = null; } } private static void CancelAndDispose(ref CancellationTokenSource? cts) { cts?.Cancel(); cts?.Dispose(); cts = null; } private static async Task GetGhostSuggestionAsync(string? value, CancellationToken cancellationToken) { await Task.Delay(300, cancellationToken); return GetGhostSuggestion(value); } ``` \n**Trim**: ```razor
[@trimmedValue]
[@notTrimmedValue]
``` ```csharp private string trimmedValue; private string notTrimmedValue; ``` \n**Validation**: ```razor Submit ``` ```csharp public class ValidationTextFieldModel { [Required(ErrorMessage = "This field is required.")] public string Text { get; set; } [RegularExpression("0*[1-9][0-9]*", ErrorMessage = "Only numeric values are allowed.")] public string NumericText { get; set; } [RegularExpression("^[a-zA-Z0-9.]*$", ErrorMessage = "Only letters(a-z), numbers(0-9), and period(.) are allowed.")] public string CharacterText { get; set; } [EmailAddress(ErrorMessage = "Invalid e-mail address.")] public string EmailText { get; set; } [StringLength(5, MinimumLength = 3, ErrorMessage = "The text length must be between 3 and 5 chars.")] public string RangeText { get; set; } } private ValidationTextFieldModel validationTextFieldModel = new(); private void HandleValidSubmit() { } private void HandleInvalidSubmit() { } ``` \n**Background**: ```razor ``` \n**Border**: ```razor ``` \n**Accent**: ```razor ``` \n**External Icons**: ```razor ``` \n**Style & Class**: ```razor ``` ```csharp private string? classesValue; ``` \n**RTL**: ```razor ```