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

Closing modal causes abrupt scrolling to last focused element #3227

Open
shareefhadid opened this issue Feb 2, 2025 · 3 comments
Open

Closing modal causes abrupt scrolling to last focused element #3227

shareefhadid opened this issue Feb 2, 2025 · 3 comments
Labels
bug Something isn't working reka-ui v3 #1289

Comments

@shareefhadid
Copy link

shareefhadid commented Feb 2, 2025

Environment



Is this bug related to Nuxt or Vue?

Nuxt

Version

v3.0.0-alpha.12

Reproduction

Sorry for not providing a reproduction, but here it is on your doc website:

test-2.mov

In the screen capture you can see:

  1. I click a button, grant it focus
  2. scroll up
  3. open the search modal with command palette using meta + k
  4. close the modal
  5. I am immediately scrolled to the last focused element

Description

As shown in the screen cap in the reproduction section, closing the modal returns focus to the last focused element causing you to scroll to its position.

I realize this is an accessibility feature, but being abruptly scrolled down is confusing and jarring for users.

Additional context

No response

Logs

@shareefhadid shareefhadid added bug Something isn't working triage v3 #1289 labels Feb 2, 2025
@benjamincanac benjamincanac added the reka-ui label Feb 3, 2025 — with Volta.net
Copy link
Member

@zernonia Would you know how to disable this behavior?

@benjamincanac benjamincanac removed the triage label Feb 3, 2025 — with Volta.net
@shareefhadid
Copy link
Author

FYI, this is what I ended up doing:

import { GMSearchPalette } from "#components";

const modal = useModal();

const openSearch = () => {
  document.activeElement instanceof HTMLElement &&
    document.activeElement.blur();
  modal.open(GMSearchPalette);
};

defineShortcuts({
  meta_k: () => {
    openSearch();
  },
});

@zernonia
Copy link
Contributor

zernonia commented Feb 11, 2025

@zernonia Would you know how to disable this behavior?

This behavior can be prevented by preventing the closeAutoFocus

<DialogContent @closeAutoFocus="(event) => {
  if(openWithShortcut) {
    event.preventDefault() // prevent auto focus when modal close
  }
}">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reka-ui v3 #1289
Projects
None yet
Development

No branches or pull requests

3 participants