Skip to content

Commit 0362ea6

Browse files
authored
Merge pull request matrix-org#3725 from matrix-org/t3chguy/LinkPreviewWidget_a11y
Make URL previews dismissable via keyboard and accessible to screen readers
2 parents b7fe067 + 17a42cd commit 0362ea6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

res/css/views/rooms/_LinkPreviewWidget.scss

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,18 @@ limitations under the License.
5252
}
5353

5454
.mx_LinkPreviewWidget_cancel {
55-
visibility: hidden;
5655
cursor: pointer;
57-
flex: 0 0 40px;
56+
width: 18px;
57+
height: 18px;
58+
59+
img {
60+
flex: 0 0 40px;
61+
visibility: hidden;
62+
}
5863
}
5964

60-
.mx_LinkPreviewWidget:hover .mx_LinkPreviewWidget_cancel {
65+
.mx_LinkPreviewWidget:hover .mx_LinkPreviewWidget_cancel img,
66+
.mx_LinkPreviewWidget_cancel.focus-visible:focus img {
6167
visibility: visible;
6268
}
6369

src/components/views/rooms/LinkPreviewWidget.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2016 OpenMarket Ltd
3+
Copyright 2019 The Matrix.org Foundation C.I.C.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@ import PropTypes from 'prop-types';
1920
import createReactClass from 'create-react-class';
2021
import { linkifyElement } from '../../../HtmlUtils';
2122
import SettingsStore from "../../../settings/SettingsStore";
23+
import { _t } from "../../../languageHandler";
2224

2325
const sdk = require('../../../index');
2426
const MatrixClientPeg = require('../../../MatrixClientPeg');
@@ -125,6 +127,7 @@ module.exports = createReactClass({
125127
</div>;
126128
}
127129

130+
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
128131
return (
129132
<div className="mx_LinkPreviewWidget" >
130133
{ img }
@@ -135,9 +138,10 @@ module.exports = createReactClass({
135138
{ p["og:description"] }
136139
</div>
137140
</div>
138-
<img className="mx_LinkPreviewWidget_cancel mx_filterFlipColor"
139-
src={require("../../../../res/img/cancel.svg")} width="18" height="18"
140-
onClick={this.props.onCancelClick} />
141+
<AccessibleButton className="mx_LinkPreviewWidget_cancel" onClick={this.props.onCancelClick} aria-label={_t("Close preview")}>
142+
<img className="mx_filterFlipColor" alt="" role="presentation"
143+
src={require("../../../../res/img/cancel.svg")} width="18" height="18" />
144+
</AccessibleButton>
141145
</div>
142146
);
143147
},

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@
876876
"Unencrypted": "Unencrypted",
877877
"Please select the destination room for this message": "Please select the destination room for this message",
878878
"Scroll to bottom of page": "Scroll to bottom of page",
879+
"Close preview": "Close preview",
879880
"device id: ": "device id: ",
880881
"Disinvite": "Disinvite",
881882
"Kick": "Kick",

0 commit comments

Comments
 (0)