@input-kit/phone 0.4.1 → 0.5.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 CHANGED
@@ -8,24 +8,29 @@
8
8
 
9
9
  Headless React phone input with a complete world country-code dataset, searchable country selection, and `libphonenumber-js` powered formatting and validation.
10
10
 
11
- Source, issues, and contributions: **[github.com/harshit-d3v/input-kit-phone](https://github.com/harshit-d3v/input-kit-phone)** if this package saves you time, a ⭐ there helps others find it.
11
+ Source, issues, and contributions: **[github.com/harshit-d3v/input-kit-phone](https://github.com/harshit-d3v/input-kit-phone)**. If this package saves you time, a ⭐ there helps others find it.
12
12
 
13
13
  ## Latest update
14
14
 
15
- **0.4.0** **correctness fixes, please upgrade.** E.164 was built by concatenating the dial code onto whatever was typed, so the national trunk prefix people actually type survived into the international form: UK `07400123456` became `+4407400123456`, and India, Germany, France and Australia were wrong the same way. Around 106 countries were affected, validation still reported these as valid, and North American numbers never were — which is why it went unnoticed. Now resolved through libphonenumber metadata, so countries that genuinely keep a leading zero (Italy) still do. Also fixes: an inline `onValidationChange` causing "Maximum update depth exceeded"; input past the country maximum being discarded instead of truncated, which silently blanked an empty field on paste; a country selection that reverted on international numbers; the country button not announcing the selected country to screen readers; focus dropping to the top of the page when the dropdown closed; and types failing to resolve for CommonJS TypeScript consumers under `node16`/`nodenext`.
15
+ **0.5.0**: lighter install. Dropped the `world-countries` runtime dependency (~600 kB unpacked); the names and dial codes it provided are now generated into the package (about 26 kB). The country list is byte-identical, nothing else changes.
16
16
 
17
- **0.3.0** auto-detect respects manual country selection, metadata-based length validation (no more false `too_long` in variable-length countries), input capped at the country's maximum length, `isPhoneTooLong()`, SSR-safe caret handling, dropdown `Home`/`End` + search→list keyboard navigation, unminified published output.
17
+ **0.4.2**: documents and locks the built-in **format as you type**. Live national formatting on every keystroke was already there (`formatOnType`, on by default), but it was barely documented and had no regression tests. Added a README section and seven tests covering national, international, per-country, delete and paste formatting, plus proof that the stored and submitted value stays clean. No behavior change.
18
18
 
19
- **0.2.2** npm README cleanup: release notes stay inline; removed pointers to repo-only markdown files.
19
+ **0.4.0**: **correctness fixes, please upgrade.** E.164 was built by concatenating the dial code onto whatever was typed, so the national trunk prefix people actually type survived into the international form: UK `07400123456` became `+4407400123456`, and India, Germany, France and Australia were wrong the same way. Around 106 countries were affected, validation still reported these as valid, and North American numbers never were, which is why it went unnoticed. Now resolved through libphonenumber metadata, so countries that genuinely keep a leading zero (Italy) still do. Also fixes: an inline `onValidationChange` causing "Maximum update depth exceeded"; input past the country maximum being discarded instead of truncated, which silently blanked an empty field on paste; a country selection that reverted on international numbers; the country button not announcing the selected country to screen readers; focus dropping to the top of the page when the dropdown closed; and types failing to resolve for CommonJS TypeScript consumers under `node16`/`nodenext`.
20
20
 
21
- **0.2.0** structured validation (`ValidationReason`, `validatePhoneNumber`, `onValidationChange`), `parsePhoneValue`, `getCountryOptions()`, improved `PhoneInput` a11y (click-outside, listbox ARIA) and RTL tests.
21
+ **0.3.0**: auto-detect respects manual country selection, metadata-based length validation (no more false `too_long` in variable-length countries), input capped at the country's maximum length, `isPhoneTooLong()`, SSR-safe caret handling, dropdown `Home`/`End` + search→list keyboard navigation, unminified published output.
22
+
23
+ **0.2.2**: npm README cleanup: release notes stay inline; removed pointers to repo-only markdown files.
24
+
25
+ **0.2.0**: structured validation (`ValidationReason`, `validatePhoneNumber`, `onValidationChange`), `parsePhoneValue`, `getCountryOptions()`, improved `PhoneInput` a11y (click-outside, listbox ARIA) and RTL tests.
22
26
 
23
27
  ## Features
24
28
 
25
- - **245 supported calling regions** derived from `libphonenumber-js` metadata and `world-countries`
26
- - **Headless hook** via `usePhoneInput()` plus an optional **unstyled reference** `PhoneInput` component (class names only no bundled CSS)
29
+ - **245 supported calling regions** derived from `libphonenumber-js` metadata, with names and dial codes generated into the package so there is no heavy country-data dependency to install
30
+ - **Headless hook** via `usePhoneInput()` plus an optional **unstyled reference** `PhoneInput` component (class names only, no bundled CSS)
27
31
  - **Searchable country selector** with country name, ISO code, and dial-code matching
28
- - **Real formatting and validation** powered by `libphonenumber-js`
32
+ - **Format as you type** in the selected country's format, on every keystroke, powered by `libphonenumber-js`
33
+ - **Real validation** powered by `libphonenumber-js`
29
34
  - **International detection** for pasted or typed `+` / `00` numbers
30
35
  - **TypeScript-first** exports for countries, helpers, hook return values, and component refs
31
36
 
@@ -41,7 +46,7 @@ npm install @input-kit/phone
41
46
 
42
47
  ```tsx
43
48
  import { PhoneInput } from '@input-kit/phone';
44
- import './phone-input.css'; // your own stylesheet the package ships no CSS
49
+ import './phone-input.css'; // your own stylesheet, the package ships no CSS
45
50
 
46
51
  function Example() {
47
52
  return (
@@ -97,6 +102,24 @@ function Example() {
97
102
  }
98
103
  ```
99
104
 
105
+ ## Format as you type
106
+
107
+ `inputProps.value` reformats on every keystroke in the selected country's national format, so the field reads `(555) 123-4567` while the user types. Typing a `+` switches to international format (`+1 555 123 4567`). This is on by default; set `formatOnType: false` for raw digits.
108
+
109
+ The formatting is display only. `onChange`, `phone`, `fullPhone` and `parsePhoneValue` still give you the clean value, so what you store and submit is never the formatted string.
110
+
111
+ ```tsx
112
+ const { inputProps, fullPhone } = usePhoneInput({
113
+ defaultCountry: 'US',
114
+ includeDialCode: true,
115
+ onChange: (phone) => console.log(phone), // +15551234567, not "(555) 123-4567"
116
+ });
117
+
118
+ // user types 5551234567
119
+ // inputProps.value -> "(555) 123-4567"
120
+ // fullPhone -> "+15551234567"
121
+ ```
122
+
100
123
  ## Phone values
101
124
 
102
125
  | Field | Meaning |
@@ -104,7 +127,7 @@ function Example() {
104
127
  | `phone` | National digits stored by the hook (default) |
105
128
  | `fullPhone` | National number plus dial code when `includeDialCode` is `true` |
106
129
  | `onChange(phone, country)` | Same contract as `phone` / `includeDialCode` |
107
- | E.164 for APIs | `parsePhoneValue(phone, country).e164` when valid prefer this over raw concatenation |
130
+ | E.164 for APIs | `parsePhoneValue(phone, country).e164` when valid. Prefer this over raw concatenation |
108
131
 
109
132
  ## Known behavior
110
133
 
@@ -151,7 +174,7 @@ Manual browser check: `test-demo/` (static HTML).
151
174
 
152
175
  ## Contributing
153
176
 
154
- Bug reports, feature requests, and pull requests are welcome see [CONTRIBUTING.md](https://github.com/harshit-d3v/input-kit-phone/blob/main/CONTRIBUTING.md). In short: open an issue with a minimal reproduction (include the exact phone number and country for formatting/validation bugs), and for PRs run `bun run test`, `bun run typecheck`, and `bun run lint` before submitting.
177
+ Bug reports, feature requests, and pull requests are welcome, see [CONTRIBUTING.md](https://github.com/harshit-d3v/input-kit-phone/blob/main/CONTRIBUTING.md). In short: open an issue with a minimal reproduction (include the exact phone number and country for formatting/validation bugs), and for PRs run `bun run test`, `bun run typecheck`, and `bun run lint` before submitting.
155
178
 
156
179
  ## Exports
157
180