Add disabled state to Send/Queue buttons for visual feedback
EnhancedInput now exposes canSubmit state via onCanSubmitChange callback, allowing parent components to show proper disabled styling when input is empty or only has a locked agent without content. This fixes the issue where buttons remained visually enabled even when clicking would have no effect.
This commit is contained in:
@@ -1785,6 +1785,7 @@ export default function ControlClient() {
|
||||
const itemsRef = useRef<ChatItem[]>([]);
|
||||
const [draftInput, setDraftInput] = useLocalStorage("control-draft", "");
|
||||
const [input, setInput] = useState(draftInput);
|
||||
const [canSubmitInput, setCanSubmitInput] = useState(false);
|
||||
const [lastMissionId, setLastMissionId] = useLocalStorage<string | null>(
|
||||
"control-last-mission-id",
|
||||
null
|
||||
@@ -5260,6 +5261,7 @@ export default function ControlClient() {
|
||||
value={input}
|
||||
onChange={setInput}
|
||||
onSubmit={handleEnhancedSubmit}
|
||||
onCanSubmitChange={setCanSubmitInput}
|
||||
placeholder="Message the root agent… (paste files to upload)"
|
||||
/>
|
||||
|
||||
@@ -5268,7 +5270,8 @@ export default function ControlClient() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => enhancedInputRef.current?.submit()}
|
||||
className="flex items-center gap-2 rounded-xl bg-indigo-500/80 hover:bg-indigo-600 px-5 py-3 text-sm font-medium text-white transition-colors shrink-0"
|
||||
disabled={!canSubmitInput}
|
||||
className="flex items-center gap-2 rounded-xl bg-indigo-500/80 hover:bg-indigo-600 px-5 py-3 text-sm font-medium text-white transition-colors shrink-0 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-indigo-500/80"
|
||||
>
|
||||
<ListPlus className="h-4 w-4" />
|
||||
Queue
|
||||
@@ -5286,7 +5289,8 @@ export default function ControlClient() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => enhancedInputRef.current?.submit()}
|
||||
className="flex items-center gap-2 rounded-xl bg-indigo-500 hover:bg-indigo-600 px-5 py-3 text-sm font-medium text-white transition-colors shrink-0"
|
||||
disabled={!canSubmitInput}
|
||||
className="flex items-center gap-2 rounded-xl bg-indigo-500 hover:bg-indigo-600 px-5 py-3 text-sm font-medium text-white transition-colors shrink-0 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-indigo-500"
|
||||
>
|
||||
<Send className="h-4 w-4" />
|
||||
Send
|
||||
|
||||
@@ -20,12 +20,14 @@ export interface SubmitPayload {
|
||||
|
||||
export interface EnhancedInputHandle {
|
||||
submit: () => void;
|
||||
canSubmit: () => boolean;
|
||||
}
|
||||
|
||||
interface EnhancedInputProps {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
onSubmit: (payload: SubmitPayload) => void;
|
||||
onCanSubmitChange?: (canSubmit: boolean) => void;
|
||||
placeholder?: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
@@ -42,6 +44,7 @@ export const EnhancedInput = forwardRef<EnhancedInputHandle, EnhancedInputProps>
|
||||
value,
|
||||
onChange,
|
||||
onSubmit,
|
||||
onCanSubmitChange,
|
||||
placeholder = "Message the root agent...",
|
||||
disabled = false,
|
||||
className,
|
||||
@@ -307,10 +310,23 @@ export const EnhancedInput = forwardRef<EnhancedInputHandle, EnhancedInputProps>
|
||||
onChange('');
|
||||
}, [displayValue, lockedAgent, disabled, onSubmit, parsedAgentFromValue, value, onChange]);
|
||||
|
||||
// Check if submission is valid (has content or locked agent)
|
||||
const canSubmit = useCallback(() => {
|
||||
if (disabled) return false;
|
||||
const trimmedValue = displayValue.trim();
|
||||
return !!(trimmedValue || lockedAgent);
|
||||
}, [disabled, displayValue, lockedAgent]);
|
||||
|
||||
// Notify parent when submission validity changes
|
||||
useEffect(() => {
|
||||
onCanSubmitChange?.(canSubmit());
|
||||
}, [canSubmit, onCanSubmitChange]);
|
||||
|
||||
// Expose submit method via ref so parent can trigger submit (e.g., from Send button)
|
||||
useImperativeHandle(ref, () => ({
|
||||
submit: handleSubmit,
|
||||
}), [handleSubmit]);
|
||||
canSubmit,
|
||||
}), [handleSubmit, canSubmit]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
const newValue = e.target.value;
|
||||
|
||||
Reference in New Issue
Block a user