@@ -24,7 +24,7 @@ import {
2424 UserRoundIcon ,
2525 type LucideIcon ,
2626} from "lucide-react" ;
27- import { memo , useLayoutEffect , useRef } from "react" ;
27+ import { memo , useLayoutEffect , useRef , useState } from "react" ;
2828
2929import { type ComposerSlashCommand , type ComposerTriggerKind } from "../../composer-logic" ;
3030import { cn } from "~/lib/utils" ;
@@ -201,6 +201,15 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
201201 props . triggerKind === "slash-command" && props . item . type === "skill" ? props . item . skill : null ;
202202 const pullRequestPresentation =
203203 props . item . type === "pull-request" ? resolvePullRequestState ( props . item . pullRequest ) : null ;
204+ const descriptionRef = useRef < HTMLSpanElement > ( null ) ;
205+ const [ descriptionTruncated , setDescriptionTruncated ] = useState ( false ) ;
206+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- measures the rendered description so only cut-off text gets a tooltip
207+ useLayoutEffect ( ( ) => {
208+ const description = descriptionRef . current ;
209+ setDescriptionTruncated (
210+ props . isActive && ! ! description && description . scrollWidth > description . clientWidth ,
211+ ) ;
212+ } , [ props . isActive ] ) ;
204213
205214 return (
206215 < CommandItem
@@ -264,11 +273,14 @@ const ComposerCommandMenuItem = memo(function ComposerCommandMenuItem(props: {
264273 props . item . label
265274 ) }
266275 </ span >
267- < Tooltip open = { props . isActive && props . item . description . length > 0 } >
276+ < Tooltip open = { descriptionTruncated } >
268277 < TooltipTrigger
269278 tabIndex = { - 1 }
270279 render = {
271- < span className = "min-w-0 flex-1 truncate text-left text-secondary-label text-xs" />
280+ < span
281+ ref = { descriptionRef }
282+ className = "min-w-0 flex-1 truncate text-left text-secondary-label text-xs"
283+ />
272284 }
273285 >
274286 { props . item . description }
0 commit comments