Skip to content

Commit

Permalink
Merge branch 'main' into cnwankwo/CallFeatureStream
Browse files Browse the repository at this point in the history
  • Loading branch information
cn0151 authored Oct 25, 2024
2 parents 0280dd8 + 06854ad commit 92f7122
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "",
"comment": "Resolve issue where rich text editor tool bar would not focus when shown. Also fixed issue where editor component would remount when showing/hiding toolbar.",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "patch",
"area": "fix",
"workstream": "",
"comment": "Resolve issue where rich text editor tool bar would not focus when shown. Also fixed issue where editor component would remount when showing/hiding toolbar.",
"packageName": "@azure/communication-react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4433,6 +4433,7 @@ export interface RichTextStrings {
richTextNewNumberedListItemAnnouncement: string;
richTextNumberedListAppliedAnnouncement: string;
richTextNumberListTooltip: string;
richTextToolbarAriaLabel: string;
richTextToolbarMoreButtonAriaLabel: string;
richTextUnderlineTooltip: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const RichTextEditor = React.forwardRef<RichTextEditorComponentRef, RichT
} = props;
const editor = useRef<IEditor | null>(null);
const editorDiv = useRef<HTMLDivElement>(null);
const toolbarRef = useRef<HTMLDivElement>(null);
const theme = useTheme();
const [contextMenuProps, setContextMenuProps] = useState<IContextualMenuProps | null>(null);
const previousThemeDirection = useRef(themeDirection(theme));
Expand All @@ -149,6 +150,16 @@ export const RichTextEditor = React.forwardRef<RichTextEditorComponentRef, RichT
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (editor.current) {
if (showRichTextEditorFormatting) {
toolbarRef.current?.focus();
} else {
editor.current?.focus();
}
}
}, [showRichTextEditorFormatting]);

useImperativeHandle(ref, () => {
return {
focus() {
Expand Down Expand Up @@ -460,7 +471,7 @@ export const RichTextEditor = React.forwardRef<RichTextEditorComponentRef, RichT

return (
<div data-testid={'rich-text-editor-wrapper'}>
{showRichTextEditorFormatting && toolbar}
<div ref={toolbarRef}>{showRichTextEditorFormatting && toolbar}</div>
<div className={richTextEditorWrapperStyle(theme)}>
{/* div that is used by Rooster JS as a parent of the editor */}
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React, { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
import React, { ReactNode, useCallback, useMemo, useState } from 'react';
import { BaseCustomStyles } from '../../types';
import { RichTextEditor, RichTextEditorComponentRef, RichTextEditorStyleProps } from './RichTextEditor';
import { RichTextSendBoxStrings } from './RichTextSendBox';
Expand Down Expand Up @@ -105,15 +105,6 @@ export const RichTextInputBoxComponent = (props: RichTextInputBoxComponentProps)
[disabled, showRichTextEditorFormatting, theme]
);

useEffect(() => {
if (showRichTextEditorFormatting !== undefined) {
// Focus the editor when toolbar shown/hidden
editorComponentRef.current?.focus();
}
// we don't need execute this useEffect if editorComponentRef is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [showRichTextEditorFormatting]);

const actionButtons = useMemo(() => {
return (
<Stack.Item align="end" className={richTextActionButtonsStackStyle}>
Expand Down Expand Up @@ -189,12 +180,16 @@ export const RichTextInputBoxComponent = (props: RichTextInputBoxComponentProps)
})}
>
{/* This layout is used for the compact view when formatting options are not shown */}
<Stack
grow
horizontal={useHorizontalLayout}
horizontalAlign={useHorizontalLayout ? 'end' : 'space-between'}
{/* We don't use a stack here as there is a bug in Fluent Stack that causes remount of children when using wrap */}
<div
className={inputBoxContentStackStyle}
wrap={useHorizontalLayout}
style={{
display: 'flex',
flexGrow: 1,
flexDirection: useHorizontalLayout ? 'row' : 'column',
justifyContent: useHorizontalLayout ? 'flex-end' : 'space-between',
flexWrap: useHorizontalLayout ? 'wrap' : 'nowrap'
}}
>
{/* Fixes the issue when flex box can grow to be bigger than parent */}
<Stack grow className={inputBoxRichTextStackStyle}>
Expand All @@ -220,7 +215,7 @@ export const RichTextInputBoxComponent = (props: RichTextInputBoxComponentProps)
{/* @conditional-compile-remove(file-sharing-acs) */ onRenderAttachmentUploads && onRenderAttachmentUploads()}
</Stack>
{actionButtons}
</Stack>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export interface RichTextStrings {
* Text for the delete table menu.
*/
richTextDeleteTableMenu: string;
/**
* Text for the rich text toolbar.
*/
richTextToolbarAriaLabel: string;
/**
* Text for the rich text toolbar more button.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export const RichTextToolbar = (props: RichTextToolbarProps): JSX.Element => {
data-testid={'rich-text-editor-toolbar'}
styles={richTextToolbarStyle}
overflowButtonProps={overflowButtonProps}
aria-label={strings.richTextToolbarAriaLabel}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"richTextDeleteColumnMenu": "Delete column",
"richTextDeleteRowMenu": "Delete row",
"richTextDeleteTableMenu": "Delete table",
"richTextToolbarAriaLabel": "Message Formatting Toolbar",
"richTextToolbarMoreButtonAriaLabel": "More options",
"attachmentMoreMenu": "More Options",
"richTextNewBulletedListItemAnnouncement": "Bullet, new line",
Expand Down

0 comments on commit 92f7122

Please sign in to comment.