-
Notifications
You must be signed in to change notification settings - Fork 963
fix: correct markup for Abbr component #19317
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 all commits
9a94037
c8f38e0
0a076c7
c69b449
2169a7b
8023039
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import type { FC, HTMLAttributes } from "react"; | ||
import { cn } from "utils/cn"; | ||
|
||
export type Pronunciation = "shorthand" | "acronym" | "initialism"; | ||
type Pronunciation = "shorthand" | "acronym" | "initialism"; | ||
|
||
type AbbrProps = HTMLAttributes<HTMLElement> & { | ||
children: string; | ||
title: string; | ||
pronunciation?: Pronunciation; | ||
className?: string; | ||
}; | ||
|
||
/** | ||
|
@@ -22,23 +23,26 @@ export const Abbr: FC<AbbrProps> = ({ | |
children, | ||
title, | ||
pronunciation = "shorthand", | ||
className, | ||
...delegatedProps | ||
}) => { | ||
return ( | ||
<abbr | ||
// Title attributes usually aren't natively available to screen readers; | ||
// always have to supplement with aria-label | ||
// Adding title to make things a little easier for sighted users, | ||
// but titles aren't always exposed via screen readers. Still have | ||
// to inject the actual text content inside the abbr itself | ||
title={title} | ||
aria-label={getAccessibleLabel(children, title, pronunciation)} | ||
className={cn( | ||
"decoration-inherit", | ||
children === children.toUpperCase() | ||
? "tracking-wide" | ||
: "tracking-normal", | ||
"no-underline tracking-normal", | ||
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 wish we understood where the underline is coming from. these kinds of conflicts are so annoying. can we at least add a TODO to clean this up one day? 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, the funny thing is, I actually don't think we should do anything – once MUI is out, we should be much closer to "normal" CSS, and this behavior would be 100% expected |
||
children === children.toUpperCase() && "tracking-wide", | ||
className, | ||
)} | ||
{...delegatedProps} | ||
> | ||
<span aria-hidden>{children}</span> | ||
<span className="sr-only"> | ||
{getAccessibleLabel(children, title, pronunciation)} | ||
</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.
Got rid of the test helper because it felt like we were binding all our tests to a shallow abstraction