Skip to content

add focusSendBoxInput method #5512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

marclundgren
Copy link
Contributor

@marclundgren marclundgren commented Jul 9, 2025

Add ref-based focus control to Composer component to enable focus send box

Summary

This PR adds a ref prop to the Composer component that exposes a focusSendBoxInput() method, allowing parent components to programmatically focus the chat input field.

Changes

  • Added ComposerRef type with focusSendBoxInput() method
  • Converted Composer component to use forwardRef
  • Created internal ComposerWithRef component that uses the existing useFocus hook
  • Updated FullComposer to forward refs properly
  • Exported ComposerRef type from all package entry points

Usage Example

import React, { useRef } from 'react';
import { Composer, ComposerRef } from 'botframework-webchat';

const MyApp: React.FC = () => {
  const webChatRef = useRef<ComposerRef>(null);
  const focusChatInput = () => {
    webChatRef.current?.focusSendBoxInput();
  };

  return (
    <div>
      <button onClick={focusChatInput}>Focus Chat Input</button>
      <Composer
        ref={webChatRef}
        directLine={yourDirectLine}
        // ... other props
      />
    </div>
  );
};
  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

Marc Lundgren added 3 commits July 22, 2025 10:29
Copy link
Contributor

@beyackle2 beyackle2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally I'd approve this, but I know William is very specific about the format of the changelog; fix that and I'll re-approve.

CHANGELOG.md Outdated
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- Resolves [#5081](https://github.com/microsoft/BotFramework-WebChat/issues/5081). Added `uploadAccept` and `uploadMultiple` style options, by [@ms-jb](https://github.com/ms-jb)
- Added `ComposerRef` type and ref-based focus control to `Composer` component, enabling programmatic focus of the send box input via `focusSendBoxInput()` method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow one of the changelog line templates above (e.g. link to an issue or your GH page)

@marclundgren
Copy link
Contributor Author

Hi @beyackle2! 👋

I've updated the CHANGELOG.md entry to follow the proper format. The entry now includes:

  • Author attribution: by [@marclundgren](https://github.com/marclundgren)
  • PR reference: in PR [#5512](https://github.com/microsoft/BotFramework-WebChat/pull/5512)

The updated entry matches the format used by other entries in the changelog. The change has been committed and pushed.

Thanks for the feedback! 🙏

@OEvgeny
Copy link
Collaborator

OEvgeny commented Aug 4, 2025

How about moving composer upper in the tree and utilizing existing useFocus() hook?

The use-case seems can be solved in userland without the proposed modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants