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(numfmt-ui): respect RTL direction in more format options (#7183)
白熱5d98ccd162d3
diff --git a/packages/design/src/components/button/ButtonGroup.tsx b/packages/design/src/components/button/ButtonGroup.tsxindex 1b11e2b240..c85ec47a46 100644--- a/packages/design/src/components/button/ButtonGroup.tsx+++ b/packages/design/src/components/button/ButtonGroup.tsx@@ -20,8 +20,9 @@import type { ReactElement } from 'react';import type { IButtonProps } from './Button';-import { Children, cloneElement } from 'react';+import { Children, cloneElement, useContext } from 'react';import { clsx } from '../../helper/clsx';+import { ConfigContext } from '../config-provider/ConfigProvider';export interface IButtonGroupProps {className?: string;@@ -34,9 +35,11 @@ export const ButtonGroup = ({orientation = 'horizontal',children,}: IButtonGroupProps) => {+ const { direction } = useContext(ConfigContext);const totalButtons = Children.count(children);const isHorizontal = orientation === 'horizontal';const isVertical = orientation === 'vertical';+ const isRtl = direction === 'rtl';return (<div@@ -52,9 +55,10 @@ export const ButtonGroup = ({return cloneElement(child, {className: clsx({- '!univer-rounded-l-none': isHorizontal && !isFirst,- '!univer-rounded-r-none': isHorizontal && !isLast,- '!univer-border-l-0': isHorizontal && !isFirst,+ '!univer-rounded-l-none': isHorizontal && (isRtl ? !isLast : !isFirst),+ '!univer-rounded-r-none': isHorizontal && (isRtl ? !isFirst : !isLast),+ '!univer-border-l-0': isHorizontal && !isRtl && !isFirst,+ '!univer-border-r-0': isHorizontal && isRtl && !isFirst,'!univer-rounded-t-none': isVertical && !isFirst,'!univer-rounded-b-none': isVertical && !isLast,diff --git a/packages/design/src/components/button/__tests__/index.spec.tsx b/packages/design/src/components/button/__tests__/index.spec.tsxindex 5705da7f76..8e1a546a28 100644--- a/packages/design/src/components/button/__tests__/index.spec.tsx+++ b/packages/design/src/components/button/__tests__/index.spec.tsx@@ -16,6 +16,7 @@import { cleanup, fireEvent, render } from '@testing-library/react';import { afterEach, describe, expect, it } from 'vitest';+import { ConfigProvider } from '../../config-provider/ConfigProvider';import { Button } from '../Button';import { ButtonGroup } from '../ButtonGroup';import '@testing-library/jest-dom/vitest';@@ -86,4 +87,24 @@ describe('ButtonGroup', () => {);expect(container.querySelector('.univer-grid-flow-row')).toBeNull();});++ it('mirrors horizontal edge styles in RTL', () => {+ const { container } = render(+ <ConfigProvider mountContainer={document.body} direction="rtl">+ <ButtonGroup orientation="horizontal">+ <Button>btn1</Button>+ <Button>btn2</Button>+ </ButtonGroup>+ </ConfigProvider>+ );++ const buttons = container.querySelectorAll('[data-u-comp="button"]');++ expect(buttons[0].className).toContain('!univer-rounded-l-none');+ expect(buttons[0].className).not.toContain('!univer-rounded-r-none');+ expect(buttons[1].className).toContain('!univer-rounded-r-none');+ expect(buttons[1].className).toContain('!univer-border-r-0');+ expect(buttons[1].className).not.toContain('!univer-rounded-l-none');+ expect(buttons[1].className).not.toContain('!univer-border-l-0');+ });});diff --git a/packages/design/src/components/color-picker/ColorInput.tsx b/packages/design/src/components/color-picker/ColorInput.tsxindex c599f1da5b..798e142b20 100644--- a/packages/design/src/components/color-picker/ColorInput.tsx+++ b/packages/design/src/components/color-picker/ColorInput.tsx@@ -75,6 +75,7 @@ function HexInput({ hsv, onChange }: IInputProps) {className={clsx(`univer-w-full univer-px-2 !univer-pl-4 univer-uppercasefocus:univer-border-primary-500 focus:univer-outline-none+ rtl:!univer-pl-2 rtl:!univer-pr-4dark:!univer-text-white`, borderClassName)}value={inputValue}@@ -87,6 +88,7 @@ function HexInput({ hsv, onChange }: IInputProps) {className={`univer-absolute univer-left-1.5 univer-top-1/2 -univer-translate-y-1/2 univer-text-smuniver-text-gray-400+ rtl:univer-left-auto rtl:univer-right-1.5`}>#diff --git a/packages/design/src/components/color-picker/ColorPicker.tsx b/packages/design/src/components/color-picker/ColorPicker.tsxindex e415eecdf6..4fc2f24d8c 100644--- a/packages/design/src/components/color-picker/ColorPicker.tsx+++ b/packages/design/src/components/color-picker/ColorPicker.tsx@@ -130,7 +130,7 @@ export function ColorPicker({ format = 'hex', value, onChange }: IColorPickerPro</div><Dialog- className="!univer-w-fit !univer-p-2.5"+ className="!univer-z-[1090] !univer-w-fit !univer-p-2.5"closable={false}maskClosable={false}open={visible}diff --git a/packages/design/src/components/color-picker/__tests__/index.spec.tsx b/packages/design/src/components/color-picker/__tests__/index.spec.tsxindex 96c2564148..bfd4848484 100644--- a/packages/design/src/components/color-picker/__tests__/index.spec.tsx+++ b/packages/design/src/components/color-picker/__tests__/index.spec.tsx@@ -15,7 +15,7 @@*/import type { ComponentProps } from 'react';-import { cleanup, render } from '@testing-library/react';+import { cleanup, fireEvent, render } from '@testing-library/react';import { useState } from 'react';import { afterEach, describe, expect, it, vi } from 'vitest';import { ConfigProvider } from '../../config-provider/ConfigProvider';@@ -84,6 +84,16 @@ describe('ColorPicker', () => {}});+ it('should place custom color dialog above parent popovers', () => {+ const { container } = render(<ColorPicker />);+ const moreLink = container.querySelector('[data-u-comp="color-picker"] a') as HTMLAnchorElement;++ fireEvent.click(moreLink);++ const dialog = document.querySelector('[role="dialog"]');+ expect(dialog?.className).toContain('!univer-z-[1090]');+ });+it('should call onChange when rgb input changes in dialog', () => {const handleChange = vi.fn();const { container } = render(<ColorPicker onChange={handleChange} />);@@ -188,4 +198,20 @@ describe('ColorInput', () => {expect(onChange).toHaveBeenCalledWith([0, 100, 100]); // Assuming #FF0000 corresponds to HSV [0, 100, 100]}});++ it('should mirror hex prefix and padding in RTL', () => {+ const { container } = render(+ <div dir="rtl">+ <TestComponent onChange={onChange} alpha={1} format="hex" />+ </div>+ );++ const hexInput = container.querySelector('input[maxlength="6"]') as HTMLInputElement;+ const prefix = container.querySelector('span') as HTMLSpanElement;++ expect(hexInput.className).toContain('rtl:!univer-pr-4');+ expect(hexInput.className).toContain('rtl:!univer-pl-2');+ expect(prefix.className).toContain('rtl:univer-left-auto');+ expect(prefix.className).toContain('rtl:univer-right-1.5');+ });});diff --git a/packages/protocol/package.json b/packages/protocol/package.jsonindex ef40dbed5a..a7a7d9227c 100644--- a/packages/protocol/package.json+++ b/packages/protocol/package.json@@ -64,7 +64,7 @@"build": "pnpm run build:bundle && pnpm run build:types"},"dependencies": {- "@grpc/grpc-js": "^1.14.3"+ "@grpc/grpc-js": "^1.14.4"},"devDependencies": {"@univerjs-infra/shared": "workspace:*",diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsxindex 3959cd4956..6441b3bcc7 100644--- a/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkPopup.tsx@@ -73,7 +73,7 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {<divclassName={clsx(`univer-mb-1 univer-flex univer-max-w-80 univer-flex-row univer-items-center univer-justify-between- univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow-md+ univer-gap-2 univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-2 univer-shadow-mddark:!univer-bg-gray-900`, borderClassName)}onClick={() => popupService.hideCurrentPopup()}@@ -81,7 +81,7 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {<divclassName={clsx(`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-flex-row univer-items-center- univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600+ univer-gap-1 univer-truncate univer-text-sm univer-leading-5 univer-text-primary-600`, { 'univer-text-red-500': isError })}onClick={() => {if (isError) {@@ -93,7 +93,7 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {><divclassName={`- univer-mr-2 univer-flex univer-size-5 univer-flex-none univer-items-center univer-justify-center+ univer-flex univer-size-5 univer-flex-none univer-items-center univer-justify-centeruniver-text-base univer-text-gray-900dark:!univer-text-white`}@@ -107,13 +107,14 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {<divclassName={`univer-flex univer-h-6 univer-flex-none univer-flex-row univer-items-center univer-justify-center+ univer-gap-2`}>{copyPermission && (<divclassName={clsx(`- univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row- univer-items-center univer-justify-center univer-rounded univer-text-base+ univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center+ univer-justify-center univer-rounded univer-text-basehover:univer-bg-gray-100dark:hover:!univer-bg-gray-700`, { 'univer-text-red-500': isError })}@@ -142,9 +143,10 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {{editPermission && (<><div+ data-u-comp="cell-link-popup-edit"className={`- univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row- univer-items-center univer-justify-center univer-rounded univer-text-base+ univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center+ univer-justify-center univer-rounded univer-text-basehover:univer-bg-gray-100dark:hover:!univer-bg-gray-700`}@@ -164,9 +166,10 @@ export const CellLinkPopupPure = (props: ICellLinkPopupPureProps) => {</Tooltip></div><div+ data-u-comp="cell-link-popup-remove"className={`- univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-flex-row- univer-items-center univer-justify-center univer-rounded univer-text-base+ univer-flex univer-size-6 univer-cursor-pointer univer-flex-row univer-items-center+ univer-justify-center univer-rounded univer-text-basehover:univer-bg-gray-100dark:hover:!univer-bg-gray-700`}diff --git a/packages/sheets-hyper-link-ui/src/views/__tests__/CellLinkPopup.spec.tsx b/packages/sheets-hyper-link-ui/src/views/__tests__/CellLinkPopup.spec.tsxindex e5ae3b5bef..91663b6d7d 100644--- a/packages/sheets-hyper-link-ui/src/views/__tests__/CellLinkPopup.spec.tsx+++ b/packages/sheets-hyper-link-ui/src/views/__tests__/CellLinkPopup.spec.tsx@@ -354,11 +354,9 @@ function renderPopup();});- const actions = Array.from(container.querySelectorAll('.univer-ml-2')) as HTMLElement[];-return {- edit: actions[0],- remove: actions[1],+ edit: container.querySelector('[data-u-comp="cell-link-popup-edit"]') as HTMLElement,+ remove: container.querySelector('[data-u-comp="cell-link-popup-remove"]') as HTMLElement,};}diff --git a/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx b/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsxindex 44b382172c..c9b806fb62 100644--- a/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx+++ b/packages/sheets-numfmt-ui/src/views/SheetNumfmtPanel.tsx@@ -140,8 +140,13 @@ export function SheetNumfmtPanel(props: ISheetNumfmtPanelProps) {</div></div>- <div className="univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end">- <Button onClick={handleCancel} className="univer-mr-3">+ <div+ className="+ univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end univer-gap-2+ rtl:univer-flex-row-reverse+ "+ >+ <Button onClick={handleCancel}>{localeService.t<LocaleKey>('sheets-numfmt-ui.cancel')}</Button><Button variant="primary" onClick={handleConfirm}>diff --git a/packages/sheets-numfmt-ui/src/views/__tests__/SheetNumfmtViews.spec.tsx b/packages/sheets-numfmt-ui/src/views/__tests__/SheetNumfmtViews.spec.tsxindex 3913586fb9..1c40b9d961 100644--- a/packages/sheets-numfmt-ui/src/views/__tests__/SheetNumfmtViews.spec.tsx+++ b/packages/sheets-numfmt-ui/src/views/__tests__/SheetNumfmtViews.spec.tsx@@ -348,6 +348,25 @@ describe('MoreNumfmtType Options', () => {expect(currentTestBed.numfmtService.getValue(UNIT_ID, SUB_UNIT_ID, 0, 0)).toEqual({ pattern: '0.00%' });expect((currentTestBed.injector.get(ILayoutService) as unknown as TestLayoutService).checkContentIsFocused()).toBe(true);});++ it('renders options in the current RTL direction', async () => {+ currentTestBed = createNumfmtViewTestBed();+ currentTestBed.injector.get(LocaleService).setDirection('rtl');+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);++ await act(async () => {+ root!.render(+ <RediContext.Provider value={{ injector: currentTestBed!.injector }}>+ <Options />+ </RediContext.Provider>+ );+ await Promise.resolve();+ });++ expect(container.firstElementChild?.getAttribute('dir')).toBe('rtl');+ });});describe('CustomFormat', () => {diff --git a/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx b/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsxindex ebc123ccc6..110cd9bd6d 100644--- a/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx+++ b/packages/sheets-numfmt-ui/src/views/components/MoreNumfmtType.tsx@@ -26,7 +26,7 @@ import {SetNumfmtCommand,SheetsNumfmtCellContentController,} from '@univerjs/sheets-numfmt';-import { ILayoutService, useDependency } from '@univerjs/ui';+import { ILayoutService, useDependency, useObservable } from '@univerjs/ui';import { useMemo } from 'react';import { OpenNumfmtPanelOperator } from '../../commands/operations/open.numfmt.panel.operation';import { MENU_OPTIONS } from '../../menu/menu';@@ -47,6 +47,7 @@ export function Options() {const localeService = useDependency(LocaleService);const layoutService = useDependency(ILayoutService);const sheetsNumfmtCellContentController = useDependency(SheetsNumfmtCellContentController);+ const direction = useObservable(localeService.direction$, localeService.getDirection());const selectionManagerService = useDependency(SheetsSelectionsService);const setNumfmt = (pattern: string | null) => {@@ -90,7 +91,7 @@ export function Options() {const defaultValue = 1220;return (- <div className="univer-grid univer-gap-1 univer-p-1.5">+ <div dir={direction} className="univer-grid univer-gap-1 univer-p-1.5">{menuOptions.map((item, index) => {if (item === '|') {return <Separator key={index} />;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 89874a0517..2bac3d2970 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1504,8 +1504,8 @@ importers:packages/protocol:dependencies:'@grpc/grpc-js':- specifier: ^1.14.3- version: 1.14.3+ specifier: ^1.14.4+ version: 1.14.4devDependencies:'@univerjs-infra/shared':specifier: workspace:*@@ -4794,8 +4794,8 @@ packages:'@floating-ui/[email protected]':resolution: {integrity: sha512-RiB/yIh78pcIxl6lLMG0CgBXAZ2Y0eVHqMPYugu+9U0AeT6YBeiJpf7lbdJNIugFP5SIjwNRgo4DhR1Qxi26Gg==}- '@grpc/[email protected]':- resolution: {integrity: sha512-Iq8QQQ/7X3Sac15oB6p0FmUg/klxQvXLeileoqrTRGJYLV+/9tubbr9ipz0GKHjmXVsgFPo/+W+2cA8eNcR+XA==}+ '@grpc/[email protected]':+ resolution: {integrity: sha512-k9Dj3DV/itK9D06Y8f190Qgop7/Ui+D0njFV3LHMPwPT75DpXLQohE9Wmz0QElrJnzsjB7KPWiKJbOl7IPDArQ==}engines: {node: '>=12.10.0'}'@grpc/[email protected]':@@ -12749,7 +12749,7 @@ snapshots:'@floating-ui/[email protected]': {}- '@grpc/[email protected]':+ '@grpc/[email protected]':dependencies:'@grpc/proto-loader': 0.8.0'@js-sdsl/ordered-map': 4.4.2@@ -14290,8 +14290,8 @@ snapshots:'@typescript-eslint/[email protected]([email protected])':dependencies:- '@typescript-eslint/tsconfig-utils': 8.56.1([email protected])- '@typescript-eslint/types': 8.56.1+ '@typescript-eslint/tsconfig-utils': 8.61.1([email protected])+ '@typescript-eslint/types': 8.61.1debug: 4.4.3typescript: 6.0.3transitivePeerDependencies: