-
Notifications
You must be signed in to change notification settings - Fork 45
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
fix(intl-phone-input): fix format outside value #311
Conversation
🦋 Changeset detectedLatest commit: 721f5ac The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Pull Request Test Coverage Report for Build 3375205641
💛 - Coveralls |
Собрана новая демка. |
Собрана новая демка. |
Добавил детект флага после вставки значения извне |
Собрана новая демка. |
Собрана новая демка. |
Собрана новая демка. |
Собрана новая демка. |
packages/base-modal/src/utils.ts
Outdated
|
||
export const restoreContainerStyles = (container: HTMLElement) => { | ||
const modalRestoreStyles = getModalStore().getRestoreStyles(); | ||
|
||
const index = modalRestoreStyles.findIndex(s => s.container === container); | ||
const index = modalRestoreStyles.findIndex((s) => s.container === container); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Как-то линтер не правильно отработал. Должно было остаться без скобок. И остальные изменения тоже странные
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хотя, и у меня тоже стало также...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Откати все лишние изменения и подлей мастер ветку
готово |
Собрана новая демка. |
[countryIso2], | ||
); | ||
|
||
const formatedValue = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему ты форматируешь значение внутри компонента? Так в инпут попадает отформатированное значение, а в стейте остается неотформатированное
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
форматирую внутри компонента, потому что тут задача уже решается внутри компонента. А если снаружи отформатировать и форматирование будет отличаться от внутреннего - будут скачки. Более того тут используется библиотека для форматирования, которая не используется в других приложениях банка. Это внутренняя задача компонента, если значение пришло не отформатированным - его нужно форматировать
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- страна не определится, если мы извне поменяем значение
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я понимаю, я о том, что так получается рассинхрон со внешним стейтом, такого быть не должно. У тебя во внешнем стейте будет номер +79991111111, а в инпуте +7 999 111-11-11. Хотя на onChange улетает отформатированный номер. Это нужно исправить - либо там и там отформатированный номер, либо всегда внутри компонента отформатированный, а во внешнем стейте нет. Сейчас рандом полный
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
выглядит как мажорные изменения. Что если при получении неотформатированного значения просто вызывать onChange с отформатированным номером? Тогда и внешний и внутренний стейт будут в норме
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Что если при получении неотформатированного значения просто вызывать onChange с отформатированным номером?" - вроде это сделать и нужно
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
спасибо, сразу не сообразил. Поправил
}; | ||
return targetCountry; | ||
}, | ||
[countries, countryIso2], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На каждый рендер прилетает новое значение countries, смысла с этого useCallback тут нет. Соответственно useEffect ниже на каждый рендер вызывается
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint-ом бы еще пройтись по файлу
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а почему прилетает новое значение countries? из-за дефолтного значения с вызовом функции? для чего это сделано?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
и как это лучше разрулить? в голову приходит только убрать тут countries из зависимостей
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
или убрать вызов метода из дефолта пропса
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать все useCallback и из зависимостей useEffect убрать getCountryByNumber и отключить eslint - eslint-disable-next-line react-hooks/exhaustive-deps ))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
спасибо, поправил
Собрана новая демка. |
Собрана новая демка. |
@@ -468,6 +466,26 @@ export const IntlPhoneInput = forwardRef<HTMLInputElement, IntlPhoneInputProps>( | |||
/* eslint-disable-next-line react-hooks/exhaustive-deps */ | |||
}, [value]); | |||
|
|||
useEffect(() => { | |||
if (value && value.length > 1 && !value.includes(' ')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Было бы неплохо описать эту логику в комментах
Исправлено форматирование номера в intl-phone-input, который передаётся снаружи компонента в props value