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

Toggle the nav drawer flyout menu when clicking/touching the same icon #1713

Closed
ryankeairns opened this issue Mar 11, 2019 · 3 comments
Closed

Comments

@ryankeairns
Copy link
Contributor

ryankeairns commented Mar 11, 2019

As a user, I expect the flyout menu to close if I touch/click the icon that originally opened it. For example, I click the 'Recently viewed' items icon, flyout menu opens; I click it again and it closes.

This was working on desktop sizes, but the mobile nav button in the header was a little unpredictable. There is some conflicting logic in here with regards to when the OutsideClickDetector is being enabled and disabled.

This issue could likely be addressed with #1712

@cchaos
Copy link
Contributor

cchaos commented Mar 12, 2019

The default behavior is back in, but needs tweaking for the mobile side.

@seeruk
Copy link
Contributor

seeruk commented May 2, 2020

I've sort of worked around this issue in a semi-hacky way right now. It might be less hacky if EuiOutsideDetector's API were extended to allow you to ignore other elements somehow.

What I've done is wrapped the EuiNavDrawer in my own EuiOutsideClickDetector. In it's onOutsideClick handler I've specifically made it ignore outside clicks from my mobile toggle button:

<EuiOutsideClickDetector isDisabled={!navDrawerOpen} onOutsideClick={(e) => {
  const ignoredTargets = e.composedPath().filter(target => (
    (target as Element).id === "navigationDrawerToggle"
  ))

  if (ignoredTargets.length === 0) {
    setNavDrawerOpen(false)
  }
}}>

Then as you can see partially there, I'm keeping track of the open state myself. If I click my toggle button it toggles that state. Of course, if I click my toggle button it'd normally be an outside click, but in this case the outside click is ignored, and the button's ability to close / open as expected is preserved:

<EuiHeaderSectionItemButton
  id="navigationDrawerToggle"
  aria-label="Open nav"
  onClick={() => {
    if (!navDrawerOpen) {
      navDrawerRef?.current?.toggleOpen()
    } else {
      navDrawerRef?.current?.closeBoth()
    }

    setNavDrawerOpen(!navDrawerOpen)
  }}
>

I have to specifically call closeBoth to avoid using the internal EuiOutsideClickDetector behaviour. But I suppose if you could pass in a list of elements to ignore outside clicks from into the nav drawer then all of this behaviour could be built-in.

No idea if there's a better way of doing this internally. I was trying to think of something for a while looking over the source code for the nav drawer, but nothing sprang to mind without modifying the outside click detector to do basically what I've done here. This at least is working around the issue for me for now until it can be put to rest properly.

@cchaos
Copy link
Contributor

cchaos commented Sep 18, 2020

This component is being deprecated in favor of EuiCollapsibleNav

@cchaos cchaos closed this as completed Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants