Skip to content

Commit 08b005e

Browse files
committed
[B] Fix collect toggle button a11y
- Remove aria-hidden on button - Always show a label, add or remove - Remove lengthy label in favor of Add or Remove - Remove separate screen reader status
1 parent 1692dc5 commit 08b005e

File tree

4 files changed

+5
-43
lines changed

4 files changed

+5
-43
lines changed

client/src/config/app/locale/en-US/json/shared/actions.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"cancel_delete": "$t(actions.cancel) $t(actions.delete)",
1717
"clear_selection": "Clear Selection",
1818
"close": "Close",
19-
"collect": "Add \"{{title}}\" to My Starred or Reading Group",
2019
"confirm": "Confirm",
2120
"confirm_delete": "$t(actions.confirm) $t(actions.delete)",
2221
"continue": "Continue",
@@ -84,7 +83,6 @@
8483
"submit": "Submit",
8584
"toggle_collecting": "Toggle collecting dialog for {{title}}",
8685
"toggle_to_state": "Toggle {{label}} to {{state}}",
87-
"uncollect": "Remove \"{{title}}\" from My Starred or Reading Group",
8886
"unflag": "Unflag",
8987
"unmute": "Unmute",
9088
"update": "Update",

client/src/frontend/components/collecting/Toggle/Icons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import IconComposer from "global/components/utility/IconComposer";
44

55
function Icons({ useOutline }) {
66
return (
7-
<div className="collecting-toggle__icons">
7+
<div className="collecting-toggle__icons" aria-hidden="true">
88
<IconComposer
99
icon="MinusUnique"
1010
size={28}

client/src/frontend/components/collecting/Toggle/Text.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from "prop-types";
44

55
function determineText(view, t) {
66
switch (view) {
7+
case "remove":
78
case "remove-active":
89
return {
910
key: "remove",
@@ -15,6 +16,7 @@ function determineText(view, t) {
1516
key: "remove-confirm",
1617
text: t("messages.confirm")
1718
};
19+
case "add":
1820
case "add-active":
1921
return {
2022
key: "add",

client/src/frontend/components/collecting/Toggle/index.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { collectingAPI, requests } from "api";
66
import { useDispatch } from "react-redux";
77
import { entityStoreActions } from "actions";
88
import withReadingGroups from "hoc/withReadingGroups";
9-
import withScreenReaderStatus from "hoc/withScreenReaderStatus";
109
import Dialog from "frontend/components/collecting/Dialog";
1110
import Text from "./Text";
1211
import Icons from "./Icons";
@@ -51,7 +50,6 @@ function CollectingToggle({
5150
onDialogOpen,
5251
onDialogClose,
5352
readingGroups: myReadingGroups,
54-
setScreenReaderStatus,
5553
onUncollect,
5654
hiddenIfUncollected
5755
}) {
@@ -87,21 +85,6 @@ function CollectingToggle({
8785
const collectableTitle = normalizeTitle(collectable);
8886
const useOutlinedStarIcon = outlined && view === "add";
8987

90-
const screenReaderButtonText = () => {
91-
if (hasReadingGroups)
92-
return t("actions.toggle_collecting", { title: collectableTitle });
93-
switch (view) {
94-
case "add":
95-
case "add-active":
96-
return t("actions.collect", { title: collectableTitle });
97-
case "remove":
98-
case "remove-active":
99-
return t("actions.uncollect", { title: collectableTitle });
100-
default:
101-
return "";
102-
}
103-
};
104-
10588
const screenReaderButtonProps = () => {
10689
if (!hasReadingGroups) return {};
10790
return {
@@ -116,7 +99,6 @@ function CollectingToggle({
11699
dispatch(collectRequest);
117100
setHovered(false);
118101
setIsCollecting(true);
119-
setScreenReaderStatus(t("messages.collected", { title: collectableTitle }));
120102
}
121103

122104
function doRemove(collection = currentUser) {
@@ -127,16 +109,6 @@ function CollectingToggle({
127109
});
128110
setConfirmed(false);
129111
setHovered(false);
130-
setScreenReaderStatus(
131-
t("messages.uncollected", { title: collectableTitle })
132-
);
133-
}
134-
135-
function onSRClick(event) {
136-
event.stopPropagation();
137-
// show dialog if user belongs to any RGs
138-
if (hasReadingGroups) return setDialogVisible(true);
139-
collected ? doRemove() : doCollect();
140112
}
141113

142114
function onClick(event) {
@@ -181,13 +153,6 @@ function CollectingToggle({
181153

182154
return (
183155
<>
184-
<button
185-
className="sr-collecting-toggle screen-reader-text"
186-
onClick={onSRClick}
187-
{...screenReaderButtonProps()}
188-
>
189-
{screenReaderButtonText()}
190-
</button>
191156
<button
192157
onClick={onClick}
193158
onMouseEnter={onEnter}
@@ -200,15 +165,13 @@ function CollectingToggle({
200165
"collecting-toggle--filled-always": !outlined,
201166
"collecting-toggle--toc-hidden": hiddenIfUncollected && !collected
202167
})}
203-
aria-hidden="true"
204-
tabIndex={-1}
168+
{...screenReaderButtonProps()}
205169
>
206170
<div
207171
className={classNames({
208172
"collecting-toggle__inner": true,
209173
[`collecting-toggle__inner--${view}`]: true
210174
})}
211-
aria-hidden="true"
212175
>
213176
<Icons useOutline={useOutlinedStarIcon} />
214177
<Text view={view} />
@@ -235,11 +198,10 @@ CollectingToggle.propTypes = {
235198
readingGroups: PropTypes.array,
236199
onDialogOpen: PropTypes.func,
237200
onDialogClose: PropTypes.func,
238-
setScreenReaderStatus: PropTypes.func,
239201
onUncollect: PropTypes.func,
240202
inline: PropTypes.bool,
241203
outlined: PropTypes.bool,
242204
hiddenIfUncollected: PropTypes.bool
243205
};
244206

245-
export default withReadingGroups(withScreenReaderStatus(CollectingToggle));
207+
export default withReadingGroups(CollectingToggle);

0 commit comments

Comments
 (0)