-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat(new-hope): add react hook form support in combobox #1552
base: dev
Are you sure you want to change the base?
Conversation
Theme Builder app deployed! https://plasma.sberdevices.ru/pr/plasma-theme-builder-pr-1552/ |
Documentation preview deployed! website:https://plasma.sberdevices.ru/pr/pr-1552/ |
packages/plasma-new-hope/src/components/Combobox/ComboboxNew/Combobox.tsx
Outdated
Show resolved
Hide resolved
outerOnChange(newValue as string & string[] & ChangeEvent<HTMLSelectElement>); | ||
} | ||
|
||
if (!name && multiple && Array.isArray(newValue)) { | ||
outerOnChange(newValue as string & string[] & ChangeEvent<HTMLSelectElement>); | ||
} | ||
|
||
if (name && typeof newValue === 'object' && !Array.isArray(newValue)) { | ||
outerOnChange(newValue as string & string[] & ChangeEvent<HTMLSelectElement>); |
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.
Кажется, что условия можно объединить, чтобы не дублировать outerOnChange(newValue as string & string[] & ChangeEvent<HTMLSelectElement>);
@@ -343,7 +383,7 @@ export const comboboxRoot = (Root: RootProps<HTMLInputElement, Omit<ComboboxProp | |||
listWidth={listWidth} | |||
target={(referenceRef) => ( | |||
<StyledTextField | |||
ref={inputForkRef} | |||
ref={name ? inputRef : (inputForkRef as React.ForwardedRef<HTMLInputElement>)} |
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.
Тоже без React.
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.
Можешь вкратце описать, почему итоговая ref зависит от name?
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.
От name зависит итоговый исходящий тип. Если он есть, то он считает, что это форма. Если нет, то обычный тип.
А ref надо обязательно прокидывать именно в select, если вариант с формой
packages/plasma-new-hope/src/components/Combobox/ComboboxNew/Combobox.types.ts
Outdated
Show resolved
Hide resolved
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.
Кажется, что нейминг немного нужно поменять. Это же не отдельный компонент Form, а только SelectHidden
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.
Тут больше логика, что это для формы штука. И потом в select и autocomplite будет нейминг такой же с таким де принципом работы. Поэтому сделал так
packages/plasma-new-hope/src/components/Combobox/ComboboxNew/ui/Form/Form.tsx
Outdated
Show resolved
Hide resolved
}; | ||
|
||
export const Form = forwardRef<HTMLSelectElement, Props>(({ name, multiple, value, onChange }, ref) => { | ||
const values = (multiple ? value : [value]) as string[]; |
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.
Можем избавиться от каста к string[]
? Кажется на уровне Props
проще переопределить
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.
Ну можно уйти, если сделать разветвление на multi и на single. Поэтому так проще и практичней
packages/plasma-new-hope/src/components/Combobox/ComboboxNew/utils/syntheticEvent.ts
Outdated
Show resolved
Hide resolved
packages/plasma-new-hope/src/examples/plasma_b2c/components/Combobox/Combobox.stories.tsx
Outdated
Show resolved
Hide resolved
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.
Размножь на другие доки тоже
af2c988
to
e4e21b9
Compare
Адаптация Combobox для ReactHookForm
react-hook-form
для компонентаcombobox
What/why changed (Это обязательный заголовок)
📦 Published PR as canary version:
Canary Versions
✨ Test out this PR locally via: