Merge pull request #3704 from MarcoZehe/MoreAccessibleReactions

Make reaction buttons more accessible
This commit is contained in:
J. Ryan Stinnett 2019-12-06 15:43:20 +00:00 committed by GitHub
commit cb28e2062b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

View file

@ -149,7 +149,11 @@ export default class ReactionsRow extends React.PureComponent {
</a>; </a>;
} }
return <div className="mx_ReactionsRow"> return <div
className="mx_ReactionsRow"
role="toolbar"
aria-label={_t("Reactions")}
>
{items} {items}
{showAllButton} {showAllButton}
</div>; </div>;

View file

@ -20,6 +20,8 @@ import classNames from 'classnames';
import MatrixClientPeg from '../../../MatrixClientPeg'; import MatrixClientPeg from '../../../MatrixClientPeg';
import sdk from '../../../index'; import sdk from '../../../index';
import { _t } from '../../../languageHandler';
import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
export default class ReactionsRowButton extends React.PureComponent { export default class ReactionsRowButton extends React.PureComponent {
static propTypes = { static propTypes = {
@ -79,7 +81,7 @@ export default class ReactionsRowButton extends React.PureComponent {
render() { render() {
const ReactionsRowButtonTooltip = const ReactionsRowButtonTooltip =
sdk.getComponent('messages.ReactionsRowButtonTooltip'); sdk.getComponent('messages.ReactionsRowButtonTooltip');
const { content, count, reactionEvents, myReactionEvent } = this.props; const { mxEvent, content, count, reactionEvents, myReactionEvent } = this.props;
const classes = classNames({ const classes = classNames({
mx_ReactionsRowButton: true, mx_ReactionsRowButton: true,
@ -96,15 +98,46 @@ export default class ReactionsRowButton extends React.PureComponent {
/>; />;
} }
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId());
let label;
if (room) {
const senders = [];
for (const reactionEvent of reactionEvents) {
const member = room.getMember(reactionEvent.getSender());
const name = member ? member.name : reactionEvent.getSender();
senders.push(name);
}
label = _t(
"<reactors/><reactedWith> reacted with %(content)s</reactedWith>",
{
content,
},
{
reactors: () => {
return formatCommaSeparatedList(senders, 6);
},
reactedWith: (sub) => {
if (!content) {
return null;
}
return sub;
},
},
);
}
return <span className={classes} return <span className={classes}
role="button"
aria-label={label}
tabindex="0"
onClick={this.onClick} onClick={this.onClick}
onMouseOver={this.onMouseOver} onMouseOver={this.onMouseOver}
onMouseOut={this.onMouseOut} onMouseOut={this.onMouseOut}
> >
<span className="mx_ReactionsRowButton_content"> <span className="mx_ReactionsRowButton_content" aria-hidden="true">
{content} {content}
</span> </span>
<span className="mx_ReactionsRowButton_count"> <span className="mx_ReactionsRowButton_count" aria-hidden="true">
{count} {count}
</span> </span>
{tooltip} {tooltip}

View file

@ -1117,6 +1117,8 @@
"You sent a verification request": "You sent a verification request", "You sent a verification request": "You sent a verification request",
"Error decrypting video": "Error decrypting video", "Error decrypting video": "Error decrypting video",
"Show all": "Show all", "Show all": "Show all",
"Reactions": "Reactions",
"<reactors/><reactedWith> reacted with %(content)s</reactedWith>": "<reactors/><reactedWith> reacted with %(content)s</reactedWith>",
"<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>": "<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>", "<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>": "<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>",
"%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s", "%(senderDisplayName)s changed the avatar for %(roomName)s": "%(senderDisplayName)s changed the avatar for %(roomName)s",
"%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.", "%(senderDisplayName)s removed the room avatar.": "%(senderDisplayName)s removed the room avatar.",