Skip to content

Dialog doesn't prevent the execution of clickshortcuts behind it #7799

Closed
vaadin/flow-components
#725

Description

@knoobie

When I create a view with a Shortcut Listener (Enter) on a button and the view opens a "Add XYZ Dialog" for some additional content - I would expect that I can create a second Shortcut Listener within the Dialog and the Dialog prevents that both Enter Shortcuts are executed.

Only the Shortcut Listener within the Dialog should be executed. Currently both Shortcuts are executed.

This creates weird side effects. Additionally any Dialog should be modal (WCAG) - that mean's that interacting with the content behind it SHOULD BE impossible.

Vaadin: 14.1.19
Browser: FF 74

How to test:

  1. Click Open Dialog
  2. Press Enter
  3. 2 Notification are displayed. It should only be one visible
@Route("shortcut")
public class ShortcutBug extends VerticalLayout {

  public ShortcutBug() {
    add(new Button("Open Dialog", e -> {
      Button myDialogButton = new Button("Hit Enter", event -> {
        Notification.show("Enter was called", 2000, Position.TOP_START).addThemeVariants(NotificationVariant.LUMO_SUCCESS);
      });
      myDialogButton.addClickShortcut(Key.ENTER);
      Dialog dialog = new Dialog(myDialogButton);
      dialog.open();
    }));

    Button myNonDialogButton = new Button("Should not be called by the other Other Enter Shortcut", e -> {
      Notification.show("ERROR: Enter was called", 5000, Position.TOP_START).addThemeVariants(NotificationVariant.LUMO_ERROR);
    });
    myNonDialogButton.addClickShortcut(Key.ENTER);

    add(new Hr(), myNonDialogButton);
  }
}

Activity

  1. denis-anisimov commented on Aug 5, 2020

    @denis-anisimov
    Contributor

    I don't think this is a bug.
    This works as designed even though I agree that the behavior could be better.
    Here is the explanation:

    • Flow allows to add the same shortcut to several components : that how it works (this can be an issue itself though).
    • So they are global.
    • Dialog is just a component for Flow the same like Div .
    • If I have two buttons : one is on the page, another is inside Div on the page then it's expected (see above) that both of them will be triggered .
    • As I said: for Flow there is no any difference between Div and Dialog .
    • So it works as expected.

    There can be a discussion whether we should trigger actions for every component with a shortcut (then cases when some components has assigned shortcuts but not attached should be considered).
    But this discussion doesn't help here anyway since in this case both buttons presents on the page (the only difference that the one is in the dialog).

    So : this is not a bug but works by design.

    On the other hand the issue makes sense: this is intuitively expected that there is an "input context" which is only active at the moment.
    The "input context" is the abstraction layer which is just absent in Flow completely .
    So we need to add a new abstraction unit into Flow which represents an "input context" , then Dialog should use this abstraction (e.g. implementing an interface) and only components which are active within the "input context" will be activated.
    That requires:

    • design
    • discussion
    • implementation in Flow
    • implementation in Dialog, Notification.

    It's a very long process and I would mark this issue as an enhancement.
    The workaround here is quite simple though: just deactivate shortcuts when a dialog is opened .

    At the moment the issue is technically in the Dialog component but it can't be implemented there (I believe) without changing design and API in Flow: components won't be able to change the Flow shortcuts logic.

  2. self-assigned this
    on Aug 12, 2020
  3. pleku commented on Aug 12, 2020

    @pleku

    The "input context" is the abstraction layer which is just absent in Flow completely .

    I agree with this, it is what we would need, but yes it would be an enhancement. The "fix" for this would be to document the current behavior in javadocs & documentation.

    This creates weird side effects. Additionally any Dialog should be modal (WCAG) - that mean's that interacting with the content behind it SHOULD BE impossible.

    The WCAG 2.x doesn't have anything about a "modal dialog" so I understand it the same way - there is no strict requirement for preventing the interaction with the content outside it. So it would be up to the application developer to ensure that the everything works as expected.

    Also with after discussing about vaadin-dialog as a component, while I do agree that everyone would expect the same behavior regardless if they use Flow or not, when working with client driven views one has to similarly handle the situation between the keyboard shortcuts on the background and with the dialog.

    But so now to handle this situation:

    • I'll add notes to javadocs & documentatio
    • Create an enhancement issue about adding a "input context" (name pending) abstraction layer to Flow which can be used in components (Notification, Dialog) to determine that the shortcut should be listened on there instead of UI when necessary.
  4. knoobie commented on Aug 12, 2020

    @knoobie
    ContributorAuthor

    Thanks for your additional feedback!

    The WCAG 2.x doesn't have anything about a "modal dialog"

    WCAG 2.x has no direct reference to dialog, but WAI-ARIA has:

    A dialog is a window overlaid on either the primary window or another dialog window. Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, and in some implementations, attempts to interact with the inert content cause the dialog to close.

    Source: https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal

    That is, users cannot interact with content outside an active dialog window.

    Especially this sentence.

  5. pleku commented on Aug 12, 2020

    @pleku

    Source: https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal

    I saw that via Google too but I discarded it as I though it was outdated information, because (I have to admit) I've misread your first comment here - I first read as "interacting should be possible" even though you clearly have written "interacting should be impossible". My bad.

    So based on that I agree - a true modal dialog should IMO out-of-the-box prevent background interaction such as keyboard shortcuts. I'll have to discuss again with the component developers / designers about this.

  6. daniel-pss-prosoft commented on Aug 29, 2020

    @daniel-pss-prosoft
    Contributor

    We also reported this bug, with warranty priority, and they gave the same answer: "won't fix".
    Eventually we implemented an in-house fix... with about 30 minutes of effort.

    Great premium support.

  7. 17 remaining items

  8. added a commit that references this issue on Mar 17, 2021
    4156f46
  9. added 6 commits that reference this issue on Mar 25, 2021
    b2b4c18
    4010fac
    abacf4b
    1897dbf
    59a2553
    77d5485
  10. added a commit that references this issue on Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions