The switcher for the role a user acts as (PhoenixKit.Users.ActiveRole).
Renders nothing unless the scope is narrowed — the switcher is on and the
user holds two or more switchable roles. An impersonation session gets the
switcher like any other: the role lives on the session token, so switching
there never touches the borrowed account's own sessions. Every row is a
plain form PUT to /users/session/role, like the account switcher: this
renders in layouts, where a phx-click would land in whichever LiveView the
page mounted.
Reads only the scope: the switchable roles are loaded once by
PhoenixKit.Users.Auth.Scope.for_user/1, so rendering on every page costs no
query.
Variants
:menu_section— a "Role" section for an account dropdown's<ul class="menu">. Always rendered where the switcher is visible, except that with the switcher placed in the header it shows only below thesmbreakpoint, where the header control is hidden.:header— a compact dropdown for a header bar, rendered only whenrole_switcher_locationis"header", and only fromsmup.
Render both, once each, and the location setting decides which one a visitor sees at which width:
<.role_switcher variant={:header} id="admin-role-switcher-header" scope={@scope} ... />
<.role_switcher variant={:menu_section} id="admin-role-switcher-menu" scope={@scope} ... />
Summary
Functions
Renders the role switcher.
Functions
Renders the role switcher.
Attributes
:scope— the current scope. Renders nothing unless it is narrowed.:id— unique per placement; prefixes every form id.:variant—:menu_section(default) or:header.:current_path— sent asreturn_to, so the switch comes back here when the new role can reach it.:current_locale— keeps the form's action on the visitor's locale.:location—:menuor:header.nil(default) reads therole_switcher_locationsetting; pass it to render without a settings read.
Attributes
scope(:any) - Defaults tonil.id(:string) (required)variant(:atom) - Defaults to:menu_section. Must be one of:menu_section, or:header.current_path(:string) - Defaults to"".current_locale(:string) - Defaults tonil.location(:atom) - Defaults tonil.Must be one ofnil,:menu, or:header.