diff --git a/solara/lab/components/chat.py b/solara/lab/components/chat.py index cd9ecba58..1f64813c5 100644 --- a/solara/lab/components/chat.py +++ b/solara/lab/components/chat.py @@ -45,6 +45,8 @@ def ChatBox( def ChatInput( send_callback: Optional[Callable[[str], None]] = None, disabled: bool = False, + disabled_input: bool = False, + disabled_send: bool = False, style: Optional[Union[str, Dict[str, str]]] = None, autofocus: bool = False, input_text_style: Optional[Union[str, Dict[str, str]]] = None, @@ -57,8 +59,9 @@ def ChatInput( # Arguments * `send_callback`: A callback function for when the user presses enter or clicks the send button taking the message as an argument. - * `disabled`: Whether the input should be disabled. Useful for disabling sending further messages while a chatbot is replying, - among other things. + * `disabled`: disable both input and send. + * `disabled_input`: Whether the input should be disabled. Useful for disabling messages while a chatbot is replying. + * `disabled_send`: Whether the send button should be disabled. Useful for disabling sending further messages while a chatbot is replying. * `style`: CSS styles to apply to the `solara.Row` containing the input field and submit button. Either a string or a dictionary. * `autofocus`: Determines if a component is to be autofocused or not (Default is False). Autofocus will occur during page load and only one component per page can have autofocus active. * `input_text_style`: CSS styles to apply to the `InputText` part of the component. Either a string or a dictionary. @@ -88,13 +91,13 @@ def send(*ignore_args): hide_details=True, autofocus=autofocus, style_="flex-grow: 1;" + input_text_style_flat, - disabled=disabled, + disabled=disabled or disabled_input, class_=" ".join(input_text_classes), ) use_change(message_input, send, update_events=["keyup.enter"]) - button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "") + button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "" or disabled or disabled_send) use_change(button, send, update_events=["click"]) diff --git a/solara/website/pages/documentation/examples/ai/chatbot.py b/solara/website/pages/documentation/examples/ai/chatbot.py index f22a7287f..c09bb33f2 100644 --- a/solara/website/pages/documentation/examples/ai/chatbot.py +++ b/solara/website/pages/documentation/examples/ai/chatbot.py @@ -108,4 +108,6 @@ def Page(): if promt_ai.pending: solara.Text("I'm thinking...", style={"font-size": "1rem", "padding-left": "20px"}) solara.ProgressLinear() - solara.lab.ChatInput(send_callback=promt_ai, disabled=promt_ai.pending) + # if we don't call .key(..) with a unique key, the ChatInput component will be re-created + # and we'll lose what we typed. + solara.lab.ChatInput(send_callback=promt_ai, disabled_send=promt_ai.pending, autofocus=True).key("input")