Feature Request: Lightweight PhoneInput with Country Code Selector #3160
TheLostByGass
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi 👋
First contribution to the Chakra ecosystem, so apologies if I'm framing anything wrong. I was redirected here from a discussion on the Chakra UI repo (chakra-ui/chakra-ui#10704), where the suggestion was that this belongs in zag-js if it ships with logic.
Why
There's currently no framework-agnostic state machine for the phone number with country selector pattern — a very common shape in sign-up flows, account settings, and contact forms. Today, consumers either:
A documented zag-js answer (machine or recipe) would close this gap.
Scope I'd propose for v1
Intentionally narrow:
Explicitly out of scope for v1:
The main design question
Looking at @zag-js/combobox, it already covers most of what's needed: trigger, listbox, items, keyboard navigation, type-to search, focus management, ARIA wiring. The differences from combobox are essentially:
So my actual question: does this want to be a dedicated @zag-js/phone-input machine, or a recipe/example that composes combobox + a controlled tel input + a derived-value hook? I'm happy to take either direction — I just want to align on the right boundary before writing it.
Proposed shape (if a dedicated machine)
Machine context (sketch):
Consumer-side example (framework-agnostic, Ark UI binding for illustration):
Interaction & accessibility expectations
role="combobox"orbutton+aria-haspopup="listbox",aria-expanded,aria-controlson the listrole="listbox"witharia-activedescendanttracking the highlighted countryrole="option"witharia-selectedfor the current countryfieldmachine fordisabled/invalid/required/readOnly(same pattern as the existinginput-style machines)
Open questions
Item/ValueText.nationalNumberas the raw typed string. Should we leave a hook for a futureformat/parseextension, or keep that purely consumer-side?
internationalValueshape — naive concatenation (dialCode + nationalNumber) for v1, with the understanding that this is notE.164-correct in edge cases. Acceptable for v1, or should we punt on the derived value entirely and let consumers compute it?
Prior art / references
@zag-js/combobox— closest existing machine; phone-input shares ~80% of its interaction surfaceFlowbite phone input — UX reference for the pattern
Lightweight PhoneInput with Country Code Selector chakra-ui#10704 — original discussion that pointed here
Happy to take this to a spike (machine + tests + Ark binding) once we agree on the shape. This is my first OSS contribution, so guidance on the boundary and any zag-js conventions I should follow is very welcome 🙏
Plus, I'm not an engineer hence I'm using coding agents for the proposal and the spike 🤖
Beta Was this translation helpful? Give feedback.
All reactions