Skip to content

Commit c462a0f

Browse files
committed
implemented input validation on the sidebar and added styles for disabled state
1 parent aee0ce0 commit c462a0f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/components/side-panel/SidePanel.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ export default function SidePanel() {
6464
};
6565
}, [client, log]);
6666

67+
// Helper function to check if input is valid (not empty and not just whitespace)
68+
const isValidInput = (input: string): boolean => {
69+
return input.trim().length > 0;
70+
};
71+
6772
const handleSubmit = () => {
68-
client.send([{ text: textInput }]);
73+
// Only send if the input is valid
74+
if (isValidInput(textInput)) {
75+
client.send([{ text: textInput }]);
6976

70-
setTextInput("");
71-
if (inputRef.current) {
72-
inputRef.current.innerText = "";
77+
setTextInput("");
78+
if (inputRef.current) {
79+
inputRef.current.innerText = "";
80+
}
7381
}
7482
};
7583

@@ -135,7 +143,10 @@ export default function SidePanel() {
135143
if (e.key === "Enter" && !e.shiftKey) {
136144
e.preventDefault();
137145
e.stopPropagation();
138-
handleSubmit();
146+
// Only submit if input is valid
147+
if (isValidInput(textInput)) {
148+
handleSubmit();
149+
}
139150
}
140151
}}
141152
onChange={(e) => setTextInput(e.target.value)}
@@ -152,6 +163,7 @@ export default function SidePanel() {
152163
<button
153164
className="send-button material-symbols-outlined filled"
154165
onClick={handleSubmit}
166+
disabled={!isValidInput(textInput) || !connected}
155167
>
156168
send
157169
</button>

src/components/side-panel/side-panel.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@
166166
&:hover {
167167
color: var(--Neutral-60);
168168
}
169+
170+
&:disabled {
171+
color: var(--Neutral-15);
172+
cursor: not-allowed;
173+
opacity: 0.6;
174+
}
169175
}
170176

171177
.input-area {

0 commit comments

Comments
 (0)