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(a11y): set aria-expanded for mgt-login when open/closed #2405

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
font-family: var(--body-font);
padding: 24px 12px;
}
.right-align {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
</style>
</head>

Expand All @@ -44,7 +49,9 @@
<h1>Developer test page</h1>
<main>
<h2>mgt-login</h2>
<mgt-login login-view="compact"></mgt-login>
<div class="right-align">
<mgt-login login-view="compact"></mgt-login>
</div>
<mgt-login></mgt-login>
<h2>mgt-person me query two lines card on click with presence</h2>
<!-- <mgt-person person-query="me" view="twoLines" person-card="click" show-presence></mgt-person> -->
Expand Down
14 changes: 8 additions & 6 deletions packages/mgt-components/src/components/mgt-login/mgt-login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { CSSResult, html, TemplateResult } from 'lit';
import { property, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import {
Providers,
ProviderState,
Expand Down Expand Up @@ -166,7 +167,7 @@ export class MgtLogin extends MgtTemplatedComponent {
* @private
* @type {boolean}
*/
@property({ attribute: false }) private _isFlyoutOpen: boolean;
@state() private _isFlyoutOpen: boolean;

/**
* The image blob string
Expand Down Expand Up @@ -319,13 +320,14 @@ export class MgtLogin extends MgtTemplatedComponent {
small: this.loginView === 'avatar'
});
const appearance = isSignedIn ? 'stealth' : 'neutral';
const buttonContentTemplate =
isSignedIn && this.userDetails
? this.renderSignedInButtonContent(this.userDetails, this._image)
: this.renderSignedOutButtonContent();

const showSignedInState = isSignedIn && this.userDetails;
const buttonContentTemplate = showSignedInState
? this.renderSignedInButtonContent(this.userDetails, this._image)
: this.renderSignedOutButtonContent();
const expandedState: boolean | undefined = showSignedInState ? this._isFlyoutOpen : undefined;
return html`
<fluent-button
aria-expanded="${ifDefined(expandedState)}"
appearance=${appearance}
aria-label=${ariaLabel}
?disabled=${this.isLoadingState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,17 @@ export class MgtFlyout extends MgtBaseComponent {
`;
}

private updateFlyout() {
/**
* Updates the position of the flyout.
* Makes a second recursive call to ensure the flyout is positioned correctly.
* This is needed as the width of the flyout is not settled until afer the first render.
*
* @private
* @param {boolean} [firstPass=true]
* @return {*}
* @memberof MgtFlyout
*/
private updateFlyout(firstPass = true) {
if (!this.isOpen) {
return;
}
Expand Down Expand Up @@ -414,6 +424,9 @@ export class MgtFlyout extends MgtBaseComponent {
flyout.style.maxHeight = null;
flyout.style.setProperty('--mgt-flyout-set-height', 'unset');
}
if (firstPass) {
window.requestAnimationFrame(() => this.updateFlyout(false));
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions stories/components/login/login.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ export const ShowPresenceLogin = () => html`
<mgt-login show-presence login-view="full"></mgt-login>
`;

export const RightAligned = () => html`
musale marked this conversation as resolved.
Show resolved Hide resolved
<div class="right">
<mgt-login login-view="compact"></mgt-login>
musale marked this conversation as resolved.
Show resolved Hide resolved
</div>
<style>
.right {
display: flex;
flex-direction: row;
justify-content: flex-end;
}
</style>
`;

export const Templates = () => html`
<mgt-login>
<template data-type="signed-out-button-content">
Expand Down
Loading