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(DateInput,DatePicker): add screenreader support to custom input #3602

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

Conversation

sashachabin
Copy link
Member

@sashachabin sashachabin commented Feb 14, 2025

Проблема

  1. Скринридер не читает значения<DateInput>
  2. Нет поддержки aria-атрибутов в кастомном input — нет возможности добавлять инструкции для пользователей со скринридером. Например, они нужны для подписей в DateRangePicker.

Проблемы связаны с тем, что кастомный ипнут состоит из <span tabindex="0" onKeyDown> + <input type="hidden">.

Решение

Изменения затрагивают компонент <DateInput> и тесты <Combobox>, которые используют <InputLikeText>.

1. Доступность <DateInput> и <InputLikeText>

  • Добавил к span атрибут role="textbox"
  • Добавил поддержку ARIA-атрибутов
    • aria-label
    • aria-labelledby
    • aria-describedby (ранее был на input type="hidden" и не работал)
    • aria-disabled (ранее disabled был только на input type="hidden")

2. Починка тестов <ComboBox>

<ComboBox> использует <InputLikeText> только для внешнего вида и получения фокуса.

После получения фокуса поле <InputLikeText> заменяется на обычный <Input> — проверки на это появились в тестах на focus/blur в PR #3133.

Ранее через queryByRole('textbox').not.toBeInTheDocument() мы проверяли отсутствие <Input>, но теперь <InputLikeText> тоже имеет правильную роль textbox.

  • Исправил конфликты через указание более точных data-tid:
    getByRole('textbox')queryByTestId(InputDataTids.root)

Ссылки

Демо

Исправленный ввод в скринридере

Было Стало
— Нельзя было прокинуть название поля, скринридер говорил __.__.____
— Не работал ввод вместе со скринридером — в NVDA цифры на клавиатуре "1", "2" тригерят навигацию к заголовкам 1 и 2 уровня

— Произносится лейбл (например, "дата") и произносится edit
— Работает ввод и произносятся цифры
— Значения не читаются целиком из-за маски (стало лучше, но не идеально — обходится через aria-атрибуты)



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

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

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

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

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

@sashachabin sashachabin force-pushed the input-like-text-screenreader branch 2 times, most recently from b123aa0 to 8f5692b Compare February 18, 2025 09:30
@sashachabin sashachabin changed the title feature(): add screenreader support to DateInput feat(DateInput): add screenreader support to <InputLikeText> Feb 18, 2025
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch 2 times, most recently from bdd1827 to 47d907b Compare February 18, 2025 16:30
@sashachabin sashachabin changed the title feat(DateInput): add screenreader support to <InputLikeText> feat(DateInput,ComboBox): add screenreader support Feb 18, 2025
@sashachabin sashachabin changed the title feat(DateInput,ComboBox): add screenreader support feat(DateInput,DatePicker,ComboBox): add screenreader support to custom input Feb 18, 2025
@sashachabin sashachabin marked this pull request as ready for review February 18, 2025 17:22
@sashachabin sashachabin requested a review from lossir February 18, 2025 17:25
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch from 47d907b to 8d84b9c Compare February 18, 2025 20:16
@sashachabin sashachabin changed the title feat(DateInput,DatePicker,ComboBox): add screenreader support to custom input feat(DateInput,DatePicker): add screenreader support to custom input Feb 18, 2025
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch from 645ffe1 to ce11adb Compare February 18, 2025 21:28
@sashachabin sashachabin removed the request for review from lossir February 18, 2025 21:28
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch from 5d97eb7 to 3d4915d Compare February 19, 2025 21:08
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch from 3d4915d to 4674f77 Compare February 19, 2025 21:52
@sashachabin sashachabin force-pushed the input-like-text-screenreader branch from 4674f77 to d5f5c51 Compare February 19, 2025 21:53
@@ -214,21 +216,20 @@ export class InputLikeText extends React.Component<InputLikeTextProps, InputLike
{...rest}
className={className}
style={{ width, textAlign: align }}
tabIndex={disabled ? undefined : 0}
tabIndex={disabled ? -1 : 0}
Copy link
Member Author

@sashachabin sashachabin Feb 19, 2025

Choose a reason for hiding this comment

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

При disabled указал -1 вместо undefined из-за ошибки ESLint: jsx-a11y/interactive-supports-focus. Правило требует обязательно задавать tabIndex вместе с role="textbox"

@sashachabin sashachabin requested a review from zhzz February 19, 2025 22:21
@sashachabin sashachabin added the a11y Issues related to a11y of components label Feb 19, 2025
@sashachabin
Copy link
Member Author

Ссылки на тестирование

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y Issues related to a11y of components
Development

Successfully merging this pull request may close these issues.

2 participants