Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: improve RTL support across UI components (#7206)
白熱6c50c50604e6
diff --git a/packages/design/src/components/segmented/Segmented.tsx b/packages/design/src/components/segmented/Segmented.tsxindex f3fc7693f6..f160a4ba88 100644--- a/packages/design/src/components/segmented/Segmented.tsx+++ b/packages/design/src/components/segmented/Segmented.tsx@@ -15,10 +15,12 @@*/import type { CSSProperties } from 'react';-import { useEffect, useRef, useState } from 'react';+import { useContext, useEffect, useRef, useState } from 'react';import { clsx } from '../../helper/clsx';+import { ConfigContext } from '../config-provider/ConfigProvider';type ItemValue = string | number;+const SEGMENTED_PADDING = 4;interface ISegmentedItem<T extends ItemValue = ItemValue> {label: string;@@ -40,6 +42,7 @@ export function Segmented<T extends ItemValue = ItemValue>({onChange,className = '',}: ISegmentedProps<T>) {+ const { direction } = useContext(ConfigContext);const [selectedItem, setSelectedItem] = useState<T>(value !== undefined ? value : (defaultValue || items[0].value));@@ -62,21 +65,23 @@ export function Segmented<T extends ItemValue = ItemValue>({const containerRect = containerRef.current.getBoundingClientRect();const newRect = newItemElement.getBoundingClientRect();- // Calculate position relative to container's padding- const newLeft = newRect.left - containerRect.left - 4; // Subtract padding-left (p-1 = 4px)+ // Calculate position relative to the fixed physical-left slider origin.+ const newLeft = newRect.left - containerRect.left - SEGMENTED_PADDING;if (oldItemElement) {const oldRect = oldItemElement.getBoundingClientRect();- const oldLeft = oldRect.left - containerRect.left - 4;+ const oldLeft = oldRect.left - containerRect.left - SEGMENTED_PADDING;setSlideStyle({'--slide-from': `${oldLeft}px`,'--slide-to': `${newLeft}px`,+ left: `${SEGMENTED_PADDING}px`,width: `${newRect.width}px`,transform: `translateX(${newLeft}px)`,} as CSSProperties);} else {setSlideStyle({+ left: `${SEGMENTED_PADDING}px`,width: `${newRect.width}px`,transform: `translateX(${newLeft}px)`,} as CSSProperties);@@ -86,7 +91,7 @@ export function Segmented<T extends ItemValue = ItemValue>({useEffect(() => {updateSliderPosition(selectedItem);- }, [selectedItem]);+ }, [direction, selectedItem]);const handleClick = (itemValue: T) => {const oldValue = selectedItem;@@ -98,6 +103,7 @@ export function Segmented<T extends ItemValue = ItemValue>({return (<divdata-u-comp="segmented"+ dir={direction}ref={containerRef}className={clsx(`univer-relative univer-box-border univer-flex univer-min-w-0 univer-gap-1 univer-rounded-lgdiff --git a/packages/design/src/components/segmented/__tests__/index.spec.tsx b/packages/design/src/components/segmented/__tests__/index.spec.tsxindex 0484b3cd20..d8be92563d 100644--- a/packages/design/src/components/segmented/__tests__/index.spec.tsx+++ b/packages/design/src/components/segmented/__tests__/index.spec.tsx@@ -14,8 +14,9 @@* limitations under the License.*/-import { cleanup, render } from '@testing-library/react';+import { cleanup, fireEvent, render } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';+import { ConfigProvider } from '../../config-provider/ConfigProvider';import { Segmented } from '../Segmented';import '@testing-library/jest-dom/vitest';@@ -52,4 +53,56 @@ describe('Segmented', () => {rerender(<Segmented items={items} value="c" />);expect(getByText('C')).toHaveClass('univer-text-gray-900', { exact: false });});++ it('should apply rtl direction from ConfigProvider', () => {+ const { container } = render(+ <ConfigProvider mountContainer={document.body} direction="rtl">+ <Segmented items={items} />+ </ConfigProvider>+ );++ expect(container.querySelector('[data-u-comp="segmented"]')?.getAttribute('dir')).toBe('rtl');+ });++ it('should position the selected slider from a stable physical left origin in rtl', () => {+ const { container, getByText } = render(+ <ConfigProvider mountContainer={document.body} direction="rtl">+ <Segmented items={items} />+ </ConfigProvider>+ );+ const root = container.querySelector('[data-u-comp="segmented"]') as HTMLDivElement;+ const slider = root.firstElementChild as HTMLDivElement;+ const buttonB = getByText('B') as HTMLButtonElement;++ vi.spyOn(root, 'getBoundingClientRect').mockReturnValue({+ x: 100,+ y: 0,+ top: 0,+ left: 100,+ width: 180,+ height: 32,+ right: 280,+ bottom: 32,+ toJSON: () => ({}),+ } as DOMRect);+ vi.spyOn(buttonB, 'getBoundingClientRect').mockReturnValue({+ x: 156,+ y: 4,+ top: 4,+ left: 156,+ width: 48,+ height: 24,+ right: 204,+ bottom: 28,+ toJSON: () => ({}),+ } as DOMRect);++ fireEvent.click(buttonB);++ expect(slider).toHaveStyle({+ left: '4px',+ width: '48px',+ transform: 'translateX(52px)',+ });+ });});diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsxindex b8c88ed332..d9d4bc0abd 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/RuleEdit.tsx@@ -301,9 +301,9 @@ export const RuleEdit = (props: IRuleEditProps) => {rule={props.rule?.rule as any}onChange={onStyleChange}/>- <div className="univer-mt-4 univer-flex univer-justify-end">+ <div className="univer-mt-4 univer-flex univer-justify-end univer-gap-2"><Button onClick={handleCancel}>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.cancel')}</Button>- <Button className="univer-ml-3" variant="primary" onClick={handleSubmit}>+ <Button variant="primary" onClick={handleSubmit}>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.submit')}</Button></div>diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsxindex 659c836a4e..da7cf69e2a 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/DataBar.tsx@@ -37,7 +37,7 @@ import { previewClassName } from './styles';const createOptionItem = (text: CFValueType, localeService: LocaleService) => ({ label: localeService.t<LocaleKey>(`sheets-conditional-formatting-ui.valueType.${text}`), value: text });-const InputText = (props: { disabled?: boolean; id: string; className: string; type: CFValueType; value: string | number; onChange: (v: string | number) => void }) => {+const InputText = (props: { disabled?: boolean; id: string; className?: string; type: CFValueType; value: string | number; onChange: (v: string | number) => void }) => {const { onChange, className, value, type, id, disabled = false } = props;const univerInstanceService = useDependency(IUniverInstanceService);const unitId = univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!.getUnitId();@@ -68,7 +68,7 @@ const InputText = (props: { disabled?: boolean; id: string; className: string; tif (type === CFValueType.formula) {const v = String(_value.current).startsWith('=') ? String(_value.current) || '' : '=';return (- <div className="univer-ml-3 univer-w-full">+ <div className="univer-w-full"><FormulaEditorref={formulaEditorRef}className={clsx(`@@ -294,7 +294,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.fillType')}</div>- <div className="univer-ml-1 univer-mt-3 univer-flex univer-items-center">+ <div className="univer-mt-3 univer-flex univer-items-center univer-gap-3"><RadioGroupvalue={isGradient}onChange={(v) => {@@ -318,7 +318,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {<span className="univer-text-xs">{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.gradient')}</span></Radio></RadioGroup>- <div className="univer-ml-6 univer-flex univer-items-center univer-text-xs">+ <div className="univer-flex univer-items-center univer-text-xs"><Checkboxchecked={!isShowValue}onChange={(v) => {@@ -348,7 +348,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.colorSet')}</div>- <div className="univer-ml-1 univer-mt-3 univer-flex univer-items-center">+ <div className="univer-mt-3 univer-flex univer-items-center univer-gap-2"><div className="univer-flex univer-items-center"><div className="univer-text-xs">{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.native')}@@ -358,7 +358,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {onChange={handleNativeColorChange}/></div>- <div className="univer-ml-3 univer-flex univer-items-center">+ <div className="univer-flex univer-items-center univer-gap-3"><div className="univer-text-xs">{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.panel.positive')}</div>@@ -379,7 +379,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.valueType.min')}</div>- <div className="univer-mt-3 univer-flex univer-items-center">+ <div className="univer-mt-3 univer-flex univer-items-center univer-gap-2"><SelectclassName="univer-w-1/2 univer-flex-shrink-0"options={minOptions}@@ -403,7 +403,6 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {<InputTextid="min"- className="univer-ml-3"disabled={!isShowInput(minValueType)}type={minValueType}value={minValue}@@ -430,7 +429,7 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {>{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.valueType.max')}</div>- <div className="univer-mt-3 univer-flex univer-items-center">+ <div className="univer-mt-3 univer-flex univer-items-center univer-gap-2"><SelectclassName="univer-w-1/2 univer-flex-shrink-0"options={maxOptions}@@ -452,7 +451,6 @@ export const DataBarStyleEditor = (props: IStyleEditorProps) => {}}/><InputText- className="univer-ml-3"disabled={!isShowInput(maxValueType)}id="max"type={maxValueType}diff --git a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsxindex efb7ebed5c..0518999f7a 100644--- a/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx+++ b/packages/sheets-conditional-formatting-ui/src/views/panel/rule-edit/IconSet.tsx@@ -606,12 +606,12 @@ export const IconSet = (props: IStyleEditorProps<unknown, IIconSet>) => {</div></Dropdown></div>- <div className="univer-mt-3 univer-flex univer-items-center univer-text-xs">+ <div className="univer-mt-3 univer-flex univer-items-center univer-gap-3 univer-text-xs"><div className="univer-flex univer-items-center univer-text-xs"><Checkbox onChange={reverseIcon} />{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.iconSet.reverseIconOrder')}</div>- <div className="univer-ml-6 univer-flex univer-items-center univer-text-xs">+ <div className="univer-flex univer-items-center univer-text-xs"><Checkbox checked={!isShowValue} onChange={(v) => { setIsShowValue(!v); }} />{localeService.t<LocaleKey>('sheets-conditional-formatting-ui.iconSet.onlyShowIcon')}</div>diff --git a/packages/sheets-note-ui/src/views/Note.tsx b/packages/sheets-note-ui/src/views/Note.tsxindex 5db2039d89..578fdf7058 100644--- a/packages/sheets-note-ui/src/views/Note.tsx+++ b/packages/sheets-note-ui/src/views/Note.tsx@@ -49,9 +49,21 @@ export const SheetsNote = (props: { popup: IPopup<{ location: INotePopupLocation}const textareaRef = useRef<HTMLTextAreaElement>(null);+ const initialWidthRef = useRef<number | null>(null);const currentRender = renderManagerService.getRenderById(activePopup.unitId)!;const [note, setNote] = useState<Partial<ISheetNote> | null>(null);+ const applyResizeOffset = useCallback((width: number) => {+ const textarea = textareaRef.current;+ if (!textarea) return;++ if (localeService.getDirection() === 'rtl' && initialWidthRef.current != null) {+ const offset = initialWidthRef.current - width;+ textarea.style.transform = offset ? `translateX(${offset}px)` : '';+ } else {+ textarea.style.transform = '';+ }+ }, [localeService]);useEffect(() => {const { unitId, subUnitId, row, col } = activePopup;@@ -73,8 +85,10 @@ export const SheetsNote = (props: { popup: IPopup<{ location: INotePopupLocation}if (textareaRef.current) {+ initialWidthRef.current = width;textareaRef.current.style.width = `${width}px`;textareaRef.current.style.height = `${height}px`;+ textareaRef.current.style.transform = '';}}, [activePopup, textareaRef]);@@ -127,12 +141,13 @@ export const SheetsNote = (props: { popup: IPopup<{ location: INotePopupLocationconst handleResize = useCallback((width: number, height: number) => {if (!note) return;+ applyResizeOffset(width);if (width === note.width && height === note.height) return;const newNote = { ...note, width, height };setNote(newNote);updateNote(newNote);- }, [note]);+ }, [applyResizeOffset, note]);return (<Textareadiff --git a/packages/sheets-note-ui/src/views/__tests__/Note.spec.tsx b/packages/sheets-note-ui/src/views/__tests__/Note.spec.tsxindex 36fee9dd47..8f6062afe1 100644--- a/packages/sheets-note-ui/src/views/__tests__/Note.spec.tsx+++ b/packages/sheets-note-ui/src/views/__tests__/Note.spec.tsx@@ -78,6 +78,12 @@ class TestCellPopupManagerService {}class TestResizeObserver {+ static callback: ResizeObserverCallback | undefined;++ constructor(callback: ResizeObserverCallback) {+ TestResizeObserver.callback = callback;+ }+observe(): void {}unobserve(): void {}@@ -172,6 +178,16 @@ function inputText(textarea: HTMLTextAreaElement, value: string) {textarea.dispatchEvent(new Event('input', { bubbles: true }));}+function resizeTextarea(textarea: HTMLTextAreaElement, width: number, height: number) {+ textarea.style.width = `${width}px`;+ textarea.style.height = `${height}px`;+ TestResizeObserver.callback?.([{+ target: {+ getBoundingClientRect: () => ({ width, height }),+ },+ } as unknown as ResizeObserverEntry], {} as ResizeObserver);+}+async function renderNote(root: Root, testBed: ReturnType<typeof createNoteViewTestBed>, row = 2, col = 3) {await act(async () => {root.render(@@ -256,6 +272,37 @@ describe('SheetsNote', () => {expect(note?.height).toBe(96);});+ it('moves an RTL note left while resizing wider, but reopens at the anchored position with the saved size', async () => {+ const testBed = createMountedNote();+ testBed.injector.get(LocaleService).setDirection('rtl');++ await renderNote(root!, testBed);+ await act(async () => {+ await awaitTime(350);+ });++ let textarea = container!.querySelector('textarea') as HTMLTextAreaElement;++ await act(async () => {+ resizeTextarea(textarea, 220, 96);+ await awaitTime(350);+ });++ expect(textarea.style.transform).toBe('translateX(-40px)');+ expect(testBed.noteModel.getNote(UNIT_ID, SUB_UNIT_ID, { row: 2, col: 3 })?.width).toBe(220);++ act(() => {+ root!.unmount();+ });+ root = createRoot(container!);++ await renderNote(root!, testBed);++ textarea = container!.querySelector('textarea') as HTMLTextAreaElement;+ expect(textarea.style.width).toBe('220px');+ expect(textarea.style.transform).toBe('');+ });+it('closes the popup when creating the initial note cannot be saved', async () => {const testBed = createMountedNote();testBed.commandService.unregisterCommand(UpdateNoteMutation.id);diff --git a/packages/ui/src/controllers/components.controller.ts b/packages/ui/src/controllers/components.controller.tsindex 7263f2da2f..38346011e8 100644--- a/packages/ui/src/controllers/components.controller.ts+++ b/packages/ui/src/controllers/components.controller.ts@@ -23,7 +23,12 @@ import { COLOR_PICKER_COMPONENT } from '../views/color-picker/interface';import { COMMON_LABEL_COMPONENT, CommonLabel } from '../views/CommonLabel';import { ShortcutPanel } from '../views/components/shortcut-panel/ShortcutPanel';import { EMOJI_PICKER_COMPONENT, EmojiPicker } from '../views/emoji-picker/index';-import { FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT, FontFamily, FontFamilyItem } from '../views/font-family/index';+import {+ FONT_FAMILY_COMPONENT,+ FONT_FAMILY_ITEM_COMPONENT,+ FontFamily,+ FontFamilyItem,+} from '../views/font-family/index';import { FontSize } from '../views/font-size/FontSize';import { FONT_SIZE_COMPONENT } from '../views/font-size/interface';import { HEADING_ITEM_COMPONENT, HeadingItem } from '../views/index';diff --git a/packages/ui/src/controllers/menus/__tests__/menus.spec.ts b/packages/ui/src/controllers/menus/__tests__/menus.spec.tsindex 6ad1874099..ea120c476f 100644--- a/packages/ui/src/controllers/menus/__tests__/menus.spec.ts+++ b/packages/ui/src/controllers/menus/__tests__/menus.spec.ts@@ -15,14 +15,16 @@*/import type { IAccessor } from '@univerjs/core';-import { EDITOR_ACTIVATED, FOCUSING_FX_BAR_EDITOR, IContextService, IUndoRedoService } from '@univerjs/core';-import { BehaviorSubject, Subject } from 'rxjs';+import type { Observable } from 'rxjs';+import { EDITOR_ACTIVATED, FOCUSING_FX_BAR_EDITOR, IContextService, IUndoRedoService, LocaleService } from '@univerjs/core';+import { BehaviorSubject, isObservable, Subject } from 'rxjs';import { describe, expect, it } from 'vitest';import { RedoMenuItemFactory, UndoMenuItemFactory } from '../menus';function createAccessor() {const undoRedoStatus$ = new BehaviorSubject({ undos: 1, redos: 1 });const contextChanged$ = new Subject<void>();+ const direction$ = new BehaviorSubject<'ltr' | 'rtl'>('ltr');const contextStore: Record<string, boolean> = {[EDITOR_ACTIVATED]: false,[FOCUSING_FX_BAR_EDITOR]: false,@@ -33,16 +35,18 @@ function createAccessor() {contextChanged$,getContextValue: (key: string) => contextStore[key] ?? false,};+ const localeService = { direction$ };const accessor = {get: (token: unknown) => {if (token === IUndoRedoService) return undoRedoService;if (token === IContextService) return contextService;+ if (token === LocaleService) return localeService;throw new Error('Unknown token');},} as unknown as IAccessor;- return { accessor, undoRedoStatus$, contextChanged$, contextStore };+ return { accessor, undoRedoStatus$, contextChanged$, contextStore, direction$ };}describe('menus controller factories', () => {@@ -94,4 +98,36 @@ describe('menus controller factories', () => {sub.unsubscribe();});++ it('should use rtl-specific undo and redo icons when locale direction changes', () => {+ const { accessor, direction$ } = createAccessor();+ const undoItem = UndoMenuItemFactory(accessor);+ const redoItem = RedoMenuItemFactory(accessor);+ const undoIcon$ = undoItem.icon as Observable<string>;+ const redoIcon$ = redoItem.icon as Observable<string>;+ const undoIcons: string[] = [];+ const redoIcons: string[] = [];++ expect(isObservable(undoItem.icon)).toBe(true);+ expect(isObservable(redoItem.icon)).toBe(true);++ const undoSub = undoIcon$.subscribe((icon) => undoIcons.push(icon));+ const redoSub = redoIcon$.subscribe((icon) => redoIcons.push(icon));++ expect(undoIcons.at(-1)).toBe('UndoIcon');+ expect(redoIcons.at(-1)).toBe('RedoIcon');++ direction$.next('rtl');++ expect(undoIcons.at(-1)).toBe('RedoIcon');+ expect(redoIcons.at(-1)).toBe('UndoIcon');++ direction$.next('ltr');++ expect(undoIcons.at(-1)).toBe('UndoIcon');+ expect(redoIcons.at(-1)).toBe('RedoIcon');++ undoSub.unsubscribe();+ redoSub.unsubscribe();+ });});diff --git a/packages/ui/src/controllers/menus/menus.ts b/packages/ui/src/controllers/menus/menus.tsindex 88f280e0e2..2632fcb19e 100644--- a/packages/ui/src/controllers/menus/menus.ts+++ b/packages/ui/src/controllers/menus/menus.ts@@ -22,6 +22,7 @@ import {FOCUSING_FX_BAR_EDITOR,IContextService,IUndoRedoService,+ LocaleService,RedoCommand,UndoCommand,} from '@univerjs/core';@@ -41,11 +42,17 @@ const undoRedoDisableFactory$ = (accessor: IAccessor, isUndo: boolean) => {}));};+const rtlIconFactory$ = (accessor: IAccessor, ltrIcon: string, rtlIcon: string) => {+ const localeService = accessor.get(LocaleService);++ return localeService.direction$.pipe(map((direction) => direction === 'rtl' ? rtlIcon : ltrIcon));+};+export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey> {return {id: UndoCommand.id,type: MenuItemType.BUTTON,- icon: 'UndoIcon',+ icon: rtlIconFactory$(accessor, 'UndoIcon', 'RedoIcon'),title: 'ui.shortcut.undo',tooltip: 'ui.shortcut.undo',disabled$: undoRedoDisableFactory$(accessor, true),@@ -56,7 +63,7 @@ export function RedoMenuItemFactory(accessor: IAccessor): IMenuButtonItem<Localereturn {id: RedoCommand.id,type: MenuItemType.BUTTON,- icon: 'RedoIcon',+ icon: rtlIconFactory$(accessor, 'RedoIcon', 'UndoIcon'),title: 'ui.shortcut.redo',tooltip: 'ui.shortcut.redo',disabled$: undoRedoDisableFactory$(accessor, false),diff --git a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsxindex d502a6d2ac..81a61c2a0b 100644--- a/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx+++ b/packages/ui/src/views/components/context-menu/ContextMenuPanel.tsx@@ -26,7 +26,7 @@ import type {import type { IMenuSchema } from '../../../services/menu/menu-manager.service';import { isRealNum, LocaleService } from '@univerjs/core';import { borderBottomClassName, borderClassName, clsx, cva, scrollbarClassName } from '@univerjs/design';-import { CheckMarkIcon, MoreRightIcon } from '@univerjs/icons';+import { CheckMarkIcon, MoreLeftIcon, MoreRightIcon } from '@univerjs/icons';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { createPortal } from 'react-dom';import { combineLatest, isObservable, of, scan, startWith } from 'rxjs';@@ -1255,6 +1255,7 @@ function ContextMenuMenuItem(props: IContextMenuMenuItemProps) {const canExecuteItem = menuItem.type === MenuItemType.BUTTON || menuItem.type === MenuItemType.BUTTON_SELECTOR;const renderAsContainer = isNonSelectableLabel(menuItem.label);+ const SubmenuAffordanceIcon = direction === 'rtl' ? MoreLeftIcon : MoreRightIcon;const interactiveItemClassName = clsx(itemClassName, isNonHoverableLabel(menuItem.label) && `hover:univer-bg-transparentdark:hover:!univer-bg-transparent@@ -1298,7 +1299,7 @@ function ContextMenuMenuItem(props: IContextMenuMenuItemProps) {>{contentNode}{hasSubmenu && (- <MoreRightIcon+ <SubmenuAffordanceIconclassName={`${sizeVariant === 'paragraph-t' ? 'univer-size-4' : 'univer-size-3.5'}univer-text-gray-400@@ -1356,7 +1357,7 @@ function ContextMenuMenuItem(props: IContextMenuMenuItemProps) {>{contentNode}{hasSubmenu && !compact && (- <MoreRightIcon+ <SubmenuAffordanceIconclassName={`${sizeVariant === 'paragraph-t' ? 'univer-size-4' : 'univer-size-3.5'}univer-text-gray-400diff --git a/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx b/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsxindex 94551d9426..d3712fdf43 100644--- a/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx+++ b/packages/ui/src/views/components/context-menu/__tests__/ContextMenuPanel.spec.tsx@@ -36,6 +36,17 @@ import {shouldShowContextMenuGroupSeparator,} from '../ContextMenuPanel';+vi.mock('@univerjs/icons', async (importOriginal) => {+ const actual = await importOriginal<typeof import('@univerjs/icons')>();++ return {+ ...actual,+ CheckMarkIcon: ({ className }: { className?: string }) => <span className={className} data-icon="check-mark" />,+ MoreLeftIcon: ({ className }: { className?: string }) => <span className={className} data-icon="more-left" />,+ MoreRightIcon: ({ className }: { className?: string }) => <span className={className} data-icon="more-right" />,+ };+});+(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;class TestMenuManagerService {@@ -538,6 +549,40 @@ describe('ContextMenuPanel', () => {expect(submenu.style.paddingLeft).toBe('0px');});+ it('renders the submenu affordance toward the opening side in rtl', () => {+ renderWithDependencies(+ <ContextMenuPanel menuType="submenu-root" />,+ {+ 'submenu-root': [+ {+ key: 'insert',+ order: 0,+ item: {+ id: 'insert',+ type: MenuItemType.SUBITEMS,+ title: 'docs-ui.insert',+ tooltip: 'docs-ui.insert',+ },+ },+ ],+ insert: [+ createButtonItem('insert-row', {+ title: 'docs-ui.insertRow',+ tooltip: 'docs-ui.insertRow',+ }),+ ],+ },+ (injector) => {+ (injector.get(LocaleService) as unknown as TestLocaleService).direction$.next('rtl');+ }+ );++ const insertButton = screen.getByRole('button', { name: 'translated:docs-ui.insert' });++ expect(insertButton.querySelector('[data-icon="more-left"]')).not.toBeNull();+ expect(insertButton.querySelector('[data-icon="more-right"]')).toBeNull();+ });+it('keeps row navigation on the same visual row until the row boundary', () => {const createButton = (left: number, top: number) => ({getBoundingClientRect: () => ({