vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
445 stars 83 forks source link

[overlay] Problem with focus / aria-hidden with multiple modeless overlays #7721

Open web-padawan opened 2 weeks ago

web-padawan commented 2 weeks ago

Description

When there are multiple modeless dialog overlays open at the same time, the focusTrap enabled by the one that was opened later always steals focus, event if the other dialog is now the topmost after bringToFront() on its overlay.

Expected outcome

There are two possible options here:

  1. Update OverlayFocusMixin logic in the overlay to respect the overlay stack so that only topmost overlay traps focus (this would require changes to how FocusTrapController and AriaModalController are handled)
  2. Do not apply focusTrap at all when the modeless property is set (this could be limited to vaadin-dialog).

Minimal reproducible example

<vaadin-dialog modeless id="dialog1" draggable></vaadin-dialog>
<vaadin-dialog modeless id="dialog2" draggable></vaadin-dialog>

<vaadin-button id="button1">Open dialog 1</vaadin-button>
<vaadin-button id="button2">Open dialog 2</vaadin-button>

<script type="module">
  const dialog1 = document.querySelector('#dialog1');
  const dialog2 = document.querySelector('#dialog2');

  dialog1.renderer = (root) => {
    if (root.firstChild) {
      return;
    }

    root.innerHTML = `
      <input placeholder="Input 1" />
      <input placeholder="Input 2" />
    `;
  };

  dialog2.renderer = (root) => {
    if (root.firstChild) {
      return;
    }

    root.innerHTML = `
      <input placeholder="Input 3" />
      <input placeholder="Input 4" />
    `;
  };

  document.querySelector('#button1').addEventListener('click', () => {
    dialog1.opened = true;
  });

  document.querySelector('#button2').addEventListener('click', () => {
    dialog2.opened = true;
  });
</script>

Steps to reproduce

  1. Open first dialog
  2. Open second dialog
  3. Drag the second dialog to make the first dialog visible
  4. Focus the input in the first dialog overlay
  5. Press Tab

Environment

Vaadin version(s): 24.x and earlier

Browsers

Issue is not browser related

yuriy-fix commented 1 week ago

Notes from the discussion: