Extras
PhoneInput
BitPhoneInput pairs a searchable country selector - flag, name and dialing code - with a tel input. The two-way bound Value always holds the full number in E.164 form (+[code][number]), while the local digits and the selected country stay available separately through Number and Country. Typing a number with an international prefix ('+' or '00') picks the matching country on its own, the digits are laid out over a per-country pattern as they are typed, and the country list can be searched, reordered, trimmed down or replaced with a fixed country. The field is keyboard and screen-reader driven throughout, and a form can post the composed number and the chosen country as hidden fields of their own.
Notes
To use this component, you need to install the Bit.BlazorUI.Extras(opens in a new tab) nuget package, as described in the Optional steps of the Getting started page.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
Typing a number that already carries an international prefix - either
+ or its
00 equivalent - selects the matching country by itself and keeps only the local digits in
the input, so a pasted number lands correctly whatever the field was showing. Separators are welcome
while typing: spaces, hyphens, dots and parentheses are dropped from the value, never from the field.
AutoFocus
Label & description
aria-required on the input.
Description writes a line under the field for the hint a label is too short to carry, and DescriptionTemplate renders markup there instead. Either way it is tied to the input through
aria-describedby, so it is read with the field rather than as a stray line of text.
Custom countries
BitCountries.All) with one of
your own, which is how a form that only ships to a handful of markets is kept short. The list is also
what the dialing-code lookup searches, so a number pasted with a code outside it is left whole instead
of being attached to the wrong country. Each entry is a BitCountry, so its Name can
be translated and its Code, Iso2 and Iso3 reused as they are.
ExcludeCountries works the other way round and takes a few countries out of the list the other parameters produced, which is the shorter way to say it when the exceptions are what is known - a sanctioned market, a territory a carrier does not reach. What is excluded is gone from the lookup too, so its dialing code no longer selects it.
Preferred countries
BitCountry.Priority, which the built-in list already sets on the country that owns each
shared code, and the country currently selected always wins over both - changing the country is the
user's decision, not the parser's. A country can also answer to more than one code:
BitCountry.ExtraCodes holds the rest of them, which is how +1-829 finds the Dominican
Republic instead of stopping at the +1 it starts with.
Search box
Dropdown display
Clear button
Strict & MaxLength
FullWidth
NoBorder & Underlined
Immediate
Binding
Format as you type
# is a
digit slot and every other character is a separator inserted for the user, so
(###) ###-#### turns 4155550123 into (415) 555-0123. Nothing is lost to it -
digits beyond the last slot are appended as they are, and the separators are display only:
the Value stays the plain E.164 number whatever the field shows. The caret stays on
the digit it was on while the pattern rearranges the text around it, so the middle of a
number is as editable as its end.
National conventions differ from one country to the next, so MaskSelector gives each one a pattern of its own; it takes precedence over Mask whenever it returns something, and returning null leaves that country unformatted. Picking a new country lays the digits already typed out over its pattern instead of keeping the separators of the country left behind.
AutoPlaceholder turns that pattern into the placeholder of the field, so the shape the country expects is offered before anything is typed. It only fills in for a missing Placeholder, and a country whose MaskSelector returns nothing keeps an empty field.
Validation
EditContext automatically and the
data annotations on the model drive it: a failing field gets the bit-inv class and the
aria-invalid="true" attribute. What is validated is the full E.164 Value, which is
why a regular expression on the model can check the dialing code and the length together.
NoValidate opts the field out of the EditContext altogether.
Outside a form the state is forced from the outside: Invalid alone marks the field, and ErrorMessage both marks it and writes the reason under it - for a rejection that comes from a server or from a rule no annotation can express. ErrorMessageTemplate renders markup there instead, and the message is pointed at by
aria-describedby along with any description.
Disabled & ReadOnly
Responsive
Templates
Events
Programmatic control
Picking a country normally hands the focus to the number input, since that is what the user came to type. NoFocusOnSelect leaves it where it was, for a form that decides itself where the focus goes next.
Custom flags
Form submission
Keyboard & autofill
tel input, so a phone keypad is what a touch device offers and
autocomplete="tel" is what a browser fills it from; spell checking, autocorrection and
autocapitalisation are all turned off, since none of them has anything to say about a phone number.
AutoComplete names another autofill token when the field is not the owner's own number
(tel-national, or off), InputMode asks for a different on-screen
keyboard, and EnterKeyHint labels its return key - "next" in the middle of a form, "send" at the
end of one.
Callout
BitDropDirection.TopAndBottom) it drops below the field when there is room and flips
above it when there is not. DropDirection set to All lets it take a side as well,
which is what a field near the bottom of a narrow window needs, and MaxHeight caps how tall it
may grow - a short list is easier to scan than one that fills the window, and a taller one saves a
scroll on a page that has the room for it.
Inside the list the arrow keys wrap around at both ends, so the last country is one press up from the first. NoWrapNavigation stops them at the ends instead, for the users who read the stop as "there is nothing more this way". Home, End, Page Up and Page Down move through it either way.
Color
External Icons
Css, Fa and
Bi) for a shorter syntax. When both parameters are set, the icon one wins. Remember to
reference the icon library's stylesheet in your app.
Size
Style & Class
::deep selector.
RTL
API
Every parameter, public member, sub-class and enum this component exposes.
BitPhoneInput parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AutoFocus | bool | false | Determines if the number input is auto focused on first render. |
| AutoPlaceholder | bool | false | Shows the pattern the number is currently formatted with as the placeholder of the number input, filling in only when no Placeholder of its own is given. |
| Classes | BitPhoneInputClassStyles? | null | Custom CSS classes for different parts of the BitPhoneInput. |
| ClearButtonAriaLabel | string? | null | The aria-label of the clear button of the number input. |
| ClearButtonIcon | BitIconInfo? | null | The icon of the clear button of the number input. Takes precedence over ClearButtonIconName when both are set, and renders icons from external libraries like FontAwesome or Bootstrap Icons. |
| ClearButtonIconName | string? | null | The icon name of the clear button of the number input from the Fluent UI icon set. |
| ClearButtonTemplate | RenderFragment? | null | The custom template for the clear button of the number input. |
| Color | BitColor? | null | The general color of the phone input. |
| Countries | ICollection<BitCountry> | BitCountries.All | The list of the countries to show in the country dropdown. |
| Country | BitCountry? | null | The currently selected country of the phone input. (two-way bound) |
| CountryName | string? | null | The name of the hidden field carrying the ISO 3166-1 alpha-2 code of the selected country, for a plain HTML form that stores the country beside the number. |
| DebounceTime | int | 0 | The debounce time in milliseconds for the number input (applied when Immediate is enabled). |
| DefaultCountry | BitCountry? | null | The default selected country to be initially used when the Country parameter is not set. |
| Description | string? | null | The description shown under the phone input, tied to the number input through aria-describedby. |
| DescriptionTemplate | RenderFragment? | null | The custom template for the description of the phone input. |
| DropDirection | BitDropDirection | BitDropDirection.TopAndBottom | Determines the allowed drop directions of the country dropdown callout. |
| DropdownAriaLabel | string? | null | The aria-label of the country dropdown button. |
| DropdownPlaceholder | string? | null | The placeholder text of the country dropdown when no country is selected. |
| DropdownTemplate | RenderFragment<BitCountry?>? | null | The custom template for the content of the country dropdown button, receiving the selected country. |
| EnterKeyHint | string? | null | Sets the enterkeyhint html attribute of the number input, which decides the label of the return key of an on-screen keyboard. |
| ErrorMessage | string? | null | The error message shown under the phone input, which also puts the field in its invalid state. |
| ErrorMessageTemplate | RenderFragment? | null | The custom template for the error message of the phone input, putting the field in the same invalid state. |
| ExcludeCountries | ICollection<BitCountry>? | null | The countries to leave out of the country dropdown and of the dialing-code lookup behind it. |
| FlagUrlSelector | Func<BitCountry, string?>? | null | The url of the flag image of a country, replacing the flags that ship with the library. Returning null or an empty string leaves that country with the built-in flag. |
| FullWidth | bool | false | Renders the phone input to fill 100% of its container width. |
| Immediate | bool | false | Updates the number input value as the user types (based on the 'oninput' HTML event). |
| InputMode | BitInputMode? | null | Sets the inputmode html attribute of the number input, which decides the on-screen keyboard it asks for. |
| Invalid | bool | false | Renders the phone input in an invalid state without going through the validation of an EditContext. |
| IsOpen | bool | false | Determines the opening state of the country dropdown callout. (two-way bound) |
| ItemTemplate | RenderFragment<BitCountry>? | null | The custom template for each country of the dropdown list. |
| Label | string? | null | The label of the phone input shown above the field. |
| LabelTemplate | RenderFragment? | null | The custom template for the label of the phone input. |
| Mask | string? | null | The pattern the local number is formatted with as the user types, where every '#' is a digit slot and every other character is a literal inserted for them. The formatting is display only: the Value stays in the E.164 form. |
| MaskSelector | Func<BitCountry?, string?>? | null | The pattern to format the local number with for a given country, taking precedence over Mask whenever it returns one. |
| MaxHeight | int? | null | The maximum height of the country dropdown callout in pixels. |
| MaxLength | int | -1 | Determines the maximum number of characters allowed in the number input. |
| NoBorder | bool | false | Removes the border of the phone input. |
| NoDialCode | bool | false | Hides the dialing code of the selected country in the country dropdown button. |
| NoDropdown | bool | false | Removes the country dropdown, so the country of the phone input can only be set through its parameters. |
| NoFlags | bool | false | Hides the flag images of the countries in the dropdown button and in the dropdown list. |
| NoFocusOnSelect | bool | false | Stops the focus from moving to the number input once a country has been picked. |
| NoResultsMessage | string? | null | The message to show when the search result of the country dropdown is empty. |
| NoResultsTemplate | RenderFragment? | null | The custom template to show when the search result of the country dropdown is empty. |
| NoSearchBox | bool | false | Hides the search box of the country dropdown. |
| NoWrapNavigation | bool | false | Stops the keyboard navigation of the country list from wrapping around at its two ends. |
| Number | string? | null | The local phone number exactly as the input shows it, separators and all, without the country dialing code. (two-way bound) |
| OnBlur | EventCallback<FocusEventArgs> | The callback that is invoked when the number input loses focus. | |
| OnClear | EventCallback | The callback that is invoked when the clear button of the number input is clicked. | |
| OnClick | EventCallback<MouseEventArgs> | The callback that is invoked when the number input is clicked. | |
| OnClose | EventCallback | The callback that is invoked when the country dropdown callout closes. | |
| OnCountryChange | EventCallback<BitCountry?> | The callback that is invoked when the selected country changes. | |
| OnEnter | EventCallback<KeyboardEventArgs> | The callback that is invoked when the Enter key is pressed in the number input. | |
| OnEscape | EventCallback<KeyboardEventArgs> | The callback that is invoked when the Escape key is pressed in the number input. | |
| OnFocus | EventCallback<FocusEventArgs> | The callback that is invoked when the number input receives focus. | |
| OnFocusIn | EventCallback<FocusEventArgs> | The callback that is invoked when focus moves into the phone input. | |
| OnFocusOut | EventCallback<FocusEventArgs> | The callback that is invoked when focus moves out of the phone input. | |
| OnKeyDown | EventCallback<KeyboardEventArgs> | The callback that is invoked on every key press in the number input. | |
| OnOpen | EventCallback | The callback that is invoked when the country dropdown callout opens. | |
| OnSearch | EventCallback<string?> | The callback that is invoked when the search text of the country dropdown changes. | |
| Placeholder | string? | null | The placeholder text of the number input. |
| PreferredCountries | ICollection<BitCountry>? | null | The countries to pin to the top of the country dropdown list. They also break the tie when a typed dialing code is shared by several countries. |
| Responsive | bool | false | Shows the country dropdown as a full height panel on small screens instead of an inline callout. |
| ResponsiveCloseButtonAriaLabel | string? | null | The aria-label of the close button of the responsive panel of the country dropdown. |
| ResponsiveCloseIcon | BitIconInfo? | null | The icon of the close button of the responsive panel of the country dropdown. Takes precedence over ResponsiveCloseIconName when both are set. |
| ResponsiveCloseIconName | string? | null | The icon name of the close button of the responsive panel of the country dropdown from the Fluent UI icon set. |
| SearchBoxAriaLabel | string? | null | The aria-label for the search box of the country dropdown. |
| SearchBoxPlaceholder | string? | null | The placeholder text of the search box of the country dropdown. |
| ShowClearButton | bool | false | Shows a clear button in the number input while it holds a value. |
| Size | BitSize? | null | The size of the phone input. |
| Strict | bool | false | Discards every character typed or pasted into the number input that cannot be part of a phone number, so only digits (and an optional leading plus sign) survive. |
| Styles | BitPhoneInputClassStyles? | null | Custom CSS styles for different parts of the BitPhoneInput. |
| ThrottleTime | int | 0 | The throttle time in milliseconds for the number input (applied when Immediate is enabled). |
| Title | string? | null | The tooltip (title attribute) of the phone input. |
| Underlined | bool | false | Renders the phone input with only a bottom border instead of a full one. |
BitTextInputBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| 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. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| 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. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| 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. |
BitPhoneInputClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitPhoneInput. |
| Label | string? | null | Custom CSS classes/styles for the label of the BitPhoneInput. |
| FieldGroup | string? | null | Custom CSS classes/styles for the field group (the container of the country dropdown and the number input) of the BitPhoneInput. |
| Dropdown | string? | null | Custom CSS classes/styles for the country dropdown of the BitPhoneInput. |
| DropdownText | string? | null | Custom CSS classes/styles for the selected country text (flag and dialing code) of the BitPhoneInput. |
| Caret | string? | null | Custom CSS classes/styles for the caret down element of the country dropdown of the BitPhoneInput. |
| Flag | string? | null | Custom CSS classes/styles for the flag image of the countries of the BitPhoneInput. |
| Input | string? | null | Custom CSS classes/styles for the number input (text field) of the BitPhoneInput. |
| ClearButton | string? | null | Custom CSS classes/styles for the clear button of the number input of the BitPhoneInput. |
| ClearButtonIcon | string? | null | Custom CSS classes/styles for the icon of the clear button of the number input of the BitPhoneInput. |
| ErrorMessageContainer | string? | null | Custom CSS classes/styles for the container of the error message of the BitPhoneInput. |
| ErrorMessage | string? | null | Custom CSS classes/styles for the error message of the BitPhoneInput. |
| DescriptionContainer | string? | null | Custom CSS classes/styles for the container of the description of the BitPhoneInput. |
| Description | string? | null | Custom CSS classes/styles for the description of the BitPhoneInput. |
| Overlay | string? | null | Custom CSS classes/styles for the overlay of the country dropdown of the BitPhoneInput. |
| Callout | string? | null | Custom CSS classes/styles for the callout of the country dropdown of the BitPhoneInput. |
| SearchBox | string? | null | Custom CSS classes/styles for the search box of the country dropdown of the BitPhoneInput. |
| ScrollContainer | string? | null | Custom CSS classes/styles for the scroll container of the country dropdown of the BitPhoneInput. |
| List | string? | null | Custom CSS classes/styles for the list (the listbox element) of the country dropdown of the BitPhoneInput. |
| Item | string? | null | Custom CSS classes/styles for each item of the country dropdown of the BitPhoneInput. |
| ItemName | string? | null | Custom CSS classes/styles for the name of each item in the country dropdown of the BitPhoneInput. |
| ItemCode | string? | null | Custom CSS classes/styles for the dialing code of each item in the country dropdown of the BitPhoneInput. |
| NoResults | string? | null | Custom CSS classes/styles for the no results message of the country dropdown of the BitPhoneInput. |
| ResponsiveLabelContainer | string? | null | Custom CSS classes/styles for the label container of the responsive panel of the country dropdown of the BitPhoneInput. |
| ResponsiveLabel | string? | null | Custom CSS classes/styles for the label of the responsive panel of the country dropdown of the BitPhoneInput. |
| ResponsiveCloseButton | string? | null | Custom CSS classes/styles for the close button of the responsive panel of the country dropdown of the BitPhoneInput. |
| ResponsiveCloseIcon | string? | null | Custom CSS classes/styles for the icon of the close button of the responsive panel of the country dropdown of the BitPhoneInput. |
BitCountry properties
Represents the basic information of a specific country.
| Name | Type | Default value | Description |
|---|---|---|---|
| Name | string | The full name of the country. | |
| Code | string | The dialing code of the country. | |
| Iso2 | string | The ISO 3166-1 alpha-2 code of the country. | |
| Iso3 | string | The ISO 3166-1 alpha-3 code of the country. | |
| Priority | int | 0 | The tie-breaking priority of the country among the ones that share its dialing code, where a higher number wins. |
| ExtraCodes | string[]? | null | The other dialing codes the country answers to beyond Code (the Dominican Republic is reached on +1-809, +1-829 and +1-849 alike). |
| DigitsCode | string | The dialing code of the country reduced to its digits, as it appears in an E.164 number. | |
| DigitsCodes | string[] | Every dialing code of the country - Code first, then ExtraCodes - reduced to the digits each of them carries in an E.164 number. |
BitColor enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | |
| Secondary | 1 | |
| Tertiary | 2 | |
| Info | 3 | |
| Success | 4 | |
| Warning | 5 | |
| SevereWarning | 6 | |
| Error | 7 |
BitDropDirection enum
| Name | Value | Description |
|---|---|---|
| All | 0 | |
| TopAndBottom | 1 |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | |
| Medium | 1 | |
| Large | 2 |
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. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.
