-
Notifications
You must be signed in to change notification settings - Fork 943
fix: make ProxyMenu more accessible to screen readers #11312
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
Changes from 1 commit
4e08a23
1402691
f003144
5f58877
1348f55
b7d05de
c836057
4af5cec
9a05ee1
cdff5fb
0f3471c
fd643ae
8853c5a
3189031
0cfc510
8f38208
d534099
03b2ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
"idtoken", | ||
"Iflag", | ||
"incpatch", | ||
"initialisms", | ||
"ipnstate", | ||
"isatty", | ||
"Jobf", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { Abbr } from "./Abbr"; | ||
|
||
const meta: Meta<typeof Abbr> = { | ||
title: "components/Abbr", | ||
component: Abbr, | ||
decorators: [ | ||
(Story) => ( | ||
// Just here to make the abbreviated text part more obvious | ||
<p css={{ textDecoration: "dotted" }}> | ||
<Story /> | ||
</p> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Abbr>; | ||
|
||
export const Abbreviation: Story = { | ||
args: { | ||
initialism: false, | ||
children: "NASA", | ||
expandedText: "National Aeronautics and Space Administration", | ||
}, | ||
}; | ||
|
||
export const Initialism: Story = { | ||
args: { | ||
initialism: true, | ||
children: "CLI", | ||
expandedText: "Command-Line Interface", | ||
}, | ||
}; | ||
|
||
export const InlinedAbbreviation: Story = { | ||
args: { | ||
initialism: false, | ||
children: "ms", | ||
expandedText: "milliseconds", | ||
}, | ||
decorators: [ | ||
(Story) => ( | ||
<p> | ||
The physical pain of getting bonked on the head with a cartoon mallet | ||
lasts precisely 593 | ||
<Story />. The emotional turmoil and complete embarrassment lasts | ||
forever. | ||
</p> | ||
), | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,31 +4,38 @@ | |
* Features: | ||
* - Better type-safety (requiring you to include certain properties) | ||
* - All default styling is stripped away by default | ||
* - Better control over how screen readers read the text | ||
* - Better integration with screen readers, with more options for controlling | ||
* how they read out initialisms. | ||
*/ | ||
import { visuallyHidden } from "@mui/utils"; | ||
import { type FC } from "react"; | ||
|
||
type AbbrProps = { | ||
title: string; | ||
children: string; | ||
|
||
// Not calling this "title" to make it clear that it doesn't have the same | ||
// issues as the native title attribute as far as screen reader support | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that this rename lends a lot of clarity, tbh - I might just use "title" so there's less cognitive overhead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I can see that. As I've been doing research, it seems that |
||
expandedText: string; | ||
|
||
initialism?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: what do you think about the var names "tooltipText" (instead of "expandedText") and "hasAcronym" (instead of "initialism")? Expanded makes me think there is a dropdown or accordion and I had to google initialism. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I think I've done a bad job of adding enough context:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks for those distinctions; makes sense. I like the proposal you came up with, i.e. |
||
className?: string; | ||
}; | ||
|
||
export const Abbr: FC<AbbrProps> = ({ | ||
title, | ||
className, | ||
children, | ||
expandedText, | ||
className, | ||
initialism = false, | ||
}) => { | ||
return ( | ||
// Have to use test IDs instead of roles because traditional <abbr> elements | ||
// have weird edge cases and aren't that accessible, so abbreviated roles | ||
// usually aren't available in testing libraries | ||
<abbr | ||
title={title} | ||
// Title attributes usually aren't natively available to screen readers; | ||
// still have to inject text manually. Main value of titles here is | ||
// letting sighted users hover over the abbreviation to see expanded text | ||
title={expandedText} | ||
css={[{ textDecoration: "inherit" }, className]} | ||
data-testid="abbr" | ||
> | ||
|
@@ -37,6 +44,10 @@ export const Abbr: FC<AbbrProps> = ({ | |
// without it affecting the visual output for sighted users | ||
<> | ||
<span css={{ ...visuallyHidden }} data-testid="visually-hidden"> | ||
{/* | ||
* Once speakAs: "spell-out" has more browser support, that CSS | ||
* property can be swapped in and clean up this code a lot | ||
*/} | ||
{initializeText(children)} | ||
</span> | ||
|
||
|
@@ -45,7 +56,7 @@ export const Abbr: FC<AbbrProps> = ({ | |
</span> | ||
</> | ||
) : ( | ||
children | ||
<span aria-label={expandedText}>{children}</span> | ||
)} | ||
</abbr> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🌠