Skip to content

feat: add selected option to commands for pre-selection#2817

Open
Br1an67 wants to merge 1 commit intoChainlit:mainfrom
Br1an67:fix/issue-2141-command-selected-option
Open

feat: add selected option to commands for pre-selection#2817
Br1an67 wants to merge 1 commit intoChainlit:mainfrom
Br1an67:fix/issue-2141-command-selected-option

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

What

Add a selected boolean option to commands that enables pre-selecting a command when the page loads.

Closes #2141

Why

Command selection resets on page refresh. Developers need a way to persist the selected command state by setting it from the backend (e.g. from a cached value).

Changes

  • backend/chainlit/types.py: Add selected: Optional[bool] to CommandDict
  • libs/react-client/src/types/command.ts: Add selected?: boolean to ICommand
  • frontend/src/components/chat/MessageComposer/index.tsx: Add useEffect that auto-selects the command marked selected: True when commands are received (only if no command is already selected)

Usage

commands = [
    {"id": "Search", "icon": "globe", "description": "Web search", "button": True, "persistent": True, "selected": True}
]

Testing

Backward compatible — commands without selected work exactly as before. The selected flag is only honored when no command is already user-selected.


Summary by cubic

Adds a selected option to commands to pre-select a command on load. This lets the backend persist command state across refreshes, addressing #2141.

  • New Features
    • Backend: CommandDict now supports selected: Optional[bool].
    • React client: ICommand now supports selected?: boolean.
    • UI: MessageComposer auto-selects the command with selected=true when commands load, only if no command is already selected.

Written for commit 0bccfa2. Summary will update on new commits.

Add 'selected' boolean to CommandDict/ICommand. When set, the command
is automatically pre-selected in the composer on load, enabling
persistence across page refreshes via backend state.
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Mar 1, 2026
@dosubot dosubot bot added enhancement New feature or request frontend Pertains to the frontend. labels Mar 1, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend Pertains to the frontend. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands - Requesting to add an option like "selected" : True which can be set dynamically based on cached value

1 participant