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

refactor: make overlay use FocusTrapController #3159

Merged
merged 6 commits into from
Dec 9, 2021

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Dec 7, 2021

Description

The PR drops the focus trap logic from the overlay component and makes it use FocusTrapController instead.

Depends on #3140

Fixes #3134

Type of change

  • Internal

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Comment on lines -108 to -119
it('should not focus next focusable element inside the content when Tab is prevented', async () => {
overlay.addEventListener('keydown', (event) => {
if (event.key === 'Tab') {
event.preventDefault();
}
});
overlay.opened = true;
await oneEvent(overlay, 'vaadin-overlay-open');
tabKeyDown(focusableElements[overlay._focusedIndex()]);
expect(overlay._focusedIndex()).to.equal(0);
});

Copy link
Contributor Author

@vursen vursen Dec 7, 2021

Choose a reason for hiding this comment

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

It was previously possible to prevent the focus trap logic on keydown by calling preventDefault() on the event (see the check). It was introduced as a workaround for vaadin/vaadin-rich-text-editor#125.

However, it appears that over time the mentioned issue was fixed directly in the rich text editor library as I wasn't able to reproduce it even without the workaround. Considering this, I decided to drop the workaround at all.

@vursen vursen force-pushed the refactor/make-overlay-use-focus-trap-controller branch from 258abb1 to 56a9ceb Compare December 7, 2021 14:49
@vursen vursen force-pushed the refactor/make-overlay-use-focus-trap-controller branch from 85d3dc6 to 50f124e Compare December 7, 2021 17:16
Copy link
Member

@tomivirkki tomivirkki left a comment

Choose a reason for hiding this comment

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

Other than the one untested condition, lgtm

packages/component-base/src/focus-trap-controller.js Outdated Show resolved Hide resolved
@vursen vursen force-pushed the refactor/make-overlay-use-focus-trap-controller branch from 50f124e to f261503 Compare December 8, 2021 11:04
@vursen vursen force-pushed the refactor/make-overlay-use-focus-trap-controller branch from f261503 to 51b562d Compare December 8, 2021 13:57
@sonarcloud
Copy link

sonarcloud bot commented Dec 8, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan merged commit e58a466 into master Dec 9, 2021
@web-padawan web-padawan deleted the refactor/make-overlay-use-focus-trap-controller branch December 9, 2021 08:00
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 23.0.0.alpha1 and is also targeting the upcoming stable 23.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[overlay] Extract the focus trap logic from the overlay to a controller
4 participants