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(react-examples): Improved information for screen readers on Facepile examples #16479

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { Facepile, OverflowButtonType } from '@fluentui/react/lib/Facepile';
import { facepilePersonas } from '@fluentui/example-data';
import { Announced } from '@fluentui/react';

const overflowButtonProps = {
ariaLabel: 'More users',
Expand All @@ -9,26 +10,36 @@ const overflowButtonProps = {

export const FacepileAddFaceExample: React.FunctionComponent = () => {
const [numberOfFaces, setNumberOfFaces] = React.useState(0);
const [addFaceAnnounced, setAddFaceAnnounced] = React.useState<JSX.Element | undefined>();

const personas = React.useMemo(() => facepilePersonas.slice(0, numberOfFaces), [numberOfFaces]);

const addButtonProps = React.useMemo(
() => ({
ariaLabel: 'Add a new person',
onClick: (ev: React.MouseEvent<HTMLButtonElement>) => setNumberOfFaces(numberOfFaces + 1),
ariaLabel: 'Add a new person to the Facepile',
onClick: (ev: React.MouseEvent<HTMLButtonElement>) => {
const currentFaces = numberOfFaces + 1;
setNumberOfFaces(currentFaces);
setAddFaceAnnounced(
<Announced message={`New person added, currently ${currentFaces} in the Facepile.`} aria-live="assertive" />,
);
},
}),
[numberOfFaces],
);

return (
<Facepile
personas={personas}
maxDisplayablePersonas={5}
overflowButtonProps={overflowButtonProps}
overflowButtonType={OverflowButtonType.descriptive}
showAddButton
addButtonProps={addButtonProps}
ariaDescription="To move through the items use left and right arrow keys."
/>
<>
{addFaceAnnounced}
<Facepile
personas={personas}
maxDisplayablePersonas={5}
overflowButtonProps={overflowButtonProps}
overflowButtonType={OverflowButtonType.descriptive}
showAddButton
addButtonProps={addButtonProps}
ariaDescription="To move through the items use left and right arrow keys."
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ exports[`Component Examples renders Facepile.AddFace.Example.tsx correctly 1`] =
}
>
<button
aria-label="Add a new person"
aria-label="Add a new person to the Facepile"
className=
ms-Button
ms-Facepile-addButton
Expand Down