QdsUserAvatar

A user avatar component that displays either an image or initials.

Overview

The qds-user-avatar component is a custom element that displays a user’s avatar, either as an image or as their initials if no image is available. It also supports displaying a status indicator.

Usage

To use the qds-user-avatar component, include it in your HTML:

<qds-user-avatar name="John Doe" image="url-to-image" status="online"></qds-user-avatar>

API Reference

Attributes

CSS Parts

Events

Example

<qds-user-avatar name="John Doe" image="url-to-image" status="online"></qds-user-avatar>
<script>
  const avatar = document.querySelector('qds-user-avatar');
  avatar.addEventListener('click', () => {
    console.log('Avatar clicked');
  });
</script>


## Image Error Fallback

If a supplied image fails to load, the avatar presents initials while preserving the public `image`, `name` and `status` values. Changing the image URL retries with the new image; clearing it restores initials immediately. Updating other properties after an error does not retry the failed URL. Errors from a replaced or disconnected image do not replace the current portrait. Attribute text is escaped before rendering.

The generic avatar remains independent of authentication. For a purely decorative portrait beside a visible contact name, mark the host `inert aria-hidden="true"` so its existing optional action semantics do not create a redundant focus stop. Northwind's review-contact list uses this composition at `/#/admin/team`. Authenticated-avatar subclasses retain their existing sign-in/menu contracts.