Skip to content

Commit ded48cf

Browse files
[Chat] Add autoFocus API to RichTextSendBox (#4435)
* Add autoFocus API to RichTextSendBox * Update api view * Change files
1 parent e9f6662 commit ded48cf

5 files changed

Lines changed: 25 additions & 2 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "none",
3+
"area": "improvement",
4+
"workstream": "RTE",
5+
"comment": "Add autoFocus API to RichTextSendBox",
6+
"packageName": "@azure/communication-react",
7+
"email": "107075081+Leah-Xia-Microsoft@users.noreply.github.com",
8+
"dependentChangeType": "none"
9+
}

packages/communication-react/review/beta/communication-react.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3883,6 +3883,7 @@ export const RichTextSendBox: (props: RichTextSendBoxProps) => JSX.Element;
38833883
// @beta
38843884
export interface RichTextSendBoxProps {
38853885
activeAttachmentUploads?: AttachmentMetadata[];
3886+
autoFocus?: 'sendBoxTextField';
38863887
disabled?: boolean;
38873888
onCancelAttachmentUpload?: (attachmentId: string) => void;
38883889
onSendMessage: (content: string) => Promise<void>;

packages/react-components/src/components/RichTextEditor/RichTextEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface RichTextEditorProps {
5353
strings: Partial<RichTextSendBoxStrings>;
5454
showRichTextEditorFormatting: boolean;
5555
styles: RichTextEditorStyleProps;
56+
autoFocus?: 'sendBoxTextField';
5657
}
5758

5859
/**
@@ -71,7 +72,8 @@ export interface RichTextEditorComponentRef {
7172
* @beta
7273
*/
7374
export const RichTextEditor = React.forwardRef<RichTextEditorComponentRef, RichTextEditorProps>((props, ref) => {
74-
const { initialContent, onChange, placeholderText, strings, showRichTextEditorFormatting, content } = props;
75+
const { initialContent, onChange, placeholderText, strings, showRichTextEditorFormatting, content, autoFocus } =
76+
props;
7577
const editor = useRef<IEditor | null>(null);
7678
const contentValue = useRef<string | undefined>(content);
7779
const theme = useTheme();
@@ -202,6 +204,7 @@ export const RichTextEditor = React.forwardRef<RichTextEditorComponentRef, RichT
202204
data-testid={'rooster-rich-text-editor'}
203205
// if we don't use 'allowKeyboardEventPropagation' only the enter key is caught
204206
onKeyDown={props.onKeyDown}
207+
focusOnInit={autoFocus === 'sendBoxTextField'}
205208
/>
206209
</div>
207210
</div>

packages/react-components/src/components/RichTextEditor/RichTextInputBoxComponent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface RichTextInputBoxComponentProps {
5050
// otherwise the editor will grow to fit the content
5151
richTextEditorStyleProps: (isExpanded: boolean) => RichTextEditorStyleProps;
5252
isHorizontalLayoutDisabled?: boolean;
53+
autoFocus?: 'sendBoxTextField';
5354
}
5455

5556
/**
@@ -71,7 +72,8 @@ export const RichTextInputBoxComponent = (props: RichTextInputBoxComponentProps)
7172
hasAttachments,
7273
richTextEditorStyleProps,
7374
isHorizontalLayoutDisabled = false,
74-
content
75+
content,
76+
autoFocus
7577
} = props;
7678
const theme = useTheme();
7779
const [showRichTextEditorFormatting, setShowRichTextEditorFormatting] = useState(false);
@@ -175,6 +177,7 @@ export const RichTextInputBoxComponent = (props: RichTextInputBoxComponentProps)
175177
strings={strings}
176178
showRichTextEditorFormatting={showRichTextEditorFormatting}
177179
styles={richTextEditorStyle}
180+
autoFocus={autoFocus}
178181
/>
179182
</Stack.Item>
180183
{

packages/react-components/src/components/RichTextEditor/RichTextSendBox.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ export interface RichTextSendBoxProps {
136136
* @beta
137137
*/
138138
activeAttachmentUploads?: AttachmentMetadata[];
139+
/**
140+
* enumerable to determine if the input box has focus on render or not.
141+
* When undefined nothing has focus on render
142+
*/
143+
autoFocus?: 'sendBoxTextField';
139144
/* @conditional-compile-remove(attachment-upload) */
140145
/**
141146
* Optional callback to remove the attachment upload before sending by clicking on
@@ -158,6 +163,7 @@ export const RichTextSendBox = (props: RichTextSendBoxProps): JSX.Element => {
158163
const {
159164
disabled = false,
160165
systemMessage,
166+
autoFocus,
161167
onSendMessage,
162168
/* @conditional-compile-remove(attachment-upload) */
163169
activeAttachmentUploads,
@@ -348,6 +354,7 @@ export const RichTextSendBox = (props: RichTextSendBoxProps): JSX.Element => {
348354
// setting the content will ensure that the latest content is used when editor is re-rendered
349355
content={contentValue}
350356
placeholderText={strings.placeholderText}
357+
autoFocus={autoFocus}
351358
onChange={setContent}
352359
onEnterKeyDown={sendMessageOnClick}
353360
editorComponentRef={editorComponentRef}

0 commit comments

Comments
 (0)