Skip to content

AppLayout drawer-toggle not working in RTL mode on Chrome and FF #4682

Closed

Description

@rolfsmeds

Description

Setting UI.getCurrent.setDirection(Direction.RIGHT_TO_LEFT) in Flow seems to break the functionality of vaadin-drawer-toggle in Chrome and Firefox: the drawer-opened attribute is not toggled, and the drawer stays put. This also makes it impossible to open the drawer in small-viewport mode.

It works correctly in Safari, however.

Have not tested outside of a Flow app.

Expected outcome

Clicking the toggle should toggle the drawer.

Minimal reproducible example

public class MainLayout extends AppLayout {
    public MainLayout() {
        addToDrawer(new Span("Foo"));
        addToNavbar(new DrawerToggle());
        UI.getCurrent().setDirection(Direction.RIGHT_TO_LEFT);
    }

Steps to reproduce

  1. Use e.g. the default Start template
  2. Add the above code to the main layout class
  3. Run the app in Chrome or Firefox, and try clicking the toggle

Environment

Vaadin version(s): 23.2.2
OS: macOS

Browsers

Chrome, Firefox

Activity

  1. vursen commented on Oct 6, 2022

    @vursen
    Contributor

    Appears to work with plain web components by the way:

    Screen.Recording.2022-10-06.at.13.20.17.mov

    My guess is that the issue is somehow related to the fact that RTL mode is enabled in the view constructor.

  2. JariHanah commented on Oct 8, 2022

    @JariHanah

    My original code puts the setDirection inside the beforeEnter call, facing the same problem, so I dont think the problem is puting this inside the constructor.

  3. sissbruecker commented on Oct 10, 2022

    @sissbruecker
    Member

    Reproduction with web components only:

    <html lang="en" dir="rtl">
    <head>...</head>
    
    <body>
      <vaadin-app-layout>
        <vaadin-drawer-toggle slot="navbar"></vaadin-drawer-toggle>
        <span slot="drawer">Drawer</span>
      </vaadin-app-layout>
      <div id="container" style="height: 100%"></div>
      <script>
        // Move layout to different parent after initialization
        setTimeout(() => {
          const layout = document.querySelector("vaadin-app-layout");
          const container = document.getElementById("container");
          container.appendChild(layout);
        }, 1000);
      </script>
    </body>
    </html>

    In Flow applications the layout is always moved to a new parent during initialization by the Vaadin router. It seems that when moving the layout to a new parent, during the AppLayout.disconnectedCallback some logic in the DirMixin triggers AppLayout.connectedCallback before the disconnect callback is fully completed. That in turn causes the layout to loose the listener for the drawer toggle event.

    The relevant line in DirMixin is this one:

    this.removeAttribute('dir');

    As mentioned this only applies in Chome and FF, but not in Safari. So it seems that Chrome and FF for some reason immediately run the pending reconnect if you change an attribute, even if the disconnect has not finished yet.

  4. self-assigned this
    on Oct 10, 2022
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