ngxsmk-tel-input 1.6.11 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -42
- package/fesm2022/ngxsmk-tel-input.mjs +534 -277
- package/fesm2022/ngxsmk-tel-input.mjs.map +1 -1
- package/lib/ngxsmk-tel-input.component.d.ts +97 -36
- package/lib/ngxsmk-tel-input.component.d.ts.map +1 -1
- package/lib/ngxsmk-tel-input.service.d.ts +1 -1
- package/lib/ngxsmk-tel-input.service.d.ts.map +1 -1
- package/lib/testing/test-fixtures.d.ts +2 -0
- package/lib/testing/test-fixtures.d.ts.map +1 -1
- package/lib/types-enhanced.d.ts +4 -0
- package/lib/types-enhanced.d.ts.map +1 -1
- package/package.json +12 -6
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -1,53 +1,45 @@
|
|
|
1
1
|
# ngxsmk-tel-input
|
|
2
2
|
|
|
3
|
-
An Angular **
|
|
4
|
-
|
|
3
|
+
An Angular **telephone input** component with country dropdown, flags, and robust validation/formatting.
|
|
4
|
+
Wraps [`intl-tel-input`](https://github.com/jackocnr/intl-tel-input) for the UI and [`libphonenumber-js`](https://github.com/catamphetamine/libphonenumber-js) for parsing/validation. Implements `ControlValueAccessor` so it plugs into Angular Forms.
|
|
5
5
|
|
|
6
6
|
> Emits **E.164** by default (e.g. `+14155550123`). SSR‑safe via lazy browser‑only import.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Try it live on StackBlitz
|
|
9
9
|
|
|
10
|
-
[](https://stackblitz.com/~/github.com/
|
|
10
|
+
[](https://stackblitz.com/~/github.com/NGXSMK/ngxsmk-tel-input)
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Features
|
|
15
15
|
|
|
16
16
|
* Country dropdown with flags
|
|
17
|
-
* E.164 output (display can be
|
|
17
|
+
* E.164 output (display can be configured via `nationalDisplay`)
|
|
18
18
|
* Reactive & template‑driven Forms support (CVA)
|
|
19
19
|
* Built‑in validation using libphonenumber‑js
|
|
20
20
|
* **Enhanced validation**: Detects invalid country codes (like "11", "99") and shows appropriate error states
|
|
21
21
|
* **Mobile responsive**: Optimized for touch devices with proper tap targets, prevents iOS zoom, and responsive dropdown
|
|
22
|
-
* **Dark & Light themes**:
|
|
22
|
+
* **Dark & Light themes**: Comprehensive theme system with automatic system preference detection
|
|
23
23
|
* **Accessibility**: Full ARIA support, screen reader compatibility, keyboard navigation
|
|
24
|
+
* **Integrations & Ionic ready**: Built-in support for Twilio, Vonage, AWS SNS, and Ionic Framework overlays/themes (see [INTEGRATIONS.md](./INTEGRATIONS.md))
|
|
24
25
|
* SSR‑friendly (no `window` on the server)
|
|
25
26
|
* Easy theming via CSS variables
|
|
26
27
|
* Nice UX options: label/hint/error text, sizes, variants, clear button, autofocus, select-on-focus
|
|
27
28
|
* Masking & caret-friendly as-you-type formatting (optional)
|
|
28
29
|
* Format only when valid (formatWhenValid) and lock once valid (lockWhenValid) to prevent extra digits
|
|
29
30
|
|
|
30
|
-
### Demo app highlights
|
|
31
|
-
|
|
32
|
-
The workspace demo (`ng serve demo`) now includes:
|
|
33
|
-
|
|
34
|
-
* polished documentation-style layout with improved spacing and visual hierarchy
|
|
35
|
-
* responsive sidebar/header behavior for mobile and desktop
|
|
36
|
-
* cleaner dark-mode palette with better text/background contrast
|
|
37
|
-
* improved focus states and reduced-motion support for accessibility
|
|
38
|
-
|
|
39
31
|
---
|
|
40
32
|
|
|
41
|
-
##
|
|
33
|
+
## Requirements
|
|
42
34
|
|
|
43
|
-
* Angular **17+** (
|
|
35
|
+
* Angular **17+** (actively tested on Angular 19)
|
|
44
36
|
* Node **18** or **20**
|
|
45
37
|
|
|
46
|
-
> Library `peerDependencies` target Angular `>=17`.
|
|
38
|
+
> Library `peerDependencies` target Angular `>=17`.
|
|
47
39
|
|
|
48
40
|
---
|
|
49
41
|
|
|
50
|
-
##
|
|
42
|
+
## Install
|
|
51
43
|
|
|
52
44
|
```bash
|
|
53
45
|
npm i ngxsmk-tel-input intl-tel-input libphonenumber-js
|
|
@@ -91,7 +83,7 @@ Restart the dev server after changes.
|
|
|
91
83
|
|
|
92
84
|
---
|
|
93
85
|
|
|
94
|
-
##
|
|
86
|
+
## Quick start (Reactive Forms)
|
|
95
87
|
|
|
96
88
|
```ts
|
|
97
89
|
// app.component.ts
|
|
@@ -152,7 +144,7 @@ export class AppComponent {
|
|
|
152
144
|
|
|
153
145
|
---
|
|
154
146
|
|
|
155
|
-
##
|
|
147
|
+
## Template‑driven usage
|
|
156
148
|
|
|
157
149
|
```html
|
|
158
150
|
<form #f="ngForm">
|
|
@@ -163,7 +155,7 @@ export class AppComponent {
|
|
|
163
155
|
|
|
164
156
|
---
|
|
165
157
|
|
|
166
|
-
##
|
|
158
|
+
## Localization & RTL
|
|
167
159
|
|
|
168
160
|
You can localize the dropdown/search labels and override country names.
|
|
169
161
|
|
|
@@ -213,19 +205,23 @@ Arabic + RTL example
|
|
|
213
205
|
```
|
|
214
206
|
|
|
215
207
|
|
|
216
|
-
##
|
|
208
|
+
## API
|
|
217
209
|
|
|
218
210
|
### Inputs
|
|
219
211
|
|
|
220
212
|
| Name | Type | Default | Description |
|
|
221
213
|
|------------------------|---------------------------------------------|-------------------------|-------------------------------------------------------------------------------|
|
|
222
|
-
| `initialCountry` | `CountryCode \| 'auto'` | `'US'` | Starting country. `'auto'` uses geoIp stub (`US` by default).
|
|
214
|
+
| `initialCountry` | `CountryCode \| 'auto'` | `'US'` | Starting country (also respected when initial form value is `''`). `'auto'` uses geoIp stub (`US` by default). |
|
|
223
215
|
| `preferredCountries` | `CountryCode[]` | `['US','GB']` | Pin these at the top. |
|
|
224
216
|
| `onlyCountries` | `CountryCode[]` | — | Limit selectable countries. |
|
|
225
|
-
| `
|
|
226
|
-
| `
|
|
217
|
+
| `excludeCountries` | `CountryCode[]` | `[]` | Exclude specific countries from the dropdown list. |
|
|
218
|
+
| `searchPlaceholder` | `string` | `''` | Custom placeholder text for the dropdown search input. |
|
|
219
|
+
| `showFlags` | `boolean` | `true` | Hide flags completely for minimalist/text-only layouts. |
|
|
220
|
+
| `searchCountryFlag` | `boolean` | `true` | Hide flag icons inside the country dropdown list. |
|
|
221
|
+
| `nationalDisplay` | `'formatted' \| 'digits'` | `'formatted'` | Controls visible input format. Value still emits E.164. |
|
|
222
|
+
| `separateDialCode` | `boolean` | `true` | Show dial code outside the input. |
|
|
227
223
|
| `allowDropdown` | `boolean` | `true` | Enable/disable dropdown. |
|
|
228
|
-
| `placeholder` | `string` |
|
|
224
|
+
| `placeholder` | `string` | — | Input placeholder. |
|
|
229
225
|
| `autocomplete` | `string` | `'tel'` | Native autocomplete. |
|
|
230
226
|
| `disabled` | `boolean` | `false` | Disable the control. |
|
|
231
227
|
| `label` | `string` | — | Optional floating label text. |
|
|
@@ -236,14 +232,15 @@ Arabic + RTL example
|
|
|
236
232
|
| `showClear` | `boolean` | `true` | Show a clear (×) button when not empty. |
|
|
237
233
|
| `autoFocus` | `boolean` | `false` | Focus on init. |
|
|
238
234
|
| `selectOnFocus` | `boolean` | `false` | Select all text on focus. |
|
|
239
|
-
| `
|
|
235
|
+
| `formatWhenValid` | `'off' \| 'blur' \| 'typing'` | `'typing'` | When to format the display value. |
|
|
240
236
|
| `showErrorWhenTouched` | `boolean` | `true` | Show error styles only after blur. |
|
|
237
|
+
| `showErrorMsg` | `boolean` | `true` | Show component's internal validation error message text. |
|
|
241
238
|
| `dropdownAttachToBody` | `boolean` | `true` | Attach dropdown to `<body>` (avoids clipping/overflow). |
|
|
242
239
|
| `dropdownZIndex` | `number` | `2000` | Z‑index for dropdown panel. |
|
|
243
240
|
| `i18n` | `IntlTelI18n` | — | Localize dropdown/search/ARIA labels. |
|
|
244
241
|
| `localizedCountries` | `Partial<Record<CountryCode, string>>` | — | Override country display names (ISO-2 keys). |
|
|
245
242
|
| `dir` | `'ltr' \| 'rtl'` | `'ltr'` | Text direction for the control. |
|
|
246
|
-
| `autoPlaceholder` | `'off' \| 'polite' \| 'aggressive'` | `'
|
|
243
|
+
| `autoPlaceholder` | `'off' \| 'polite' \| 'aggressive'` | `'off'` | Example placeholders. Requires `utilsScript` unless `off`. |
|
|
247
244
|
| `utilsScript` | `string` | — | Path/URL to `utils.js` (needed for example placeholders). |
|
|
248
245
|
| `customPlaceholder` | `(example: string, country: any) => string` | — | Transform the example placeholder. |
|
|
249
246
|
| `clearAriaLabel` | `string` | `'Clear phone number'` | ARIA label for the clear button. |
|
|
@@ -259,18 +256,15 @@ Arabic + RTL example
|
|
|
259
256
|
| `countryChange` | `{ iso2: CountryCode }` | Fired when selected country changes. |
|
|
260
257
|
| `validityChange` | `boolean` | Fired when validity flips. |
|
|
261
258
|
| `inputChange` | `{ raw: string; e164: string \| null; iso2: CountryCode }` | Emitted on every keystroke. |
|
|
262
|
-
| `ready` | `void` | Emitted after plugin + listeners finish wiring (including each re-init cycle). |
|
|
263
259
|
|
|
264
260
|
### Public methods
|
|
265
261
|
|
|
266
262
|
* `focus(): void`
|
|
267
263
|
* `selectCountry(iso2: CountryCode): void`
|
|
268
264
|
|
|
269
|
-
For deterministic first render behavior, prefer setting `[initialCountry]` directly. If you call imperative APIs like `selectCountry(...)` immediately after mount, wait for `(ready)` first.
|
|
270
|
-
|
|
271
265
|
---
|
|
272
266
|
|
|
273
|
-
##
|
|
267
|
+
## Formatting & validity behavior
|
|
274
268
|
|
|
275
269
|
* No formatting while invalid. As-you-type masking only starts when the digits form a valid number for the selected country.
|
|
276
270
|
|
|
@@ -282,7 +276,7 @@ For rare patterns not covered by libphonenumber-js, the control falls back to ra
|
|
|
282
276
|
|
|
283
277
|
---
|
|
284
278
|
|
|
285
|
-
##
|
|
279
|
+
## Theming
|
|
286
280
|
|
|
287
281
|
### CSS Variables
|
|
288
282
|
|
|
@@ -336,7 +330,7 @@ Dark mode: wrap in a `.dark` parent or use `[theme]="'dark'"` — tokens adapt a
|
|
|
336
330
|
|
|
337
331
|
---
|
|
338
332
|
|
|
339
|
-
##
|
|
333
|
+
## Validation patterns
|
|
340
334
|
|
|
341
335
|
```html
|
|
342
336
|
<ngxsmk-tel-input formControlName="phone"></ngxsmk-tel-input>
|
|
@@ -372,14 +366,14 @@ The component now includes enhanced validation that detects and handles various
|
|
|
372
366
|
|
|
373
367
|
---
|
|
374
368
|
|
|
375
|
-
##
|
|
369
|
+
## SSR notes
|
|
376
370
|
|
|
377
371
|
* The library lazy‑imports `intl-tel-input` only in the **browser** (guards with `isPlatformBrowser`).
|
|
378
372
|
* No `window`/`document` usage on the server path.
|
|
379
373
|
|
|
380
374
|
---
|
|
381
375
|
|
|
382
|
-
##
|
|
376
|
+
## Local development
|
|
383
377
|
|
|
384
378
|
This repo is an Angular workspace with a library.
|
|
385
379
|
|
|
@@ -400,7 +394,7 @@ npm i ../path-to-workspace/dist/ngxsmk-tel-input/ngxsmk-tel-input-<version>.tgz
|
|
|
400
394
|
|
|
401
395
|
---
|
|
402
396
|
|
|
403
|
-
##
|
|
397
|
+
## Troubleshooting
|
|
404
398
|
|
|
405
399
|
**UI looks unstyled / bullets in dropdown**
|
|
406
400
|
Add the CSS and assets in `angular.json` (see Install). Restart the dev server.
|
|
@@ -419,13 +413,13 @@ Clear `.angular/cache`, rebuild the lib, and restart `ng serve`.
|
|
|
419
413
|
|
|
420
414
|
---
|
|
421
415
|
|
|
422
|
-
##
|
|
416
|
+
## License
|
|
423
417
|
|
|
424
418
|
[MIT](./LICENSE)
|
|
425
419
|
|
|
426
|
-
##
|
|
420
|
+
## Credits
|
|
427
421
|
|
|
428
422
|
* UI powered by [`intl-tel-input`](https://github.com/jackocnr/intl-tel-input)
|
|
429
423
|
* Parsing & validation by [`libphonenumber-js`](https://github.com/catamphetamine/libphonenumber-js)
|
|
430
424
|
|
|
431
|
-
Last updated:
|
|
425
|
+
Last updated: 2025-01-21
|