ngx-dial-input 2.1.1 → 2.1.2
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 +193 -13
- package/esm2020/data/countries.mjs +4 -4
- package/esm2020/lib/phone-input.component.mjs +4 -4
- package/esm2020/lib/phone-input.module.mjs +5 -5
- package/fesm2015/ngx-dial-input.mjs +10 -10
- package/fesm2015/ngx-dial-input.mjs.map +1 -1
- package/fesm2020/ngx-dial-input.mjs +10 -10
- package/fesm2020/ngx-dial-input.mjs.map +1 -1
- package/package.json +3 -2
- package/esm2020/ngx-country-dial-input.mjs +0 -5
- package/fesm2015/ngx-country-dial-input.mjs +0 -1673
- package/fesm2015/ngx-country-dial-input.mjs.map +0 -1
- package/fesm2020/ngx-country-dial-input.mjs +0 -1669
- package/fesm2020/ngx-country-dial-input.mjs.map +0 -1
- package/ngx-dial-input-2.0.2.tgz +0 -0
- package/ngx-dial-input-2.0.8.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,24 +1,204 @@
|
|
|
1
|
-
#
|
|
1
|
+
# PhoneInputComponent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> A powerful Angular phone input component with international country selection, automatic formatting, and validation.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Part of **ngx-dial-input** library. See main [README](../../README.md) for general information.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project phone-input` or else it will be added to the default project in your `angular.json` file.
|
|
7
|
+
## Component Inputs
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
| Input | Type | Default | Description |
|
|
10
|
+
|-------|------|---------|-------------|
|
|
11
|
+
| `defaultCountry` | `string` | `''` | ISO 2-letter country code (e.g., 'US', 'GB', 'IN') |
|
|
12
|
+
| `placeholder` | `string` | `''` | Placeholder text in the phone input field |
|
|
13
|
+
| `searchEnabled` | `boolean` | `true` | Enable/disable country search in dropdown |
|
|
14
|
+
| `numberFormat` | `'international' \| 'national'` | `'international'` | Phone number format: +12015551234 (international) or 2015551234 (national) |
|
|
15
|
+
| `setFirstCountry` | `string` | `''` | Pre-select a specific country |
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
## Component Output
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
### phoneChange Event
|
|
15
20
|
|
|
16
|
-
|
|
21
|
+
Emitted when phone value changes:
|
|
17
22
|
|
|
18
|
-
|
|
23
|
+
```typescript
|
|
24
|
+
interface PhoneData {
|
|
25
|
+
e164Number: string; // '+12015551234' - International format for storage
|
|
26
|
+
nationalNumber: string; // '2015551234' - Just the digits
|
|
27
|
+
dialCode: string; // '+1' - Country dial code
|
|
28
|
+
countryCode: string; // 'us' - ISO 2-letter code (lowercase)
|
|
29
|
+
isValid: boolean; // true/false - Validation status
|
|
30
|
+
}
|
|
31
|
+
```
|
|
19
32
|
|
|
20
|
-
|
|
33
|
+
## Usage Example
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
### Reactive Forms
|
|
23
36
|
|
|
24
|
-
|
|
37
|
+
```typescript
|
|
38
|
+
import { Component } from '@angular/core';
|
|
39
|
+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
|
40
|
+
import { PhoneInputModule } from 'ngx-dial-input';
|
|
41
|
+
|
|
42
|
+
@Component({
|
|
43
|
+
selector: 'app-contact-form',
|
|
44
|
+
template: `
|
|
45
|
+
<form [formGroup]="form" (ngSubmit)="submit()">
|
|
46
|
+
<div class="form-group">
|
|
47
|
+
<label>Phone Number</label>
|
|
48
|
+
<phone-input
|
|
49
|
+
[defaultCountry]="'US'"
|
|
50
|
+
[placeholder]="'Enter phone number'"
|
|
51
|
+
[searchEnabled]="true"
|
|
52
|
+
formControlName="phone"
|
|
53
|
+
(phoneChange)="onPhoneChange($event)">
|
|
54
|
+
</phone-input>
|
|
55
|
+
<small *ngIf="form.get('phone').invalid && form.get('phone').touched">
|
|
56
|
+
Please enter a valid phone number
|
|
57
|
+
</small>
|
|
58
|
+
</div>
|
|
59
|
+
<button type="submit" [disabled]="form.invalid">Submit</button>
|
|
60
|
+
</form>
|
|
61
|
+
`,
|
|
62
|
+
standalone: false
|
|
63
|
+
})
|
|
64
|
+
export class ContactFormComponent {
|
|
65
|
+
form: FormGroup;
|
|
66
|
+
|
|
67
|
+
constructor(private fb: FormBuilder) {
|
|
68
|
+
this.form = this.fb.group({
|
|
69
|
+
phone: [null, Validators.required]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
onPhoneChange(data: any) {
|
|
74
|
+
if (data.isValid) {
|
|
75
|
+
console.log('Valid phone (e164):', data.e164Number);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
submit() {
|
|
80
|
+
const phoneData = this.form.get('phone').value;
|
|
81
|
+
console.log('Phone to save:', phoneData.e164Number);
|
|
82
|
+
// API call to save phone
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### With Default Country
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<phone-input
|
|
91
|
+
[defaultCountry]="'GB'"
|
|
92
|
+
[setFirstCountry]="'GB'"
|
|
93
|
+
[numberFormat]="'national'"
|
|
94
|
+
formControlName="phone">
|
|
95
|
+
</phone-input>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Validation Behavior
|
|
99
|
+
|
|
100
|
+
### Empty Input
|
|
101
|
+
- Initial state with no input: `isValid = false` (but no validation error)
|
|
102
|
+
- Allows users to leave the field empty until they start typing
|
|
103
|
+
|
|
104
|
+
### Partial Input
|
|
105
|
+
- Once user starts typing, validates against country's minimum length
|
|
106
|
+
- Phone with insufficient digits: `isValid = false`
|
|
107
|
+
|
|
108
|
+
### Complete Input
|
|
109
|
+
- Phone matching country's required length: `isValid = true`
|
|
110
|
+
- Phone exceeding max length: `isValid = false`
|
|
111
|
+
|
|
112
|
+
### Example
|
|
113
|
+
```
|
|
114
|
+
Country: United States (min: 10 digits, max: 10 digits)
|
|
115
|
+
- Empty (no input): isValid = false, no error
|
|
116
|
+
- Entering: '201' (3 digits): isValid = false, too short
|
|
117
|
+
- Complete: '2015551234' (10 digits): isValid = true
|
|
118
|
+
- Excess: '20155512345' (11 digits): isValid = false, too long
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Supported Features
|
|
122
|
+
|
|
123
|
+
✅ **200+ Countries** with:
|
|
124
|
+
- Dial codes
|
|
125
|
+
- Flag images
|
|
126
|
+
- Min/max phone length
|
|
127
|
+
- Format patterns
|
|
128
|
+
|
|
129
|
+
✅ **Smart Search**
|
|
130
|
+
- Search by country name
|
|
131
|
+
- Case-insensitive matching
|
|
132
|
+
- Fast filtering
|
|
133
|
+
|
|
134
|
+
✅ **Animations**
|
|
135
|
+
- Smooth dropdown open/close
|
|
136
|
+
- Responsive to user interactions
|
|
137
|
+
|
|
138
|
+
✅ **Keyboard Support**
|
|
139
|
+
- Arrow keys to navigate
|
|
140
|
+
- Enter to select
|
|
141
|
+
- Escape to close dropdown
|
|
142
|
+
|
|
143
|
+
✅ **ControlValueAccessor**
|
|
144
|
+
- Works with `formControlName`
|
|
145
|
+
- Works with `[(ngModel)]`
|
|
146
|
+
- Works with Reactive Forms and Template Forms
|
|
147
|
+
|
|
148
|
+
## Building & Testing
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Build the library
|
|
152
|
+
ng build phone-input
|
|
153
|
+
|
|
154
|
+
# Run unit tests
|
|
155
|
+
ng test phone-input --watch
|
|
156
|
+
|
|
157
|
+
# Run tests (CI mode, no watch)
|
|
158
|
+
ng test phone-input --watch=false --browsers=ChromeHeadless
|
|
159
|
+
|
|
160
|
+
# Create distributable package
|
|
161
|
+
npm run build
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Output Structure
|
|
165
|
+
|
|
166
|
+
After building:
|
|
167
|
+
```
|
|
168
|
+
dist/
|
|
169
|
+
phone-input/
|
|
170
|
+
lib/
|
|
171
|
+
phone-input.component.d.ts
|
|
172
|
+
phone-input.module.d.ts
|
|
173
|
+
package.json
|
|
174
|
+
README.md
|
|
175
|
+
LICENSE
|
|
176
|
+
phone-input.d.ts (public API)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Browser Compatibility
|
|
180
|
+
|
|
181
|
+
- Chrome 90+
|
|
182
|
+
- Firefox 88+
|
|
183
|
+
- Safari 14+
|
|
184
|
+
- Edge 90+
|
|
185
|
+
|
|
186
|
+
## Performance
|
|
187
|
+
|
|
188
|
+
- Component uses OnPush change detection
|
|
189
|
+
- Optimized country list filtering
|
|
190
|
+
- Minimal re-renders
|
|
191
|
+
|
|
192
|
+
## Accessibility
|
|
193
|
+
|
|
194
|
+
- Semantic HTML structure
|
|
195
|
+
- Keyboard navigation support
|
|
196
|
+
- ARIA labels on country selector
|
|
197
|
+
|
|
198
|
+
## Contributing
|
|
199
|
+
|
|
200
|
+
Issues and PRs are welcome on [GitHub](https://github.com/CroemInc/ngx-dial-input)
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
MIT © [CroemInc](https://github.com/CroemInc)
|