-
Notifications
You must be signed in to change notification settings - Fork 494
feat: add overflow tooltip to NavItem #8009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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' | ||||||||||||||||||||||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid undocumented magic number in overflow check. The 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const tooltipText = computed(() => textRef.value?.textContent ?? '') | ||||||||||||||||||||||
| </script> | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.