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

Added support for aria labels in IconButtons & aria roles in menus #3370

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 6 additions & 3 deletions client/common/IconButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ButtonWrapper = styled(Button)`
`;

const IconButton = (props) => {
const { icon, ...otherProps } = props;
const { icon, ariaLabel, ...otherProps } = props;
const Icon = icon;

return (
Expand All @@ -22,17 +22,20 @@ const IconButton = (props) => {
iconOnly
display={Button.displays.inline}
focusable="false"
aria-label={ariaLabel}
{...otherProps}
/>
);
};

IconButton.propTypes = {
icon: PropTypes.func
icon: PropTypes.func,
ariaLabel: PropTypes.string
};

IconButton.defaultProps = {
icon: null
icon: null,
ariaLabel: ''
};

export default IconButton;
51 changes: 42 additions & 9 deletions client/modules/IDE/components/Header/MobileNav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const MobileNav = () => {
<Options>
<div>
<Link to={editorLink}>
<IconButton icon={CrossIcon} />
<IconButton ariaLabel="Close button" icon={CrossIcon} />
</Link>
</div>
</Options>
Expand All @@ -262,7 +262,7 @@ const MobileNav = () => {
) : (
<div>
<Link to="/login">
<IconButton icon={AccountIcon} />
<IconButton ariaLabel="Login button" icon={AccountIcon} />
</Link>
</div>
)}
Expand All @@ -271,7 +271,7 @@ const MobileNav = () => {
) : (
<div>
<Link to={editorLink}>
<IconButton icon={EditorIcon} />
<IconButton ariaLabel="Editor button" icon={EditorIcon} />
</Link>
</div>
)}
Expand All @@ -291,8 +291,19 @@ const StuffMenu = () => {

return (
<div>
<IconButton icon={AddIcon} {...handlers} />
<ul className={isOpen ? 'opened' : ''}>
<IconButton
icon={AddIcon}
ariaLabel="Stuff Menu"
aria-controls="stuff-menu"
id="stuff-menu-button"
{...handlers}
/>
<ul
className={isOpen ? 'opened' : ''}
id="stuff-menu"
role="menu"
aria-labelledby="stuff-menu-button"
>
<ParentMenuContext.Provider value="stuff">
<NavMenuItem onClick={() => newSketch()}>
{t('DashboardView.NewSketch')}
Expand Down Expand Up @@ -322,8 +333,19 @@ const AccountMenu = () => {

return (
<div>
<IconButton icon={AccountIcon} {...handlers} />
<ul className={isOpen ? 'opened' : ''}>
<IconButton
icon={AccountIcon}
ariaLabel="Account Menu"
aria-controls="more-menu"
id="account-menu-button"
{...handlers}
/>
<ul
className={isOpen ? 'opened' : ''}
id="account-menu"
role="menu"
aria-labelledby="account-menu-button"
>
<ParentMenuContext.Provider value="account">
<li className="user">{user.username}</li>
<NavMenuItem href={`/${user.username}/sketches`}>
Expand Down Expand Up @@ -393,8 +415,19 @@ const MoreMenu = () => {
</LanguageSelect>
</Overlay>
)}
<IconButton icon={MoreIcon} {...handlers} />
<ul className={isOpen ? 'opened' : ''}>
<IconButton
icon={MoreIcon}
ariaLabel="More Menu"
aria-controls="more-menu"
id="more-menu-button"
{...handlers}
/>
<ul
id="more-menu"
className={isOpen ? 'opened' : ''}
role="menu"
aria-labelledby="more-menu-button"
>
<ParentMenuContext.Provider value="more">
<b>{t('Nav.File.Title')}</b>
<NavMenuItem onClick={newSketch}>{t('Nav.File.New')}</NavMenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ exports[`Nav renders dashboard version for mobile 1`] = `
href="/login"
>
<button
aria-label="Login button"
class="c4 c5"
display="inline"
focusable="false"
Expand All @@ -332,9 +333,12 @@ exports[`Nav renders dashboard version for mobile 1`] = `
</div>
<div>
<button
aria-controls="more-menu"
aria-label="More Menu"
class="c4 c5"
display="inline"
focusable="false"
id="more-menu-button"
kind="primary"
type="button"
>
Expand All @@ -345,7 +349,10 @@ exports[`Nav renders dashboard version for mobile 1`] = `
/>
</button>
<ul
aria-labelledby="more-menu-button"
class=""
id="more-menu"
role="menu"
>
<b>
File
Expand Down Expand Up @@ -1017,6 +1024,7 @@ exports[`Nav renders editor version for mobile 1`] = `
href="/login"
>
<button
aria-label="Login button"
class="c4 c5"
display="inline"
focusable="false"
Expand All @@ -1033,9 +1041,12 @@ exports[`Nav renders editor version for mobile 1`] = `
</div>
<div>
<button
aria-controls="more-menu"
aria-label="More Menu"
class="c4 c5"
display="inline"
focusable="false"
id="more-menu-button"
kind="primary"
type="button"
>
Expand All @@ -1046,7 +1057,10 @@ exports[`Nav renders editor version for mobile 1`] = `
/>
</button>
<ul
aria-labelledby="more-menu-button"
class=""
id="more-menu"
role="menu"
>
<b>
File
Expand Down