| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | import { useState } from "react"; | 1 | import { useId, useState } from "react"; |
| 2 | | 2 | |
| 3 | import { cn } from "../../lib/utils"; | 3 | import { cn } from "../../lib/utils"; |
| 4 | | 4 | |
| ... | @@ -17,12 +17,14 @@ export function ExpandableText({ | ... | @@ -17,12 +17,14 @@ export function ExpandableText({ |
| 17 | collapsedClassName?: string; | 17 | collapsedClassName?: string; |
| 18 | expandLabel?: string; | 18 | expandLabel?: string; |
| 19 | }) { | 19 | }) { |
| | 20 | const textId = useId(); |
| 20 | const [expanded, setExpanded] = useState(false); | 21 | const [expanded, setExpanded] = useState(false); |
| 21 | const canExpand = text.length > 180 || text.includes("\n"); | 22 | const canExpand = text.length > 180 || text.includes("\n"); |
| 22 | | 23 | |
| 23 | return ( | 24 | return ( |
| 24 | <div className={cn("min-w-0", className)}> | 25 | <div className={cn("min-w-0", className)}> |
| 25 | <div | 26 | <div |
| | 27 | id={textId} |
| 26 | className={cn( | 28 | className={cn( |
| 27 | "whitespace-pre-wrap break-words", | 29 | "whitespace-pre-wrap break-words", |
| 28 | !expanded && canExpand ? collapsedClassName : null, | 30 | !expanded && canExpand ? collapsedClassName : null, |
| ... | @@ -33,6 +35,8 @@ export function ExpandableText({ | ... | @@ -33,6 +35,8 @@ export function ExpandableText({ |
| 33 | {canExpand ? ( | 35 | {canExpand ? ( |
| 34 | <button | 36 | <button |
| 35 | type="button" | 37 | type="button" |
| | 38 | aria-expanded={expanded} |
| | 39 | aria-controls={textId} |
| 36 | className="cursor-pointer mt-1 text-[11px] font-medium text-foreground/70 underline-offset-2 hover:text-foreground hover:underline" | 40 | className="cursor-pointer mt-1 text-[11px] font-medium text-foreground/70 underline-offset-2 hover:text-foreground hover:underline" |
| 37 | onClick={() => setExpanded((value) => !value)} | 41 | onClick={() => setExpanded((value) => !value)} |
| 38 | > | 42 | > |