-
Notifications
You must be signed in to change notification settings - Fork 198
feat(FocusTrap): refactor using focus guards #9330
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
Open
EldarMuhamethanov
wants to merge
11
commits into
master
Choose a base branch
from
e.muhamethanov/5093/refactor-focus-trap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(FocusTrap): refactor using focus guards #9330
EldarMuhamethanov
wants to merge
11
commits into
master
from
e.muhamethanov/5093/refactor-focus-trap
+1,831
−755
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Conflicts: # packages/vkui/src/components/ActionSheet/ActionSheetDropdownSheet.tsx # packages/vkui/src/components/FocusTrap/FocusTrap.test.tsx
Contributor
e2e tests |
Contributor
Contributor
👀 Docs deployed
📦 Package ✅yarn add @vkontakte/vkui@https://development.s3.prodcloud.vk.team/pull/9330/cb5dd295ca993913bbf511e89ae4b009a3226b08/pkg/@vkontakte/vkui/_pkg.tgzCommit cb5dd29 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #9330 +/- ##
==========================================
- Coverage 94.96% 94.92% -0.04%
==========================================
Files 436 440 +4
Lines 11752 11807 +55
Branches 4324 4339 +15
==========================================
+ Hits 11160 11208 +48
- Misses 592 599 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
size-limit report 📦
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Описание
Рефакторинг хука
useFocusTrapи компонентаFocusTrapс целью улучшения архитектуры, упрощения логики и повышения гибкости использования.Основные изменения:
useFocusTrapна модульную структуру с выделением отдельных хуковuseAutoFocusиuseRestoreFocusbeforeGuard,afterGuard) вместо их внутреннего рендерингаFocusTrap- теперь компонент отвечает только за захват фокуса и Tab-навигациюEscapeвынесена в компоненты черезuseGlobalEscKeyDownдля большей гибкостиUseFocusTrapPropsв публичных API компонентов, добавление прямых типов для лучшей читаемостиFocusTrapилиuseFocusTrapдля работы с новым APIИзменения
Архитектурные изменения
Рефакторинг
useFocusTrap:useFocusTrap.tsx- основной хук, координирующий работуuseAutoFocus.ts- логика автофокуса при монтированииuseRestoreFocus.ts- логика восстановления фокуса при размонтировании{beforeGuard, afterGuard}вместоvoidonFocusвместо глобальных обработчиковkeydownдля TabИзменение компонента
FocusTrap:FocusTrapInternal(с полным API) иFocusTrap(публичный API без внутренних опций)data-focus-guardдля идентификации guard-элементовonCloseиcaptureEscapeKeyboardEvent- теперьFocusTrapотвечает только за захват фокуса и Tab-навигациюОбновление типизации:
UseFocusTrapPropsв публичных типах компонентов (ModalCard,ModalPage,Alert,ActionSheet,Popover,OnboardingTooltip,DateInput,DateRangeInput)restoreFocus,autoFocus,disableFocusTrapв интерфейсы компонентовОбновление компонентов:
DateInput,DateRangeInput: переход наFocusTrapInternalдля доступа к внутренним опциямAlert,ActionSheet,OnboardingTooltip,DateInput,DateRangeInputтеперь используютuseGlobalEscKeyDownдля обработки нажатия Escapecapture: falseдляDateInputиDateRangeInput)Другие изменения:
FocusTrapиFocusTrapPropsдобавлен в публичный API (src/index.ts)Технические детали
arraysEqualsдля сравнения массивов фокусируемых элементовFocusTrapтеперь отвечает только за управление фокусом (захват, Tab-навигация, автофокус, восстановление фокуса), а обработка Escape вынесена в компонентыRelease notes