Skip to content
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

Open
wants to merge 12 commits into
base: next
Choose a base branch
from

Conversation

SchwJ
Copy link
Member

@SchwJ SchwJ commented Feb 3, 2025

Проблема

Необходимо отрисовывать в инпуте крестик и очищать значение по клику на него.

Решение

Добавила пропы в Input и Combobox, отнаследовала проп в Autocomplete, написала скриншотные тесты и добавила примеры в документацию.

Ссылки

Задача
Гайд для Input с крестикой очистки
Тред в маттермосте с обсуждением дизайна

Чек-лист перед запросом ревью

  1. Добавлены тесты на все изменения
    ✅ unit-тесты для логики
    ✅ скриншоты для верстки и кросс-браузерности
    ⬜ нерелевантно

  2. Добавлена (обновлена) документация
    ✅ styleguidist для пропов и примеров использования компонентов
    ⬜ jsdoc для утилит и хелперов
    ⬜ комментарии для неочевидных мест в коде
    ⬜ прочие инструкции (README.md, contributing.md и др.)
    ⬜ нерелевантно

  3. Изменения корректно типизированы
    ✅ без использования any (см. PR 2856)
    ⬜ нерелевантно

  4. Прочее
    ✅ все тесты и линтеры на CI проходят
    ✅ в коде нет лишних изменений
    ✅ заголовок PR кратко и доступно отражает суть изменений (он попадет в changelog)

@SchwJ SchwJ force-pushed the add-clean-cross-in-input-and-combobox branch from 8432121 to 4cf6e49 Compare February 5, 2025 13:41
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пример в доку Autocomplete, так как он наследует свойство инпута showCleanCross

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тест, проверяющий что в Autocomplete работает свойство showCleanCross. Достаточно selenium теста, так как визуально всё аналогично инпуту

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creevey-тест, проверяющий Combobox:

  • появление крестика при вводе в инпут
  • очистка при клике на крестик
  • фокусировка по табу на крестике

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пример в доку ComboBox

Copy link
Member Author

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('');
Copy link
Member Author

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) {
Copy link
Member Author

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,
Copy link
Member Author

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)) {
Copy link
Member Author

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 {
Copy link
Member Author

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 })

@SchwJ SchwJ changed the title feat(Input): add clean cross prop feat(Input, Combobox): add showCleanCross prop Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant