Skip to content

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.

fix: tidy up locale-sensitive UI behavior (#7209)

白熱b7d5bbc80913
diff --git a/packages/core/src/shared/__tests__/date-kit.spec.ts b/packages/core/src/shared/__tests__/date-kit.spec.ts
index a9fc0d23fe..5c75b3b914 100644
--- a/packages/core/src/shared/__tests__/date-kit.spec.ts
+++ b/packages/core/src/shared/__tests__/date-kit.spec.ts
@@ -56,4 +56,21 @@ describe('date-kit', () => {
expect(dateKit.unix(1704067200).valueOf()).toBe(1704067200000);
expect(dateKit.isDateKit(dateKit())).toBe(true);
});
+
+ it('should format dates with Intl locale options', () => {
+ const value = dateKit('2024-01-02 03:04:05');
+
+ expect(value.formatIntl('ar-SA-u-nu-arab', {
+ hour: '2-digit',
+ minute: '2-digit',
+ second: '2-digit',
+ hour12: false,
+ })).toMatch(/[٠-٩]/);
+ expect(value.formatIntl('fa-IR-u-nu-arabext', {
+ hour: '2-digit',
+ minute: '2-digit',
+ second: '2-digit',
+ hour12: false,
+ })).toMatch(/[۰-۹]/);
+ });
});
diff --git a/packages/core/src/shared/date-kit.ts b/packages/core/src/shared/date-kit.ts
index bbf1eecb40..15fa133dcb 100644
--- a/packages/core/src/shared/date-kit.ts
+++ b/packages/core/src/shared/date-kit.ts
@@ -100,6 +100,7 @@ interface IDateParts {
export interface IDateKit {
isValid(): boolean;
format(template?: string): string;
+ formatIntl(locale?: string | string[], options?: Intl.DateTimeFormatOptions): string;
valueOf(): number;
toDate(): Date;
add(value: number, unit?: DateKitUnitType): IDateKit;
@@ -131,6 +132,21 @@ class DateKitImpl implements IDateKit {
return formatDate(this._date, template, this._isUTC);
}
+ formatIntl(locale?: string | string[], options: Intl.DateTimeFormatOptions = {}) {
+ if (!this.isValid()) {
+ return 'Invalid Date';
+ }
+ if (typeof Intl === 'undefined' || typeof Intl.DateTimeFormat !== 'function') {
+ return this.format();
+ }
+
+ const formatOptions = this._isUTC && !options.timeZone
+ ? { ...options, timeZone: 'UTC' }
+ : options;
+
+ return new Intl.DateTimeFormat(locale, formatOptions).format(this._date);
+ }
+
valueOf() {
return this._date.getTime();
}
diff --git a/packages/core/src/types/enum/locale-type.ts b/packages/core/src/types/enum/locale-type.ts
index 6052ef55c8..c278c954a0 100644
--- a/packages/core/src/types/enum/locale-type.ts
+++ b/packages/core/src/types/enum/locale-type.ts
@@ -38,3 +38,112 @@ export enum LocaleType {
PL_PL = 'plPL',
AR_SA = 'arSA',
}
+
+type LocaleDirection = 'ltr' | 'rtl';
+
+interface ILocaleMeta {
+ name: string;
+ tag: string;
+ direction: LocaleDirection;
+ numberingSystem?: string;
+}
+
+export const LOCALE_META: Record<LocaleType, ILocaleMeta> = {
+ [LocaleType.EN_US]: {
+ name: 'English',
+ tag: 'en-US',
+ direction: 'ltr',
+ },
+ [LocaleType.FR_FR]: {
+ name: 'Français',
+ tag: 'fr-FR',
+ direction: 'ltr',
+ },
+ [LocaleType.ZH_CN]: {
+ name: '简体中文',
+ tag: 'zh-CN',
+ direction: 'ltr',
+ },
+ [LocaleType.RU_RU]: {
+ name: 'Русский',
+ tag: 'ru-RU',
+ direction: 'ltr',
+ },
+ [LocaleType.ZH_TW]: {
+ name: '繁體中文',
+ tag: 'zh-TW',
+ direction: 'ltr',
+ },
+ [LocaleType.ZH_HK]: {
+ name: '繁體中文(香港)',
+ tag: 'zh-HK',
+ direction: 'ltr',
+ },
+ [LocaleType.VI_VN]: {
+ name: 'Tiếng Việt',
+ tag: 'vi-VN',
+ direction: 'ltr',
+ },
+ [LocaleType.FA_IR]: {
+ name: 'فارسی',
+ tag: 'fa-IR',
+ direction: 'rtl',
+ numberingSystem: 'arabext',
+ },
+ [LocaleType.JA_JP]: {
+ name: '日本語',
+ tag: 'ja-JP',
+ direction: 'ltr',
+ },
+ [LocaleType.KO_KR]: {
+ name: '한국어',
+ tag: 'ko-KR',
+ direction: 'ltr',
+ },
+ [LocaleType.ES_ES]: {
+ name: 'Español',
+ tag: 'es-ES',
+ direction: 'ltr',
+ },
+ [LocaleType.CA_ES]: {
+ name: 'Català',
+ tag: 'ca-ES',
+ direction: 'ltr',
+ },
+ [LocaleType.SK_SK]: {
+ name: 'Slovenčina',
+ tag: 'sk-SK',
+ direction: 'ltr',
+ },
+ [LocaleType.PT_BR]: {
+ name: 'Português (Brasil)',
+ tag: 'pt-BR',
+ direction: 'ltr',
+ },
+ [LocaleType.DE_DE]: {
+ name: 'Deutsch',
+ tag: 'de-DE',
+ direction: 'ltr',
+ },
+ [LocaleType.IT_IT]: {
+ name: 'Italiano',
+ tag: 'it-IT',
+ direction: 'ltr',
+ },
+ [LocaleType.ID_ID]: {
+ name: 'Bahasa Indonesia',
+ tag: 'id-ID',
+ direction: 'ltr',
+ },
+ [LocaleType.PL_PL]: {
+ name: 'Polski',
+ tag: 'pl-PL',
+ direction: 'ltr',
+ },
+ [LocaleType.AR_SA]: {
+ name: 'العربية',
+ tag: 'ar-SA',
+ direction: 'rtl',
+ numberingSystem: 'arab',
+ },
+};
diff --git a/packages/design/src/components/gallery/Gallery.tsx b/packages/design/src/components/gallery/Gallery.tsx
index 838ca63ff6..84e5169e45 100644
--- a/packages/design/src/components/gallery/Gallery.tsx
+++ b/packages/design/src/components/gallery/Gallery.tsx
@@ -44,6 +44,7 @@ export function Gallery(props: IGalleryProps) {
const dialogRef = useRef<HTMLDivElement>(null);
const activeImage = useMemo(() => images[activeImageIndex], [activeImageIndex, images]);
+ const hasPagination = images.length > 1;
// Focus management
useEffect(() => {
@@ -159,16 +160,18 @@ export function Gallery(props: IGalleryProps) {
univer-text-gray-400
`}
>
- <Pager
- className={`
- !univer-text-gray-400
- [&_[data-u-comp=pager-left-arrow]:hover]:!univer-bg-gray-600
- [&_[data-u-comp=pager-right-arrow]:hover]:!univer-bg-gray-600
- `}
- value={activeImageIndex + 1}
- total={images.length}
- onChange={(value) => setActiveImageIndex(value - 1)}
- />
+ {hasPagination && (
+ <Pager
+ className={`
+ !univer-text-gray-400
+ [&_[data-u-comp=pager-left-arrow]:hover]:!univer-bg-gray-600
+ [&_[data-u-comp=pager-right-arrow]:hover]:!univer-bg-gray-600
+ `}
+ value={activeImageIndex + 1}
+ total={images.length}
+ onChange={(value) => setActiveImageIndex(value - 1)}
+ />
+ )}
<button
type="button"
aria-label="Zoom in"
diff --git a/packages/design/src/components/gallery/__tests__/index.spec.tsx b/packages/design/src/components/gallery/__tests__/index.spec.tsx
index 51ac6d9a7e..27643b8fa4 100644
--- a/packages/design/src/components/gallery/__tests__/index.spec.tsx
+++ b/packages/design/src/components/gallery/__tests__/index.spec.tsx
@@ -101,6 +101,13 @@ describe('Gallery', () => {
expect(img).toHaveAttribute('alt', 'Image 2 of 3');
});
+ it('does not render pagination for a single image', () => {
+ render(<Gallery images={[images[0]]} open={true} />);
+
+ expect(document.querySelector('[data-u-comp="pager"]')).not.toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /zoom in/i })).toBeInTheDocument();
+ });
+
it('should zoom with wheel event and keep value in range', () => {
render(<Gallery images={images} open={true} />);
const img = screen.getByRole('img');
diff --git a/packages/design/src/components/pager/Pager.tsx b/packages/design/src/components/pager/Pager.tsx
index c3dd3db284..8f30dd3c34 100644
--- a/packages/design/src/components/pager/Pager.tsx
+++ b/packages/design/src/components/pager/Pager.tsx
@@ -68,7 +68,7 @@ export function Pager(props: IPagerProps) {
data-u-comp="pager-left-arrow"
className={`
univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded
- univer-border-none univer-bg-transparent univer-p-0
+ univer-border-none univer-bg-transparent univer-p-0 univer-text-current
hover:univer-bg-gray-50
dark:hover:!univer-bg-gray-600
`}
@@ -76,14 +76,14 @@ export function Pager(props: IPagerProps) {
role="button"
onClick={onClickLeftArrow}
>
- <MoreLeftIcon />
+ <MoreLeftIcon className="rtl:univer-rotate-180" />
</button>
<span className="univer-mx-1">{text}</span>
<button
data-u-comp="pager-right-arrow"
className={`
univer-inline-flex univer-size-4 univer-cursor-pointer univer-items-center univer-rounded
- univer-border-none univer-bg-transparent univer-p-0
+ univer-border-none univer-bg-transparent univer-p-0 univer-text-current
hover:univer-bg-gray-50
dark:hover:!univer-bg-gray-600
`}
@@ -91,7 +91,7 @@ export function Pager(props: IPagerProps) {
role="button"
onClick={onClickRightArrow}
>
- <MoreRightIcon />
+ <MoreRightIcon className="rtl:univer-rotate-180" />
</button>
</>
)
diff --git a/packages/design/src/locale/ar-SA.ts b/packages/design/src/locale/ar-SA.ts
index 9be5f5aa87..d9fa1df5a4 100644
--- a/packages/design/src/locale/ar-SA.ts
+++ b/packages/design/src/locale/ar-SA.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'زاوية',
flip: 'قلب',
delete: 'حذف',
- transparency: 'Transparency',
+ transparency: 'الشفافية',
},
},
};
diff --git a/packages/design/src/locale/ca-ES.ts b/packages/design/src/locale/ca-ES.ts
index 4250f2771b..d6e4079e3e 100644
--- a/packages/design/src/locale/ca-ES.ts
+++ b/packages/design/src/locale/ca-ES.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Angle',
flip: 'Girar',
delete: 'Eliminar',
- transparency: 'Transparency',
+ transparency: 'Transparència',
},
},
};
diff --git a/packages/design/src/locale/de-DE.ts b/packages/design/src/locale/de-DE.ts
index 66de40d0a0..5caafca3b7 100644
--- a/packages/design/src/locale/de-DE.ts
+++ b/packages/design/src/locale/de-DE.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Winkel',
flip: 'Umkehren',
delete: 'Löschen',
- transparency: 'Transparency',
+ transparency: 'Transparenz',
},
},
};
diff --git a/packages/design/src/locale/es-ES.ts b/packages/design/src/locale/es-ES.ts
index d2bf2b6f5d..983ec46f38 100644
--- a/packages/design/src/locale/es-ES.ts
+++ b/packages/design/src/locale/es-ES.ts
@@ -19,8 +19,8 @@ import type enUS from './en-US';
const locale: typeof enUS = {
design: {
Confirm: {
- cancel: 'cancel·la',
- confirm: 'ok',
+ cancel: 'Cancelar',
+ confirm: 'Aceptar',
},
CascaderList: {
empty: 'Cap',
@@ -53,20 +53,20 @@ const locale: typeof enUS = {
empty: 'Cap',
},
ColorPicker: {
- more: 'Més colors',
- cancel: 'cancel·la',
- confirm: 'ok',
+ more: 'Más colores',
+ cancel: 'Cancelar',
+ confirm: 'Aceptar',
},
GradientColorPicker: {
linear: 'Lineal',
radial: 'Radial',
angular: 'Angular',
- diamond: 'Diamant',
- offset: 'Desplaçament',
- angle: 'Angle',
- flip: 'Girar',
+ diamond: 'Diamante',
+ offset: 'Desplazamiento',
+ angle: 'Ángulo',
+ flip: 'Invertir',
delete: 'Eliminar',
- transparency: 'Transparency',
+ transparency: 'Transparencia',
},
},
};
diff --git a/packages/design/src/locale/fa-IR.ts b/packages/design/src/locale/fa-IR.ts
index 09da413d0a..3be9107a17 100644
--- a/packages/design/src/locale/fa-IR.ts
+++ b/packages/design/src/locale/fa-IR.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'زاویه',
flip: 'برگردان',
delete: 'حذف',
- transparency: 'Transparency',
+ transparency: 'شفافیت',
},
},
};
diff --git a/packages/design/src/locale/fr-FR.ts b/packages/design/src/locale/fr-FR.ts
index dcb5112f51..16a686897b 100644
--- a/packages/design/src/locale/fr-FR.ts
+++ b/packages/design/src/locale/fr-FR.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Angle',
flip: 'Retourner',
delete: 'Supprimer',
- transparency: 'Transparency',
+ transparency: 'Transparence',
},
},
};
diff --git a/packages/design/src/locale/id-ID.ts b/packages/design/src/locale/id-ID.ts
index 7029272b58..d86878a1e4 100644
--- a/packages/design/src/locale/id-ID.ts
+++ b/packages/design/src/locale/id-ID.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Sudut',
flip: 'Balik',
delete: 'Hapus',
- transparency: 'Transparency',
+ transparency: 'Transparansi',
},
},
};
diff --git a/packages/design/src/locale/it-IT.ts b/packages/design/src/locale/it-IT.ts
index 832f55322a..657ecc1610 100644
--- a/packages/design/src/locale/it-IT.ts
+++ b/packages/design/src/locale/it-IT.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Angolo',
flip: 'Capovolgi',
delete: 'Elimina',
- transparency: 'Transparency',
+ transparency: 'Trasparenza',
},
},
};
diff --git a/packages/design/src/locale/ja-JP.ts b/packages/design/src/locale/ja-JP.ts
index 45113e0c06..2603faf12c 100644
--- a/packages/design/src/locale/ja-JP.ts
+++ b/packages/design/src/locale/ja-JP.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: '角度',
flip: '反転',
delete: '削除',
- transparency: 'Transparency',
+ transparency: '透明度',
},
},
};
diff --git a/packages/design/src/locale/ko-KR.ts b/packages/design/src/locale/ko-KR.ts
index e3e0ee0662..31085bb3b9 100644
--- a/packages/design/src/locale/ko-KR.ts
+++ b/packages/design/src/locale/ko-KR.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: '각도',
flip: '뒤집기',
delete: '삭제',
- transparency: 'Transparency',
+ transparency: '투명도',
},
},
};
diff --git a/packages/design/src/locale/pl-PL.ts b/packages/design/src/locale/pl-PL.ts
index 0f3efb0d1c..33b365d7f8 100644
--- a/packages/design/src/locale/pl-PL.ts
+++ b/packages/design/src/locale/pl-PL.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Kąt',
flip: 'Obrót',
delete: 'Usuń',
- transparency: 'Transparency',
+ transparency: 'Przezroczystość',
},
},
};
diff --git a/packages/design/src/locale/pt-BR.ts b/packages/design/src/locale/pt-BR.ts
index c9e97c044a..a198a4fa84 100644
--- a/packages/design/src/locale/pt-BR.ts
+++ b/packages/design/src/locale/pt-BR.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Ângulo',
flip: 'Inverter',
delete: 'Excluir',
- transparency: 'Transparency',
+ transparency: 'Transparência',
},
},
};
diff --git a/packages/design/src/locale/ru-RU.ts b/packages/design/src/locale/ru-RU.ts
index efaa1d95ed..377bfa7f30 100644
--- a/packages/design/src/locale/ru-RU.ts
+++ b/packages/design/src/locale/ru-RU.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'угол',
flip: 'перевернуть',
delete: 'удалить',
- transparency: 'Transparency',
+ transparency: 'прозрачность',
},
},
};
diff --git a/packages/design/src/locale/sk-SK.ts b/packages/design/src/locale/sk-SK.ts
index fb2ac583d0..bbab0a1711 100644
--- a/packages/design/src/locale/sk-SK.ts
+++ b/packages/design/src/locale/sk-SK.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Uhol',
flip: 'Prevrátiť',
delete: 'Odstrániť',
- transparency: 'Transparency',
+ transparency: 'Priehľadnosť',
},
},
};
diff --git a/packages/design/src/locale/vi-VN.ts b/packages/design/src/locale/vi-VN.ts
index 06d44a17bd..3d88befb29 100644
--- a/packages/design/src/locale/vi-VN.ts
+++ b/packages/design/src/locale/vi-VN.ts
@@ -66,7 +66,7 @@ const locale: typeof enUS = {
angle: 'Góc',
flip: 'Lật',
delete: 'Xóa',
- transparency: 'Transparency',
+ transparency: 'Độ trong suốt',
},
},
};
diff --git a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
index b5b823d3eb..a578fc811d 100644
--- a/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
+++ b/packages/drawing-ui/src/views/object-list-panel/ObjectListPanelBase.tsx
@@ -19,7 +19,6 @@ import { Button, clsx, Input } from '@univerjs/design';
import {
ArrowDownIcon,
ArrowUpIcon,
- CloseIcon,
EyeIcon,
EyelashIcon,
LocateFixedIcon,
@@ -159,7 +158,6 @@ export interface IObjectListPanelBaseProps {
labels: IObjectListPanelLabels;
showHeader?: boolean;
capabilities?: IObjectListPanelCapabilities;
- onClose?: () => void;
onSelect: (objectId: string, multiSelect: boolean) => void;
onSetVisible: (objectIds: string[], visible: boolean) => void;
onCommitName: (objectId: string, value: string) => void;
@@ -215,7 +213,6 @@ export function ObjectListPanelBase(props: IObjectListPanelBaseProps) {
labels,
showHeader = true,
capabilities,
- onClose,
onSelect,
onSetVisible,
onCommitName,
@@ -332,7 +329,7 @@ export function ObjectListPanelBase(props: IObjectListPanelBaseProps) {
<div
className="
univer-box-border univer-flex univer-size-full univer-min-w-0 univer-max-w-full univer-flex-col
- univer-gap-3 univer-overflow-hidden univer-p-4 univer-text-gray-700
+ univer-gap-3 univer-overflow-hidden univer-text-gray-700
dark:!univer-text-gray-200
"
data-drawing-object-list-panel="true"
@@ -348,11 +345,6 @@ export function ObjectListPanelBase(props: IObjectListPanelBaseProps) {
>
{labels.title}
</div>
- {onClose && (
- <Button aria-label={labels.close} className="univer-size-8 univer-shrink-0" size="small" variant="ghost" onClick={onClose}>
- <CloseIcon className="univer-size-4" />
- </Button>
- )}
</div>
)}
diff --git a/packages/sheets-ui/src/views/menu-item-input/MenuItemInput.tsx b/packages/sheets-ui/src/views/menu-item-input/MenuItemInput.tsx
index 466fa2938c..0a3de0fe42 100644
--- a/packages/sheets-ui/src/views/menu-item-input/MenuItemInput.tsx
+++ b/packages/sheets-ui/src/views/menu-item-input/MenuItemInput.tsx
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+import type { KeyboardEvent } from 'react';
import type { IMenuItemInputProps } from './interface';
import { LocaleService } from '@univerjs/core';
import { InputNumber } from '@univerjs/design';
@@ -81,6 +82,10 @@ export const MenuItemInput = (props: IMenuItemInputProps) => {
}
}
+ function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
+ event.stopPropagation();
+ }
+
return (
<div className="univer-inline-flex univer-items-center univer-gap-1">
{localeService.t(prefix)}
@@ -93,6 +98,7 @@ export const MenuItemInput = (props: IMenuItemInputProps) => {
max={max}
disabled={disabled}
onPressEnter={handlePressEnter}
+ onKeyDown={handleKeyDown}
onChange={handleChange}
/>
</div>
diff --git a/packages/ui/src/views/font-family/FontFamilyDropdown.tsx b/packages/ui/src/views/font-family/FontFamilyDropdown.tsx
index 9e106c4b3e..d6f23e6263 100644
--- a/packages/ui/src/views/font-family/FontFamilyDropdown.tsx
+++ b/packages/ui/src/views/font-family/FontFamilyDropdown.tsx
@@ -16,10 +16,11 @@
import type { MouseEvent, PointerEvent, ReactNode } from 'react';
import type { Observable } from 'rxjs';
+import { LocaleService } from '@univerjs/core';
import { clsx, Dropdown } from '@univerjs/design';
import { MoreDownIcon } from '@univerjs/icons';
import { useState } from 'react';
-import { useObservable } from '../../utils/di';
+import { useDependency, useObservable } from '../../utils/di';
import { FontFamily } from './FontFamily';
import { FontFamilyItem } from './FontFamilyItem';
@@ -53,6 +54,8 @@ export function FontFamilyDropdown(props: IFontFamilyDropdownProps) {
onMouseDown,
onPointerDown,
} = props;
+ const localeService = useDependency(LocaleService);
+ const direction = useObservable(localeService.direction$, localeService.getDirection());
const disabledObservableValue = useObservable(disabled$);
const disabled = Boolean(disabledProp || disabledObservableValue);
const [open, setOpen] = useState(false);
@@ -70,6 +73,7 @@ export function FontFamilyDropdown(props: IFontFamilyDropdownProps) {
onOpenChange={setOpen}
overlay={(
<div
+ dir={direction}
className={clsx(`
univer-max-h-72 univer-min-w-44 univer-overflow-y-auto univer-rounded-lg univer-border
univer-border-solid univer-border-gray-200 univer-bg-white univer-p-1 univer-shadow-lg
@@ -85,6 +89,7 @@ export function FontFamilyDropdown(props: IFontFamilyDropdownProps) {
aria-disabled={disabled}
aria-expanded={open}
aria-label={ariaLabel}
+ dir={direction}
className={clsx(`
univer-flex univer-h-6 univer-min-w-0 univer-cursor-default univer-items-center univer-justify-between
univer-gap-1 univer-rounded-md univer-px-1.5 univer-text-sm univer-text-gray-900
diff --git a/packages/ui/src/views/font-family/FontFamilyItem.tsx b/packages/ui/src/views/font-family/FontFamilyItem.tsx
index 93f6ee0ac0..743c29dd7e 100644
--- a/packages/ui/src/views/font-family/FontFamilyItem.tsx
+++ b/packages/ui/src/views/font-family/FontFamilyItem.tsx
@@ -19,7 +19,7 @@ import type { ICustomComponentProps } from '../../services/menu/menu';
import { LocaleService } from '@univerjs/core';
import { Tooltip } from '@univerjs/design';
import { InfoIcon } from '@univerjs/icons';
-import { useDependency } from '../../utils/di';
+import { useDependency, useObservable } from '../../utils/di';
import { useFontList } from './use-font-list';
export interface IFontFamilyItemProps extends ICustomComponentProps<string> {
@@ -30,6 +30,7 @@ export const FONT_FAMILY_ITEM_COMPONENT = 'UI_FONT_FAMILY_ITEM_COMPONENT';
export const FontFamilyItem = ({ value, onChange }: IFontFamilyItemProps) => {
const localeService = useDependency(LocaleService);
+ const direction = useObservable(localeService.direction$, localeService.getDirection());
const { fonts, fontService } = useFontList();
function handleSelectFont(nextValue: string) {
@@ -38,6 +39,7 @@ export const FontFamilyItem = ({ value, onChange }: IFontFamilyItemProps) => {
return (
<ul
+ dir={direction}
className="univer-m-0 univer-list-none univer-p-0 univer-text-sm"
style={{ fontFamily: value }}
>
diff --git a/packages/ui/src/views/font-family/__tests__/FontInputs.spec.tsx b/packages/ui/src/views/font-family/__tests__/FontInputs.spec.tsx
index 5954c0f38e..25249b3307 100644
--- a/packages/ui/src/views/font-family/__tests__/FontInputs.spec.tsx
+++ b/packages/ui/src/views/font-family/__tests__/FontInputs.spec.tsx
@@ -47,10 +47,11 @@ const SetFontFamilyCommand: ICommand<{ value: string }> = {
},
};
-function renderWithDependencies(element: ReactElement) {
+function renderWithDependencies(element: ReactElement, direction: 'ltr' | 'rtl' = 'ltr') {
const univer = new Univer();
const injector = univer.__getInjector();
injector.add([IFontService, { useClass: FontService }]);
+ injector.get(LocaleService).setDirection(direction);
injector.get(LocaleService).load({
[LocaleType.ZH_CN]: {
ui: {
@@ -144,6 +145,19 @@ describe('font input views', () => {
rendered.dispose();
});
+ it('applies locale direction to the font-family menu list', () => {
+ const rendered = renderWithDependencies(
+ <FontFamilyItem
+ value="Arial"
+ onChange={(value) => TestState.familyChanges.push(value)}
+ />,
+ 'rtl'
+ );
+
+ expect(rendered.container.querySelector('ul')?.getAttribute('dir')).toBe('rtl');
+ rendered.dispose();
+ });
+
it('commits font size only when Enter is pressed', () => {
const disabled$ = new BehaviorSubject(false);
const rendered = render(