Phone number input¶
The phone number input allows a user to enter a phone number by selecting the country (international area code) from a dropdown list and entering the rest of the number in a text input field.
Usage¶

When to use¶
- For allowing users to enter or update a phone number.
- When validation and formatting of international phone numbers are required.
Best practices¶
- Ensure the input field is wide enough to accommodate different international phone number formats.
- Use smart defaults, such as showing the country code and phone number format based on the user's location.
- When collecting non-phone number data, a standard input component should be used.
Design¶
Elements¶

1. Label (optional) 2. Content/placeholder text, 3. Container, 4. Menu, 5. Country code with flag.
Label (optional)¶
Effective form labeling helps users understand what information to enter.

- Keep labels short and clear (should not be wider than the input field).
- A mandatory field is marked with an
*-asterisk.
Interaction states¶

Validation¶
Real-time validation ensures that the data being entered is within a specific range or follows certain rules, preventing errors and ensuring the integrity of the data.

Code¶
Usage¶
import { SiPhoneNumberInputComponent } from '@siemens/element-ng/phone-number';
@Component({
imports: [SiPhoneNumberInputComponent, ...]
})
Required Packages
The versions of the required packages are defined in the peer-dependencies of element-ng. Together with the types package, they are also part of the package.json of the demo app.
- Ensure to import the
node_modules/flag-icons/css/flag-icons.cssto theangular.jsonstyles configuration as follows:
"styles": [
"node_modules/flag-icons/css/flag-icons.css",
...
]
- Set the
supportedCountriesinput array to define the available list of countries. The countries are defined in ISO-3166-2 format. - To display all the available countries, don't add
supportedCountriesinput. - Use the
defaultCountryISO-3166-2 input to select a default. - Set
validatePhoneNumberinput to enable a validation service and show status information in the form control. - Use the
placeholderForSearchinput for a custom placeholder text of the country search. - The
selectCountryAriaLabelinput sets the ARIA label for the country dropdown. - The
phoneNumberAriaLabelinput sets the ARIA label for the phone number input. - All changes are emitted through the
valueChangeoutput.
import { SiPhoneNumberInputComponent } from '@siemens/element-ng/phone-number'; Input Properties¶
| Name | Type | Default | Description |
|---|---|---|---|
| country ¶ | string | undefined | ISO_3166-2 Code of the selected country. | |
| defaultCountry ¶ | string | undefined | ISO_3166-2 Code of the country which shall be used on form-control reset. | |
| disabled ¶ | boolean | false | Whether the input is disabled. |
| errormessageId ¶ | string | `${this.id()}-errormessage` | This ID will be bound to the Implements SiFormItemControl |
| id ¶ | string | `__si-phone-number-input-${SiPhoneNumberInputComponent.idCounter++}` | Unique identifier. Implements SiFormItemControl |
| labelledby ¶ | string | `${this.id()}-label` | ID of the element that labels the phone number input. Implements SiFormItemControl |
| phoneNumberAriaLabel ¶ | TranslatableString | $localize`:@@SI_PHONE_NUMBER_INPUT.PHONE_NUMBER_INPUT_LABEL:Enter phone number` | Text for the phone number input aria-label attribute. |
| placeholderForSearch ¶ | TranslatableString | $localize`:@@SI_PHONE_NUMBER_INPUT.SEARCH_PLACEHOLDER:Search` | Placeholder text for country search input. |
| readonly ¶ | boolean | false | Whether the input can be focused but not edited. |
| scrollStrategy ¶ | ScrollStrategy | defaultConnectedOverlayScrollStrategy() | Optional CDK scroll strategy used for the country selection overlay. |
| searchNoResultsFoundLabel ¶ | TranslatableString | $localize`:@@SI_PHONE_NUMBER_INPUT.SEARCH_NO-RESULTS_FOUND:No results found` | Text shown when the country search returns no results. |
| selectCountryAriaLabel ¶ | TranslatableString | $localize`:@@SI_PHONE_NUMBER_INPUT.SELECT_COUNTRY:Select country` | Text for the country dropdown aria-label attribute. |
| supportedCountries ¶ | readonly string[] | null | undefined | List of countries in ISO2 format, from which the user is allowed to select one. If no values are provided, the dropdown will show all known countries. |
Output Properties¶
| Name | Type | Description |
|---|---|---|
| countryChange ¶ | string | undefined | ISO_3166-2 Code of the selected country. |
| valueChange ¶ | PhoneDetails | Emits the selected country, formatted phone number, and its validity when the value changes. |
Types Documentation¶
Represents a translatable string. This can either be a translation key, e.g. ACTIONS.EDIT that will be automatically translated when displayed on the UI or a pre-translated string, e.g. Edit. Equivalent to a normal string in usage and functionality.
Describes the phone number, its validity and associated country information.
-
CountryInfo object containing name, countryCode and isoCode of the phone number.
-
Confirms if the phone number is valid or not
-
Phone number entered by the user.
Common interface for form item controls. Controls that should be connected to SiFormItemComponent must implement this interface and must be provided using the SI_FORM_ITEM_CONTROL token.
-
Generated ID that the SiFormItemComponent will assign to the element containing the error messages. Implementations of SiFormItemControl must generate this ID and assign it to the
aria-describedbyattribute of their focusable elements.errormessageId:
readonlystring | Signal<string>¶ -
The actual id of the control that should be used in the
forattribute of a label.id?:
readonlystring | Signal<string | undefined>¶ - readonly
If the control is meant to be used a checkbox. This affects the label positioning.
-
ID that should be assigned to the label element inside the SiFormItemComponent.
If the target control is not of type input, select or button, it cannot be referenced by a label. Instead, aria-labelledby must be used to create a reference to a label. In such a case, an implementation of SiFormItemControl must provide the id of the label in labelledby. SiFormItemComponent will apply the id to the label so that it can be used inside the control to reference it in the aria-labelledby attribute.
labelledby?:
readonlystring | Signal<string | undefined> | null¶
Except where otherwise noted, content on this site is licensed under MIT License.