Skip to content

Return focus to input field after sending message via chat portal #451

@HammerHeston

Description

@HammerHeston

Bug: Webchat input loses focus after sending a message

Description

After sending a message in the webchat interface, the cursor/focus does not automatically return to the input field. The user must manually click/tap the input to continue typing.

Expected Behavior

After sending a message, focus should return to the text input field so the user can immediately type their next message without additional interaction.

Actual Behavior

  • User types a message and presses Enter (or clicks Send)
  • Message is sent successfully
  • Focus remains on the page body or shifts elsewhere
  • User must click/tap the input field again to continue typing

Environment

  • Spacebot version: 0.3.3
  • Browser: Chrome 45.0.7632.119
  • OS: Windows 11
  • Device: Desktop

Steps to Reproduce

  1. Navigate to an agent's chat page (e.g., /agents/main/chat)
  2. Click/focus the message input field
  3. Type a message
  4. Press Enter or click the Send button
  5. Observe that the input field is no longer focused

Proposed Fix

After the message is sent (and the input is cleared), call inputRef.focus() to restore focus to the textarea/input element. This is a common pattern in chat UIs.

const handleSend = async () => {
  if (!message.trim()) return;
  await sendMessage(message);
  setMessage('');
  inputRef.current?.focus();
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions