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

fix: dismiss login flyout when moving out of the popup #2637

Merged
merged 13 commits into from
Aug 17, 2023
39 changes: 34 additions & 5 deletions packages/mgt-components/src/components/mgt-login/mgt-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,43 @@ export class MgtLogin extends MgtTemplatedComponent {
light-dismiss
@opened=${this.flyoutOpened}
@closed=${this.flyoutClosed}>
<div slot="flyout">
<fluent-card class="flyout-card">
${this.renderFlyoutContent()}
</fluent-card>
</div>
<fluent-card
slot="flyout"
tabindex="0"
class="flyout-card"
@keydown=${this.onUserKeyDown}
>
${this.renderFlyoutContent()}
</fluent-card>
</mgt-flyout>`;
}

/**
* Tracks tabbing through the flyout (keydown)
*/
private readonly onUserKeyDown = (): void => {
if (!this.flyout.isOpen) {
return;
}

const el = this.renderRoot.querySelector('.popup-content');
const focusableEls = el.querySelectorAll('li, fluent-button');
const lastFocusableEl = focusableEls[focusableEls.length - 1];

lastFocusableEl.addEventListener('keydown', this.closeFlyout);
};

/**
* Closes the login popup flyout on tab (keydown)
*
* @param event - event tracked on user input (keydown)
*/
private readonly closeFlyout = (e: KeyboardEvent): void => {
if (e.key === 'Tab') {
this.hideFlyout();
}
gavinbarron marked this conversation as resolved.
Show resolved Hide resolved
Mnickii marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Render the flyout menu content.
*
Expand Down
Loading