ng-clarity icon indicating copy to clipboard operation
ng-clarity copied to clipboard

Focus should return to previously active element after closing modal

Open steve-haar opened this issue 2 years ago • 1 comments

Describe the bug

After closing clarity modal, the previously active element is not focused.

How to reproduce

https://clarity-v3-light-theme-focus-element.stackblitz.io/

Steps to reproduce the behavior:

Use keyboard to navigate to button "foo". Hit "Enter" to open modal. Hit "Escape" to close the modal.

Expected behavior

The button "foo" should be focused.

Additional notes

It should be fixable in focus-trap.directive.ts since it is already doing so, but it sets previousActiveElement wrong. In AfterViewInit it is set to the element inside focusTrap, it will be fixed if it is set to document.activeElement before AfterViewInit (in onInit maybe?).

See https://github.com/vmware/clarity/issues/5668

steve-haar avatar Jul 07 '22 15:07 steve-haar

+1.. We have a scroll at a body level and focus does not return back to the element that trigerred the modal since body scroll is removed when the modal is open. Extending no-scrolling to set overflow:auto doesnt fix the issue .

siddharth1903 avatar Jul 28 '22 05:07 siddharth1903

This was fixed in https://github.com/vmware-clarity/ng-clarity/pull/455.

kevinbuhmann avatar Feb 03 '23 00:02 kevinbuhmann

Hi there 👋, this is an automated message. To help Clarity keep track of discussions, we automatically lock closed issues after 14 days. Please look for another open issue or open a new issue with updated details and reference this one as necessary.

github-actions[bot] avatar Feb 17 '23 01:02 github-actions[bot]