-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Bug Report - Typing +
into input does not display it until follow up digit is entered
#54
Comments
I see what you mean, but I would not consider it a bug or even an issue. Users don't have to input |
Sure, I can try if you point me to correct way :) Should this be handled in |
I think this must have been an option for the |
Ok, I'll take a stab at this this week hopefully - finishing implementation of phone input using the lib at the moment at my company, will know more by then. I was following examples in
This also clears entered To overcome this, i made a wrapper. Seems to work.. import { getFormattedNumber as getFormattedNumberCore } from 'react-phone-hooks`;
export const getFormattedNumber = (raw: string, pattern: string) => {
// do not clear entered plus sign
if (raw === '+') return raw;
return getFormattedNumberCore(raw, pattern);
} |
Okay, and what about having a static |
One downside I see with It will probably lead to more overhead / cases to handle - Another problem may be with form libraries (e.g. Formik) which uses This may also can get in the way if in the future there's gonna be a feature to enter phones in national format (without + / country code). Just speculating of course, but somehow strongly leaning towards option for hooks, where |
Okay, I see your point, but what about not including it in the value? It can be a static part of the input component outside the input box. Interesting point of view, by the way :) Like the way you think. |
This will break current behaviour / we'll need changing formatted value displayed in input and won't fix original issue: typing Another big issue is that this will require more work with styles. I assume how this is used is something like: <div className="flex items-center gap-4">
<select />
<input />
</div>
// ...or (most likely), from existing components in your design system
<FormRow>
<SelectField />
<Text>+</Text>
<TextField />
</FormFow>
// ...or
<TextField leftElement={<SelectField />} />
Beauty and selling point of this lib is that it doesn't do too much and just provides hook / props for your inputs and that's it. Then developers can reuse their own components without thinking too much / needing to worry about setting this up properly. Suggest not throwing that away :) |
Okay, let's proceed with the initial scenario. |
Bug description
When starting to type international number in empty input, entering
+
doesn't display it right away, only when entering number after that. It seems confusing and makes end users wonder if something is not working.I'd expect seeing
+
in input right away.Didn't dig too much into the code, but seems that problem is with
getFormattedNumber()
, which returns empty string if passed raw value is+
. It's used internally inuseMask
'sonInput
handler andevent.target.value
is mutated / cleared, as method return empty string in that case.Maybe that's expected behaviour. If so, would like to understand motivation behind this
As workaround for this, I'm not calling
onInput
if input value is+
Reproduction URL
https://playground.typesnippet.org/mui-phone-input/
Reproduction steps
+
with keyboard - no change in inputScreenshots
Logs
No response
Browsers
Safari
OS
Mac
The text was updated successfully, but these errors were encountered: