-
Notifications
You must be signed in to change notification settings - Fork 131
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(Input, Combobox): add showCleanCross prop #3594
base: next
Are you sure you want to change the base?
Conversation
8432121
to
4cf6e49
Compare
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.
Пример в доку Autocomplete, так как он наследует свойство инпута showCleanCross
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.
Тест, проверяющий что в Autocomplete работает свойство showCleanCross. Достаточно selenium теста, так как визуально всё аналогично инпуту
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.
Creevey-тест, проверяющий Combobox:
- появление крестика при вводе в инпут
- очистка при клике на крестик
- фокусировка по табу на крестике
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.
Пример в доку ComboBox
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.
История для теста Combobox
@@ -446,6 +453,20 @@ export class Input extends React.Component<InputProps, InputState> { | |||
|
|||
return ( | |||
<InputLayout | |||
clearInput={() => { | |||
if (this.props.onValueChange) { | |||
this.props.onValueChange(''); |
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.
для управляемого инпута и для оповещения при неуправляемом
if (this.props.onValueChange) { | ||
this.props.onValueChange(''); | ||
} | ||
if (this.input) { |
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.
для неуправляемого инпута
@@ -513,6 +534,10 @@ export class Input extends React.Component<InputProps, InputState> { | |||
}; | |||
|
|||
private handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | |||
this.setState({ | |||
needsShowCleanCross: this.state.focused && !!this.input?.value, |
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.
По договоренности с дизайном крестик отображается только в том случае, когда поле непустое и в фокусе
@@ -582,7 +608,20 @@ export class Input extends React.Component<InputProps, InputState> { | |||
private resetFocus = () => this.setState({ focused: false }); | |||
|
|||
private handleBlur = (event: React.FocusEvent<HTMLInputElement>) => { | |||
this.resetFocus(); | |||
this.props.onBlur?.(event); | |||
if (this.props.showCleanCross && this.isBlurToCleanCrossIcon(event)) { |
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.
Определяем кликнули ли на крестик
if (this.props.showCleanCross && this.isBlurToCleanCrossIcon(event)) { | ||
event.preventDefault(); | ||
this.setState({ focused: false }); | ||
} else { |
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.
Старое поведение, только resetFocus (делающий setState({ focused: false }) ) заменен на одновременное изменение двух полей стейта: setState({ needsShowCleanCross: false, focused: false })
Проблема
Необходимо отрисовывать в инпуте крестик и очищать значение по клику на него.
Решение
Добавила пропы в Input и Combobox, отнаследовала проп в Autocomplete, написала скриншотные тесты и добавила примеры в документацию.
Ссылки
Задача
Гайд для Input с крестикой очистки
Тред в маттермосте с обсуждением дизайна
Чек-лист перед запросом ревью
Добавлены тесты на все изменения
✅ unit-тесты для логики
✅ скриншоты для верстки и кросс-браузерности
⬜ нерелевантно
Добавлена (обновлена) документация
✅ styleguidist для пропов и примеров использования компонентов
⬜ jsdoc для утилит и хелперов
⬜ комментарии для неочевидных мест в коде
⬜ прочие инструкции (
README.md
,contributing.md
и др.)⬜ нерелевантно
Изменения корректно типизированы
✅ без использования
any
(см. PR2856
)⬜ нерелевантно
Прочее
✅ все тесты и линтеры на CI проходят
✅ в коде нет лишних изменений
✅ заголовок PR кратко и доступно отражает суть изменений (он попадет в changelog)