N
Nuxt3mo ago
PetyXbron

Nuxt UI DropDownMenuItem avatar size

When replicating Nuxt UI dashboard, there is a teams ref const teams = ref([{ label: 'Nuxt', avatar: { src: 'https://github.com/nuxt.png', alt: 'Nuxt' } }, { label: 'NuxtHub', avatar: { src: 'https://github.com/nuxt-hub.png', alt: 'NuxtHub' } }, { label: 'NuxtLabs', avatar: { src: 'https://github.com/nuxtlabs.png', alt: 'NuxtLabs' } }]) computed like this: const items = computed<DropdownMenuItem[][]>(() => { return [teams.value.map(team => ({ ...team, onSelect() { selectedTeam.value = team } })), [{ label: 'Create team', icon: 'i-lucide-circle-plus' }, { label: 'Manage teams', icon: 'i-lucide-cog' }]] }) If I want to make the avatar size bigger, I just add "size" property to the avatar object of team. It works, but I get a type error. What's the right solution for changing the size of DropdownMenuItem avatar?
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @PetyXbron. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The correct way to change the avatar size for a DropdownMenuItem in Nuxt UI is to use the avatar.size property, as you have done. The avatar object supports a size prop with values like "md", "lg", "xl", etc., which are documented for the UAvatar component. This prop is also available when using avatars inside menu items, including DropdownMenuItem objects. However, if you are getting a type error, it is likely because the type definition for DropdownMenuItem['avatar'] may not explicitly include the size property, even though the underlying component supports it. The documentation shows that the avatar prop is of type AvatarProps, and AvatarProps does include size as a valid property:
| `size` | `'md'` | `"md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl"` |
| `size` | `'md'` | `"md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl"` |
Avatar API So, the approach you are using is correct from a usage perspective:
const teams = ref([{
label: 'Nuxt',
avatar: {
src: '<https://github.com/nuxt.png',>
alt: 'Nuxt',
size: 'xl' // This is correct
}
}, ...])
const teams = ref([{
label: 'Nuxt',
avatar: {
src: '<https://github.com/nuxt.png',>
alt: 'Nuxt',
size: 'xl' // This is correct
}
}, ...])
If you get a type error, you can safely ignore it or cast the object to the correct type, since the runtime component will accept the size prop. Alternatively, you can extend the type definition in your project if you want strict type safety. Summary:
- Setting size on the avatar object is the correct way to change the avatar size in a DropdownMenuItem. - Type errors may be due to incomplete type definitions, not a usage issue. - The runtime will render the avatar at the specified size as expected. References:
- DropdownMenu items and avatar prop - UAvatar size prop ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@411436203330502658> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?