feat: phone input autocomplete#3624
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Size Change: +829 B (+0.12%) Total Size: 676 kB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3624 +/- ##
==========================================
- Coverage 93.69% 93.68% -0.01%
==========================================
Files 199 199
Lines 4486 4531 +45
Branches 1768 1779 +11
==========================================
+ Hits 4203 4245 +42
- Misses 256 259 +3
Partials 27 27
🚀 New features to boost your workflow:
|
|
Thank you for your contribution, Nico ! |
@sirineJ I will prepare it for review without the variant 🙌 |
| renderPrefix={Prefix} | ||
| />, | ||
| ); | ||
| expect(screen.getByTestId('prefix')).toHaveTextContent('CA'); |
There was a problem hiding this comment.
Prefer getByText() over getByTestId() to better mimic users' perception of the UI
| expect(screen.getByTestId('prefix')).toHaveTextContent('CA'); | |
| expect(screen.getByText('CA')).toBeVisible(); |
| position: absolute; | ||
| top: 50%; | ||
| left: 0; | ||
| z-index: calc(var(--cui-z-index-input) + 1); |
There was a problem hiding this comment.
why assign a z-index value ?
There was a problem hiding this comment.
There was a border conflict before when having the Select, removed now 👍
| defaultValue={defaultValue} | ||
| {...props} | ||
| /> | ||
| {readOnly || countryCode.readonly ? ( |
There was a problem hiding this comment.
Do we still need this readOnly Input now that we have the AutocompleteInput that also supports a read only state ?
There was a problem hiding this comment.
good question, this is what I considered:
- this keeps the same content (writing only the input text without full country name)
- in terms of accessibility is a much simpler structure and more direct semantics
- less content (no options)
There was a problem hiding this comment.
I find this makes the component even more complex (which it already is). The options (and the Autocomplete) are already there and I don't see a valid reason as to why not use it directly. As for the presentation content, I find it strange that the read only content is different from the active state (I know this is already how the component currently is and not your implementation). I also checked figma and the read-only content is the same as the active state. So this makes a good opportunity to align them.
| renderPrefix={countryCode.renderPrefix ?? DefaultPrefix} | ||
| /> | ||
| <div className={classes['country-code-autocomplete-shell']}> | ||
| <input |
There was a problem hiding this comment.
What is the purpose of this hidden input ?
There was a problem hiding this comment.
Very good point, thanks.
It's only to keep the onChange sending the same target.
If we change to react state, we could remove the setVersion hack but it would break the onChange contract
I don't have a strong opinion / reason to prefer one over the other, wdyt?
There was a problem hiding this comment.
That is a valid point about the API !
We also changed the type of the country code ref to be HTMLInputElement instead of HTMLSelectElement | HTMLInputElement, which makes them breaking changes :/
I think this change need to be part of the next major (planned for early Q3)
There was a problem hiding this comment.
I will change the target branch to next and keep you posted !
| disabled={disabled} | ||
| size={size} | ||
| className={clsx( | ||
| classes['country-code'], |
There was a problem hiding this comment.
can we merge these two classNames ?
| classes['country-code'], | ||
| classes['country-code-autocomplete'], | ||
| )} | ||
| comboboxClassName={classes['country-code-combobox']} |
There was a problem hiding this comment.
instead of passing down a className prop, what do you think about using a [role="combobox] selector to target the input ?
| flex: 0 0 auto; | ||
| margin-right: -1px; | ||
| } | ||
|
|
There was a problem hiding this comment.
Can we make the flags rectangular instead of circular ? 🙏
| .country-code-autocomplete-shell [role="option"] img { | |
| height: var(--cui-icon-sizes-mega); | |
| width: var(--cui-icon-sizes-giga); | |
| border-radius: var(--cui-border-radius-bit); | |
| } |
| countryCode={value as FlagProps['countryCode']} | ||
| alt="" | ||
| className={className} | ||
| width={16} |
There was a problem hiding this comment.
The Flag component already defaults to a width of 16, can we keep that here instead of overriding?
| disabled={disabled} | ||
| readOnly={readOnly} | ||
| tabIndex={-1} | ||
| aria-hidden="true" |
There was a problem hiding this comment.
Since type="hidden" already handles non-focusability and accessibility tree exclusion, are the last three props needed here?
Details: - Simplified the rendering of the prefix in ComboboxInput tests. - Updated test assertions to check for visibility instead of test ID. - Removed unused `comboboxClassName` prop from ComboboxInput. - Enhanced PhoneNumberInput to render the country code as a read-only input when specified. - Adjusted styles for country code autocomplete to improve layout and responsiveness.
it was introduced because of a conflict with select now removed
simplify styles further
|
Hey many thanks for the great review... I think everything was tackled / answered, lmk wdyt! |
Purpose
People choosing their country of phone number sometimes have to scroll / swipe a lot to find their country
With this variant, the users can filter their country by typing any part of it (including prefix and screen keyboard in mobile) instead of finding with only the first letter if they have a keyboard
Approach and changes
Demo: https://oss-circuit-ui-git-phone-input-autocomplete.sumup-vercel.app/?path=/story/forms-autocompleteinput--base
Definition of done