@@ -14,15 +14,13 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import React , { useCallback , useContext , useEffect , useRef } from "react" ;
17+ import React , { useCallback , useContext , useRef } from "react" ;
1818import { Room } from "matrix-js-sdk/src/models/room" ;
1919import classNames from "classnames" ;
2020import { EventType } from "matrix-js-sdk/src/@types/event" ;
2121
22- import { linkifyElement } from "../../../HtmlUtils" ;
2322import { useTopic } from "../../../hooks/room/useTopic" ;
24- import useHover from "../../../hooks/useHover" ;
25- import Tooltip , { Alignment } from "./Tooltip" ;
23+ import { Alignment } from "./Tooltip" ;
2624import { _t } from "../../../languageHandler" ;
2725import dis from "../../../dispatcher/dispatcher" ;
2826import { Action } from "../../../dispatcher/actions" ;
@@ -32,6 +30,7 @@ import { useDispatcher } from "../../../hooks/useDispatcher";
3230import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
3331import AccessibleButton from "./AccessibleButton" ;
3432import { Linkify } from "./Linkify" ;
33+ import TooltipTarget from "./TooltipTarget" ;
3534
3635interface IProps extends React . HTMLProps < HTMLDivElement > {
3736 room ?: Room ;
@@ -43,7 +42,6 @@ export default function RoomTopic({
4342} : IProps ) {
4443 const client = useContext ( MatrixClientContext ) ;
4544 const ref = useRef < HTMLDivElement > ( ) ;
46- const hovered = useHover ( ref ) ;
4745
4846 const topic = useTopic ( room ) ;
4947
@@ -57,14 +55,27 @@ export default function RoomTopic({
5755 dis . fire ( Action . ShowRoomTopic ) ;
5856 } , [ props ] ) ;
5957
58+ const ignoreHover = ( ev : React . MouseEvent ) : boolean => {
59+ return ( ev . target as HTMLElement ) . tagName . toUpperCase ( ) === "A" ;
60+ } ;
61+
6062 useDispatcher ( dis , ( payload ) => {
6163 if ( payload . action === Action . ShowRoomTopic ) {
6264 const canSetTopic = room . currentState . maySendStateEvent ( EventType . RoomTopic , client . getUserId ( ) ) ;
6365
6466 const modal = Modal . createDialog ( InfoDialog , {
6567 title : room . name ,
6668 description : < div >
67- < Linkify as = "p" > { topic } </ Linkify >
69+ < Linkify
70+ as = "p"
71+ onClick = { ( ev : MouseEvent ) => {
72+ if ( ( ev . target as HTMLElement ) . tagName . toUpperCase ( ) === "A" ) {
73+ modal . close ( ) ;
74+ }
75+ } }
76+ >
77+ { topic }
78+ </ Linkify >
6879 { canSetTopic && < AccessibleButton
6980 kind = "primary_outline"
7081 onClick = { ( ) => {
@@ -80,10 +91,6 @@ export default function RoomTopic({
8091 }
8192 } ) ;
8293
83- useEffect ( ( ) => {
84- linkifyElement ( ref . current ) ;
85- } , [ topic ] ) ;
86-
8794 const className = classNames ( props . className , "mx_RoomTopic" ) ;
8895
8996 return < div { ...props }
@@ -92,9 +99,10 @@ export default function RoomTopic({
9299 dir = "auto"
93100 className = { className }
94101 >
95- { topic }
96- { hovered && (
97- < Tooltip label = { _t ( "Click to read topic" ) } alignment = { Alignment . Bottom } />
98- ) }
102+ < TooltipTarget label = { _t ( "Click to read topic" ) } alignment = { Alignment . Bottom } ignoreHover = { ignoreHover } >
103+ < Linkify >
104+ { topic }
105+ </ Linkify >
106+ </ TooltipTarget >
99107 </ div > ;
100108}
0 commit comments