Skip to content

Conversation

@far-fetched
Copy link
Contributor

@far-fetched far-fetched commented Oct 10, 2021

What is wrong and why

  1. Adding transition component to menu causes a situation when variable isOpen is false in <Menu> but <Menu.Items> is still visible - e.g. is fading out.

  2. This getter

get itemsGuid() {
   return this.isOpen ? `${this.guid}-items` : undefined;
}

will be updated to undefined which will be passed down to <Menu.Items>

  1. Menu Items uses headlessui-focus-trap with parameter itemsGuid

Captura de pantalla 2021-10-10 a las 12 10 37

Thus, if we change itemsGuid from e.g. ember-123 to undefined modifier will be recalculated (teardown old, and mount new)

  1. When a new modifier is mounted, fallbackFocus is #undefined. focus-trap after activation is focusing first tabbable element. As we set explicitly each item element with tabindex=-1, focus-trap doesn't see any tabbable nodes and tries to focus fallback element which is #undefined.

  2. Finally, focus-trap will throw error, which you can see here (try to close menu). Also failing test with first build.

Fix

I changed getter itemsGuid to always return not undefined value (modifier will be not rerun when close menu with transition). It breaks a lot of tests as Menu.Button component uses it to set aria-controls - when is closed this aria should be undefined. So eventually I added if condition based on @isOpen which already is provided to Menu.Button

@far-fetched far-fetched marked this pull request as ready for review October 11, 2021 09:47
@GavinJoyce GavinJoyce added the bug Something isn't working label Oct 11, 2021
@GavinJoyce GavinJoyce merged commit 5f87506 into GavinJoyce:master Oct 11, 2021
@GavinJoyce
Copy link
Owner

GavinJoyce commented Oct 11, 2021

Very nice, thanks @far-fetched!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants