Skip to content

Commit 1880bf4

Browse files
feat: separate disabled_send and disabled_input so we can type while the AI replies
1 parent 7302527 commit 1880bf4

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

solara/lab/components/chat.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def ChatBox(
4545
def ChatInput(
4646
send_callback: Optional[Callable[[str], None]] = None,
4747
disabled: bool = False,
48+
disabled_input: bool = False,
49+
disabled_send: bool = False,
4850
style: Optional[Union[str, Dict[str, str]]] = None,
4951
autofocus: bool = False,
5052
input_text_style: Optional[Union[str, Dict[str, str]]] = None,
@@ -57,8 +59,9 @@ def ChatInput(
5759
# Arguments
5860
5961
* `send_callback`: A callback function for when the user presses enter or clicks the send button taking the message as an argument.
60-
* `disabled`: Whether the input should be disabled. Useful for disabling sending further messages while a chatbot is replying,
61-
among other things.
62+
* `disabled`: disable both input and send.
63+
* `disabled_input`: Whether the input should be disabled. Useful for disabling messages while a chatbot is replying.
64+
* `disabled_send`: Whether the send button should be disabled. Useful for disabling sending further messages while a chatbot is replying.
6265
* `style`: CSS styles to apply to the `solara.Row` containing the input field and submit button. Either a string or a dictionary.
6366
* `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.
6467
* `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):
8891
hide_details=True,
8992
autofocus=autofocus,
9093
style_="flex-grow: 1;" + input_text_style_flat,
91-
disabled=disabled,
94+
disabled=disabled or disabled_input,
9295
class_=" ".join(input_text_classes),
9396
)
9497

9598
use_change(message_input, send, update_events=["keyup.enter"])
9699

97-
button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "")
100+
button = solara.v.Btn(color="primary", icon=True, children=[solara.v.Icon(children=["mdi-send"])], disabled=message == "" or disabled or disabled_send)
98101

99102
use_change(button, send, update_events=["click"])
100103

solara/website/pages/documentation/examples/ai/chatbot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,6 @@ def Page():
108108
if promt_ai.pending:
109109
solara.Text("I'm thinking...", style={"font-size": "1rem", "padding-left": "20px"})
110110
solara.ProgressLinear()
111-
solara.lab.ChatInput(send_callback=promt_ai, disabled=promt_ai.pending)
111+
# if we don't call .key(..) with a unique key, the ChatInput component will be re-created
112+
# and we'll lose what we typed.
113+
solara.lab.ChatInput(send_callback=promt_ai, disabled_send=promt_ai.pending, autofocus=True).key("input")

0 commit comments

Comments
 (0)