Skip to content

Commit c794f27

Browse files
committed
MSFT-231 Fix prize and bonus being read out incorrectly by screen reader (NVDA).
1 parent 8110e92 commit c794f27

File tree

2 files changed

+20
-10
lines changed
  • src/shared/components/challenge-listing/ChallengeCard/Prize/Tip

2 files changed

+20
-10
lines changed

src/shared/components/challenge-listing/ChallengeCard/Prize/Tip/Bonus/index.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ export default function Bonus({
1414
prizeUnitSymbol,
1515
}) {
1616
return (
17-
<div styleName="bonus">
18-
<span styleName="name">
19-
{name}
17+
<div styleName="bonus" aria-label={`${name} bonus is ${prizeUnitSymbol}${prize.toLocaleString()}`}>
18+
<span aria-hidden="true">
19+
<span styleName="name">
20+
{name}
21+
</span>
22+
{prizeUnitSymbol}
23+
{prize.toLocaleString()}
2024
</span>
21-
{prizeUnitSymbol}
22-
{prize.toLocaleString()}
2325
</div>
2426
);
2527
}

src/shared/components/challenge-listing/ChallengeCard/Prize/Tip/Prize/index.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import PT from 'prop-types';
22
import React from 'react';
33
import './style.scss';
44

5+
const suffixes = ['th', 'st', 'nd', 'rd'];
6+
const getOrdinalSuffix = (n) => {
7+
const v = n % 100;
8+
return suffixes[(v - 20) % 10] || suffixes[v] || suffixes[0];
9+
};
10+
511
/**
612
* A single prise component.
713
* It renders a round-shaped medal with the specified place number inside it,
@@ -15,12 +21,14 @@ export default function Prize({
1521
let medalStyleName = 'medal';
1622
if (place <= 3) medalStyleName += ` place-${place}`;
1723
return (
18-
<div styleName="prize">
19-
<span styleName={medalStyleName}>
20-
{place}
24+
<div styleName="prize" aria-label={`${place}${getOrdinalSuffix(place)} prize is ${prizeUnitSymbol}${prize.toLocaleString()}`}>
25+
<span aria-hidden="true">
26+
<span styleName={medalStyleName}>
27+
{place}
28+
</span>
29+
{prizeUnitSymbol}
30+
{prize.toLocaleString()}
2131
</span>
22-
{prizeUnitSymbol}
23-
{prize.toLocaleString()}
2432
</div>
2533
);
2634
}

0 commit comments

Comments
 (0)