Avatar
VAvatar represents a person or entity with an image, icon or initials.
Usage
Examples
With a picture
src displays the image. If it fails to load, the avatar uses its icon or initials.
With an icon
icon replaces initials. Provide name or alt for an accessible name.
Initials and automatic colour
Without an image or icon, name supplies initials and determines the background colour.
Sizes
size sets the avatar diameter.
Custom colour
color overrides the automatic background. Check its contrast with the white foreground.
Buttons and links
clickable creates a button; href creates a link and takes precedence. disabled disables either control.
With a tooltip
For VTooltip, make the avatar focusable with clickable or href and bind triggerProps.
Router
VAvatar renders a real <a> when href is set. With Nuxt or Vue Router, render it inside the router link in custom mode and pass on href and navigate. A click with a modifier key still opens a new tab.
<RouterLink v-slot="{ href, navigate }" to="/profile" custom>
<VAvatar :href="href" name="Ada Lovelace" @click="navigate" />
</RouterLink>API
Props
| Prop | Type | Default |
|---|---|---|
src | string | none |
| Image URL. Falls back to the icon or initials on loading failure. | ||
icon | IconSource | none |
| Icon shown without an image. Takes precedence over initials. | ||
name | string | none |
| Full name used for the accessible name, initials and automatic colour. | ||
alt | string | none |
Accessible name overriding name. Consumer aria-label takes precedence. | ||
color | string | none |
| Custom CSS background colour. The foreground stays white. | ||
size | AvatarSize'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
Avatar diameter. Inherits the group size; otherwise defaults to md. | ||
href | string | none |
Link destination. Takes precedence over clickable; removed when disabled. | ||
clickable | boolean | false |
Renders a button when href is absent. | ||
disabled | boolean | false |
| Disables interactive avatars and removes them from the tab order. | ||
Slots
| Slot | Type |
|---|---|
default | {} |
| Content replacing initials. | |
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender
CSS variables
| Token | Value |
|---|---|
--vectis-control-size-avatar-ring | 2px |