Overview
TheTeamSwitcher component provides a select dropdown that allows users to switch between their teams. It includes team creation options, management links, and support for a “personal” or null team state. The component automatically displays team avatars and handles team switching logic.
Usage
With Null/Personal Option
Props
The currently selected team object. Takes precedence over
teamId.The ID of the currently selected team. Used when
team prop is not provided.Array of available teams. If not provided, uses teams from the current user via
useTeams() hook.Enables a “no team” or “personal” option in the dropdown for contexts where team selection is optional.
Custom label for the null/personal option when
allowNull is true.Additional CSS classes to apply to the select trigger button.
Callback function triggered when a team is selected. Receives the selected team or null (if
allowNull is true).Mock user data for testing:
team: Currently selected mock team withid,displayName, and optionalprofileImageUrl
Array of mock teams for testing, each with
id, displayName, and optional profileImageUrl.Mock project configuration:
config.clientTeamCreationEnabled: Enable/disable team creation button
Examples
Basic Team Switcher
With Personal/No Team Option
With Custom Handler
Controlled Component
With Custom Styling
In Navigation Bar
Features
Team Selection Groups
The dropdown organizes teams into logical groups:- Current Team: The selected team with a settings button
- Personal/No Team (optional): When
allowNullis enabled - Other Teams: All other teams the user belongs to
- Create Team Button: When team creation is enabled
Team Icons
- Displays team profile images when available
- Falls back to team initials
- Consistent icon sizing across all items
- Special “personal” icon for null team option
Management Features
- Quick access to team settings via gear icon
- Deep links to team-specific settings pages
- “Create a team” button when enabled in project config
- Team creation redirects to account settings
Responsive Design
- Maximum width of 256px (w-64) for optimal display
- Truncated team names with ellipsis for long names
- Loading skeleton while team data is being fetched
- Smooth transitions and animations
Smart Sorting
- Selected team automatically appears at the top
- Remaining teams sorted by ID
- Consistent ordering for better UX
Error Handling
- Validates team selection
- Throws assertion error if selected team not found
- Proper async error handling with alerts
Dropdown Structure
Integration
The TeamSwitcher integrates with:- User’s team membership data
- Account settings interface
- Team creation flow
- Project configuration
Accessibility
- Full keyboard navigation
- Screen reader support
- ARIA labels and roles
- Focus management
Mock Mode
When using mock data:- Navigation actions are prevented
- Team switching logs to console
- Perfect for demos and testing
Related Components
- UserButton - User menu and authentication
- AccountSettings - Team management interface
- Team Management - Learn about teams and organizations