Skip to content

Commit 974b299

Browse files
authored
Update chat-message-content.tsx links in new tab
1 parent a22747c commit 974b299

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/features/ui/chat/chat-message-area/chat-message-content.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ForwardRefRenderFunction } from "react";
1+
import React, { ForwardRefRenderFunction, useEffect } from "react";
22

33
interface ChatMessageContentAreaProps {
44
children?: React.ReactNode;
@@ -8,10 +8,20 @@ const ChatMessageContentArea: ForwardRefRenderFunction<
88
HTMLDivElement,
99
ChatMessageContentAreaProps
1010
> = (props, ref) => {
11+
useEffect(() => {
12+
const links = ref.current?.querySelectorAll('a'); // Select all anchor tags in the current ref
13+
if (links) {
14+
links.forEach(link => {
15+
link.setAttribute('target', '_blank'); // Open in new tab
16+
link.setAttribute('rel', 'noopener noreferrer'); // Security measure
17+
});
18+
}
19+
}, [props.children]); // Run effect when children change
20+
1121
return (
1222
<div
1323
ref={ref}
14-
className="container max-w-3xl relative min-h-screen pb-[240px] pt-16 flex flex-col gap-16"
24+
className="container max-w-3xl relative min-h-screen pb-[240px] pt-16 flex flex-col gap-16"
1525
>
1626
{props.children}
1727
</div>

0 commit comments

Comments
 (0)