Fix clicking whitespaces on replies

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-08-06 15:06:11 +02:00
parent 81b70c6955
commit 0e041f2e77
No known key found for this signature in database
GPG Key ID: CC823428E9B582FB
1 changed files with 9 additions and 3 deletions

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React from 'react'; import React, { createRef } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import dis from '../../../dispatcher/dispatcher'; import dis from '../../../dispatcher/dispatcher';
@ -38,6 +38,8 @@ interface IProps {
@replaceableComponent("views.rooms.ReplyTile") @replaceableComponent("views.rooms.ReplyTile")
export default class ReplyTile extends React.PureComponent<IProps> { export default class ReplyTile extends React.PureComponent<IProps> {
private anchorElement = createRef<HTMLAnchorElement>();
static defaultProps = { static defaultProps = {
onHeightChanged: () => {}, onHeightChanged: () => {},
}; };
@ -71,7 +73,11 @@ export default class ReplyTile extends React.PureComponent<IProps> {
// Following a link within a reply should not dispatch the `view_room` action // Following a link within a reply should not dispatch the `view_room` action
// so that the browser can direct the user to the correct location // so that the browser can direct the user to the correct location
// The exception being the link wrapping the reply // The exception being the link wrapping the reply
if (clickTarget.tagName.toLowerCase() !== "a" || clickTarget.closest("a") === null) { if (
clickTarget.tagName.toLowerCase() !== "a" ||
clickTarget.closest("a") === null ||
clickTarget === this.anchorElement.current
) {
// This allows the permalink to be opened in a new tab/window or copied as // This allows the permalink to be opened in a new tab/window or copied as
// matrix.to, but also for it to enable routing within Riot when clicked. // matrix.to, but also for it to enable routing within Riot when clicked.
e.preventDefault(); e.preventDefault();
@ -141,7 +147,7 @@ export default class ReplyTile extends React.PureComponent<IProps> {
return ( return (
<div className={classes}> <div className={classes}>
<a href={permalink} onClick={this.onClick}> <a href={permalink} onClick={this.onClick} ref={this.anchorElement}>
{ sender } { sender }
<EventTileType <EventTileType
ref="tile" ref="tile"