fix(overlay-controller): do not scroll to invoker if it is visible (#2155)

* fix(overlay-controller): do not scroll to invoker if it is visible on screen

When closing an overlay, srollIntoView forced the invoker element to be placed in the middle of the screen. This fix prevents the scroll if the invoker is already visible, but still scrolls it into view if needed.

* chore: changeset
This commit is contained in:
Alberto López-Barranco 2023-12-11 12:44:01 +01:00 committed by GitHub
parent d997e5233e
commit c80bca7c83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
Fix scroll behavior when closing an overlay

View file

@ -933,7 +933,7 @@ export class OverlayController extends EventTarget {
if (this.elementToFocusAfterHide) {
this.elementToFocusAfterHide.focus();
this.elementToFocusAfterHide.scrollIntoView({ block: 'center' });
this.elementToFocusAfterHide.scrollIntoView({ block: 'nearest' });
} else {
/** @type {HTMLElement} */ (this.__activeElementRightBeforeHide).blur();
}