Skip to content

add focusSendBoxInput method#5512

Closed
marclundgren wants to merge 13 commits intomicrosoft:mainfrom
marclundgren:input-focus-ref-2
Closed

add focusSendBoxInput method#5512
marclundgren wants to merge 13 commits intomicrosoft:mainfrom
marclundgren:input-focus-ref-2

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)

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
### 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.

Marc Lundgren added 2 commits August 20, 2025 15:54
@marclundgren marclundgren force-pushed the input-focus-ref-2 branch 2 times, most recently from 0784b4b to 5085a30 Compare August 21, 2025 19:56
Marc Lundgren and others added 2 commits August 24, 2025 14:05
- Add proper type parameters to generic types (Promise<void>, Readonly<{...}>)
- Remove unused imports (DecoratorMiddleware, HTMLContentTransformMiddleware, ContextOf)
- Define proper prop types for ComposerCoreUIProps and ComposerCoreProps

This fixes the build errors preventing declaration file generation in CI.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add decoratorMiddleware and htmlContentTransformMiddleware to ComposerProps type
- Import required DecoratorMiddleware and HTMLContentTransformMiddleware types
- Add PropTypes validation for new middleware properties

This fixes the remaining TypeScript compilation errors in CI:
- Property 'decoratorMiddleware' does not exist on type 'PropsWithChildren<ComposerProps>'
- Property 'htmlContentTransformMiddleware' does not exist on type 'PropsWithChildren<ComposerProps>'
- PropTypes validation mismatch errors

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Marc Lundgren and others added 2 commits August 24, 2025 16:16
Replace spread operator with explicit PropTypes definitions to avoid
type conflicts between APIComposer.propTypes and ComposerCore.propTypes.

This fixes CI error: "The types of 'suggestedActionsAccessKey[nominalTypeHack].type'
are incompatible between these types" by explicitly defining PropTypes instead
of using spread which was causing TypeScript validation conflicts.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The connectToWebChat function was removed in commit 73ee44a as part of
the ESM build refactoring, but the bundle package still referenced it,
causing TypeScript compilation errors. This removes the obsolete import
references from the bundle package and fixes the addVersion import path.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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