AvatarButton

AvatarButton

HkAvatarButton is the avatar trigger: the round account button at the top of every application face. It owns the shared avatar grammar — the image, the graceful letter fallback when there is no image or it failed to load, and the 28px round footprint — so every face renders it the same way.

  • It is a trigger, not a menu: what opens on a press is the host's. For the standard console header that already contains one, see the admin header.
  • To show who a piece of content belongs to, without an action, use the avatar rather than a button.

Import

tsx
1
import { HkAvatarButton } from "@celestia-island/hikari";
rust
1
2
// The mirror lives in the crate's `theme` module, not at its root.
use hikari_components::theme::AvatarButton;

In the Vue form the component is the named export HkAvatarButton; in the Rust form the function is hikari_components::theme::AvatarButton, so a fence begins with a block-scoped use for it.

Image, letter and empty name

avatarUrl is the picture; username is the letter shown when the picture is missing — the first character, upper-cased — and the image's alt text. With neither, the button shows ?. label is the accessible name of the trigger and should say what it opens, not who the user is.

What it opens

popup is the aria-haspopup value — "menu" for a dropdown, "dialog" for a drawer — and expanded is aria-expanded, which says whether that menu is open. A drawer-mode trigger carries no expanded state, since it has none to announce.

Interaction

click carries the native MouseEvent. The example is an account switcher: each press advances to the next user, and a new avatarUrl gets a fresh load attempt. A small menu opens alongside and expanded follows it.

TSX

API

Vue

Props

NameTypeDefaultRequired
avatarUrlString""—
usernameString""—
labelStringundefined—
popup<code>String as PropType<"menu" | "dialog" | undefined></code>undefined—
expandedBooleanundefined—

Emits

EventPayload
clickMouseEvent

Rust

Props — AvatarButton

PropTypeDefaultDescription
avatar_urlString""Avatar image URL; empty renders the letter fallback (Vue avatarUrl, default "").
usernameString""Signed-in name: the fallback letter, and the image's alt.
labelOption<String>NoneAccessible label for the trigger — what it OPENS, not who it is.
popupOption<AvatarButtonPopup>Nonearia-haspopup value (Vue popup).
expandedOption<bool>Nonearia-expanded; omit for drawer-mode triggers (no open state).
failedboolfalseCONTROLLED failed-load latch (Vue: the internal avatarFailed ref).
on_errorOption<EventHandler<()>>NoneThe trigger image failed to load (the host sets failed).
on_clickOption<EventHandler<MouseEvent>>NoneTrigger pressed (Vue: the click emit, the event verbatim).

Notes

  • The Rust mirror keeps no state: a failed image load is reported through on_error and remembered only when the host sets the failed prop; clearing it on a new avatar_url is the host's job too.
  • Extra attributes fall through to the button element in the Vue form; the Rust form has typed props only.
  • The button has no hover veil on purpose: what it opens is a menu, not an avatar editor.

Accessibility

  • Always pass label: it is the button's accessible name (aria-label), and it should name the destination — "Account menu", not the user's name.
  • Set popup and expanded to match what actually opens; they are what assistive technology announces.
  • The image's alt text is the username; the letter fallback carries no text for assistive technology beyond the label.

Related components