({
tab,
active,
showDivider = true,
isDragging,
isReordering,
onSelect,
onClose,
onRename,
onContextMenu,
onDragStart,
onDragOver,
onDrop,
onDragEnd,
onHoverChanged,
renameRef,
}: VTabProps)
| 36 | } |
| 37 | |
| 38 | export function VTab({ |
| 39 | tab, |
| 40 | active, |
| 41 | showDivider = true, |
| 42 | isDragging, |
| 43 | isReordering, |
| 44 | onSelect, |
| 45 | onClose, |
| 46 | onRename, |
| 47 | onContextMenu, |
| 48 | onDragStart, |
| 49 | onDragOver, |
| 50 | onDrop, |
| 51 | onDragEnd, |
| 52 | onHoverChanged, |
| 53 | renameRef, |
| 54 | }: VTabProps) { |
| 55 | const [originalName, setOriginalName] = useState(tab.name); |
| 56 | const [isEditable, setIsEditable] = useState(false); |
| 57 | const editableRef = useRef<HTMLDivElement>(null); |
| 58 | const editableTimeoutRef = useRef<NodeJS.Timeout | null>(null); |
| 59 | const badges = tab.badges ?? (tab.badge ? [tab.badge] : null); |
| 60 | |
| 61 | const rawFlagColor = tab.flagColor; |
| 62 | let flagColor: string | null = null; |
| 63 | if (rawFlagColor) { |
| 64 | try { |
| 65 | validateCssColor(rawFlagColor); |
| 66 | flagColor = rawFlagColor; |
| 67 | } catch { |
| 68 | flagColor = null; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | useEffect(() => { |
| 73 | setOriginalName(tab.name); |
| 74 | }, [tab.name]); |
| 75 | |
| 76 | useEffect(() => { |
| 77 | return () => { |
| 78 | if (editableTimeoutRef.current) { |
| 79 | clearTimeout(editableTimeoutRef.current); |
| 80 | } |
| 81 | }; |
| 82 | }, []); |
| 83 | |
| 84 | const selectEditableText = useCallback(() => { |
| 85 | if (!editableRef.current) { |
| 86 | return; |
| 87 | } |
| 88 | editableRef.current.focus(); |
| 89 | const range = document.createRange(); |
| 90 | const selection = window.getSelection(); |
| 91 | if (!selection) { |
| 92 | return; |
| 93 | } |
| 94 | range.selectNodeContents(editableRef.current); |
| 95 | selection.removeAllRanges(); |
nothing calls this directly
no test coverage detected