Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/components/widget/nav/NavItem.vue
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
<template>
<div
v-tooltip.right="{
value: tooltipText,
disabled: !isOverflowing,
pt: { text: { class: 'whitespace-nowrap' } }
}"
class="flex cursor-pointer items-start gap-2 rounded-md px-4 py-3 text-sm transition-colors text-base-foreground"
:class="
active
? 'bg-interface-menu-component-surface-selected'
: 'hover:bg-interface-menu-component-surface-hovered'
"
role="button"
@mouseenter="checkOverflow"
@click="onClick"
>
<div v-if="icon" class="pt-0.5">
<NavIcon :icon="icon" />
</div>
<i v-else class="text-neutral icon-[lucide--folder] text-xs shrink-0" />
<span class="flex items-center break-all">
<span ref="textRef" class="min-w-0 truncate">
<slot></slot>
</span>
</div>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'

import type { NavItemData } from '@/types/navTypes'

import NavIcon from './NavIcon.vue'
Expand All @@ -29,4 +37,15 @@ const { icon, active, onClick } = defineProps<{
active?: boolean
onClick: () => void
}>()

const textRef = ref<HTMLElement | null>(null)
const isOverflowing = ref(false)

const checkOverflow = () => {
if (!textRef.value) return
isOverflowing.value =
textRef.value.scrollWidth > textRef.value.clientWidth + 1
}
Comment on lines +44 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Avoid undocumented magic number in overflow check.

The + 1 tolerance is unconventional and undocumented. Standard overflow detection uses scrollWidth > clientWidth. If this accounts for sub-pixel rendering or rounding, add a comment explaining the intent—otherwise it may miss edge cases where text overflows by exactly 1 pixel.

Suggested fix
 const checkOverflow = () => {
   if (!textRef.value) return
-  isOverflowing.value =
-    textRef.value.scrollWidth > textRef.value.clientWidth + 1
+  // Use strict comparison for overflow detection
+  isOverflowing.value = textRef.value.scrollWidth > textRef.value.clientWidth
 }

Or, if the tolerance is intentional for sub-pixel rendering:

 const checkOverflow = () => {
   if (!textRef.value) return
+  // Add 1px tolerance to account for sub-pixel rendering differences
   isOverflowing.value =
     textRef.value.scrollWidth > textRef.value.clientWidth + 1
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const checkOverflow = () => {
if (!textRef.value) return
isOverflowing.value =
textRef.value.scrollWidth > textRef.value.clientWidth + 1
}
const checkOverflow = () => {
if (!textRef.value) return
// Use strict comparison for overflow detection
isOverflowing.value = textRef.value.scrollWidth > textRef.value.clientWidth
}
🤖 Prompt for AI Agents
In @src/components/widget/nav/NavItem.vue around lines 44 - 48, The overflow
check in checkOverflow uses an undocumented magic number "+ 1" which is unclear;
either remove the tolerance and use the standard check
(textRef.value.scrollWidth > textRef.value.clientWidth) or replace the literal
with a named constant (e.g., OVERFLOW_TOLERANCE) and a short comment explaining
it's to account for sub-pixel/rounding issues; update checkOverflow to reference
that constant and ensure isOverflowing.value is set accordingly, using the
unique symbols checkOverflow, textRef, and isOverflowing to locate the change.


const tooltipText = computed(() => textRef.value?.textContent ?? '')
</script>