ProfileDropdown
@experimental
Authenticated user menu for dashboards and portals.
Quick Start
from faststrap import ProfileDropdown
ProfileDropdown(
"Alice Smith",
subtitle="Administrator",
items=[
("Profile", "/profile"),
("Settings", "/settings"),
("Sign out", "/logout"),
],
)
Features
- Avatar with image or automatic initials fallback
- Optional subtitle/role display
- Dropdown menu with account actions
- Menu items render as real
<a>links, so navigation works without extra JavaScript
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
required | User display name. |
subtitle |
str \| None |
None |
Optional role, team, or email shown below the name. |
src |
str \| None |
None |
Optional avatar image URL. When omitted, initials are shown. |
items |
list[tuple[str, str]] \| list[tuple[str, str, dict]] \| None |
None |
Menu entries as (label, href) tuples rendered as anchor links; an optional third dict element merges extra attributes onto the anchor. |
alignment |
str |
"end" |
Bootstrap dropdown menu alignment. |
avatar_size |
int |
32 |
Avatar edge length in pixels (initials font scales automatically). |
layout |
"horizontal" \| "stacked" |
"stacked" |
"horizontal" places the subtitle beside the name on one line; "stacked" reproduces the original block layout. |
trigger_cls / menu_cls / item_cls |
str |
"" |
Slot classes for the toggle, menu, and each item anchor. |
footer |
Any \| None |
None |
Element rendered after the items inside the menu (divider + padded section). |
**kwargs |
Any |
Extra wrapper attributes. |
ProfileDropdown(
"Alice Smith",
subtitle="Administrator",
src="/assets/avatars/alice.jpg",
layout="horizontal", # one-line trigger on desktop
avatar_size=36,
items=[
("Profile", "/profile"),
("Settings", "/settings"),
("Sign out", "/logout", {"data_testid": "logout"}),
],
footer=Button("Switch workspace", variant="outline-secondary", size="sm"),
)
Global defaults work too: set_component_defaults("ProfileDropdown", avatar_size=36, layout="horizontal").
Usage Examples
Basic Profile Menu
ProfileDropdown(
"Alice Smith",
items=[
("Profile", "/profile"),
("Settings", "/settings"),
("Sign out", "/logout"),
],
)
With Avatar Image
ProfileDropdown(
"Bob Jones",
src="/assets/avatars/bob.jpg",
subtitle="Editor",
items=[("Profile", "/profile"), ("Sign out", "/logout")],
)
Without Menu Items
Notes
- Requires Bootstrap Dropdown JavaScript for toggle behavior; menu item links are plain anchors and navigate without extra JS.
- The trigger is a native
<button>(type="button",data-bs-toggle="dropdown") so the menu opens with a mouse click,Enter, orSpace, and is announced to screen readers with anaria-labelmatching the user's full name. - Marked
@experimental.
API Reference
faststrap.components.navigation.profile_dropdown.ProfileDropdown(name, *, subtitle=None, src=None, items=None, alignment=UNSET, avatar_size=UNSET, layout=UNSET, trigger_cls='', menu_cls='', item_cls='', footer=None, **kwargs)
Authenticated user menu for dashboards and portals.
Renders a dropdown toggle showing the user's avatar/initials and a
menu of account actions. The toggle is a native <button> so the
menu opens via mouse click, Enter, or Space, and menu items
render as real <a> links so navigation works without custom
JavaScript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
User display name. |
required |
subtitle
|
str | None
|
Optional role, team, or email shown below ( |
None
|
src
|
str | None
|
Optional avatar image URL. When omitted, initials are shown. |
None
|
items
|
list[tuple[str, str]] | list[tuple[str, str, dict[str, Any]]] | None
|
Optional menu entries as |
None
|
alignment
|
str | None
|
Bootstrap dropdown menu alignment, typically |
UNSET
|
avatar_size
|
int | None
|
Avatar edge length in pixels (default 32). |
UNSET
|
layout
|
Literal['horizontal', 'stacked'] | None
|
Trigger text arrangement: |
UNSET
|
trigger_cls
|
str
|
Extra classes for the dropdown toggle button. |
''
|
menu_cls
|
str
|
Extra classes for the dropdown menu. |
''
|
item_cls
|
str
|
Extra classes for each menu anchor. |
''
|
footer
|
Any | None
|
Optional element rendered after the items inside the menu (wrapped in a bordered footer section when present). |
None
|
**kwargs
|
Any
|
Additional HTML attributes for the wrapper. |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML |
Source code in src/faststrap/components/navigation/profile_dropdown.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |