Events
The Blazor PromptBox component provides comprehensive event handling for user interactions and state changes. This article explains the events available in the PromptBox component and how to use them effectively.
The PromptBox fires events for text input changes, action button interactions, speech-to-text results, and file selection activities.
OnPromptAction
The OnPromptAction event represents the primary user action for submitting content or stopping ongoing operations. This event fires when:
- The user clicks the action button
- The user presses Enter (when content is available and not loading)
- The button state changes between Send and Stop modes
The event provides PromptBoxActionButtonEventArgs containing the current text and action type.
Handle action button interactions
The event is an
EventCallback. It can be synchronous and returnvoid, or asynchronous and returnasync Task. Do not useasync void.
ValueChanged
The ValueChanged event fires upon every change in the text input (such as each keystroke). When using the ValueChanged event, you cannot use two-way data binding because the @bind-Value directive internally uses this event.
Handle ValueChanged event
OnChange
The OnChange event represents a user confirmation of the current value. It is triggered when the input loses focus after the value has been changed during that focus session.
Handle OnChange event
OnBlur
The OnBlur event fires when the PromptBox loses focus, regardless of whether the value has changed.
Handle OnBlur event
Speech-to-Text Events
When speech-to-text functionality is enabled, the PromptBox provides events through the PromptBoxSpeechToTextButtonSettings:
-
OnStart: Fires when speech recognition begins.
-
OnResult: Fires when speech recognition returns results. Provides
SpeechToTextButtonResultEventArgswith recognition data. -
OnEnd: Fires when speech recognition ends or disconnects.
-
OnError: Fires when a speech recognition error occurs.
Speech-to-text event handling
File Selection Events
File selection events are handled through the PromptBoxFileSelectButtonSettings.
OnSelect
Fires when users select files. Provides FileSelectEventArgs with information about the selected files.