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(mobile): correct sheet editing, dialogs and numeric inputs (#7887)
wpxp12345687a512794d31
diff --git a/packages/design/src/components/confirm/__tests__/index.spec.tsx b/packages/design/src/components/confirm/__tests__/index.spec.tsxindex db344b4589..562c56c576 100644--- a/packages/design/src/components/confirm/__tests__/index.spec.tsx+++ b/packages/design/src/components/confirm/__tests__/index.spec.tsx@@ -43,7 +43,7 @@ describe('Confirm', () => {it('should render the mobile confirmation as a bottom surface', () => {render(<MobileConfirm visible title="Mobile confirm" confirmText="Confirm">content</MobileConfirm>);- expect(document.querySelector('[role="dialog"]')).toHaveClass('!univer-bottom-0');+ expect(screen.getByRole('dialog')).toHaveStyle({ position: 'fixed', bottom: '0px' });expect(screen.getByRole('button', { name: 'Confirm' }).parentElement).toHaveClass('univer-w-full');});});diff --git a/packages/design/src/components/dialog/MobileDialog.tsx b/packages/design/src/components/dialog/MobileDialog.tsxindex 2542d7298d..b6512bc350 100644--- a/packages/design/src/components/dialog/MobileDialog.tsx+++ b/packages/design/src/components/dialog/MobileDialog.tsx@@ -17,6 +17,8 @@import type { IDialogProps } from './Dialog';import { useContext, useRef } from 'react';import { clsx } from '../../helper/clsx';+import { useMobileKeyboardViewportLayout } from '../../hooks/use-mobile-keyboard-viewport';+import { MobileActionRowGroup } from '../action-row/MobileActionRowGroup';import { Button } from '../button/Button';import { ConfigContext } from '../config-provider/ConfigProvider';import {@@ -51,14 +53,15 @@ export function MobileDialog(props: IMobileDialogProps) {onCancel,} = props;const contentRef = useRef<HTMLDivElement>(null);+ const keyboardLayout = useMobileKeyboardViewportLayout(contentRef);const { locale, mountContainer, direction } = useContext(ConfigContext);const maxHeight = globalThis.CSS?.supports('height', '1dvh') ? '80dvh' : '80vh';const footer = propFooter ?? (showOk || showCancel? (- <div className="univer-flex univer-justify-end univer-gap-2">+ <MobileActionRowGroup>{showCancel && <Button onClick={onCancel}>{locale?.Confirm.cancel}</Button>}{showOk && <Button variant="primary" onClick={onOk}>{locale?.Confirm.confirm}</Button>}- </div>+ </MobileActionRowGroup>): null);@@ -82,9 +85,9 @@ export function MobileDialog(props: IMobileDialogProps) {<DialogProvider open={open} onOpenChange={handleOpenChange} modal={mask !== false}><DialogContentclassName={clsx(`- !univer-bottom-0 !univer-left-0 !univer-right-0 !univer-top-auto !univer-flex !univer-max-w-none- !univer-translate-x-0 !univer-translate-y-0 !univer-flex-col !univer-gap-4 !univer-overflow-hidden- !univer-rounded-t-2xl !univer-p-4+ !univer-left-0 !univer-right-0 !univer-top-auto !univer-flex !univer-max-w-none !univer-translate-x-0+ !univer-translate-y-0 !univer-flex-col !univer-gap-4 !univer-overflow-hidden !univer-rounded-t-2xl+ !univer-p-4[&_[data-slot='dialog-footer']]:!univer-flex-row [&_[data-slot='dialog-footer']]:!univer-gap-3[&_[data-slot='dialog-footer']_button]:!univer-h-12[&_[data-slot='dialog-footer']_button]:!univer-flex-1@@ -101,9 +104,9 @@ export function MobileDialog(props: IMobileDialogProps) {position: 'fixed',insetInline: 0,top: 'auto',- bottom: 0,+ bottom: keyboardLayout?.bottom ?? 0,width: '100%',- maxHeight,+ maxHeight: keyboardLayout ? `min(${maxHeight}, ${keyboardLayout.availableHeight}px)` : maxHeight,maxWidth: 'none',margin: 0,transform: 'none',diff --git a/packages/design/src/components/dialog/__tests__/MobileDialog.spec.tsx b/packages/design/src/components/dialog/__tests__/MobileDialog.spec.tsxindex b589330e05..3ca50e9557 100644--- a/packages/design/src/components/dialog/__tests__/MobileDialog.spec.tsx+++ b/packages/design/src/components/dialog/__tests__/MobileDialog.spec.tsx@@ -14,6 +14,7 @@* limitations under the License.*/+import type { IMobileKeyboardViewport } from '../../config-provider/ConfigProvider';import { cleanup, fireEvent, render, screen } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';import enUS from '../../../locale/en-US';@@ -54,28 +55,50 @@ describe('MobileDialog', () => {expect(onClose).toHaveBeenCalledOnce();});- it('keeps its original geometry while the keyboard viewport is visible', () => {+ it('keeps the dialog above the keyboard as its height and viewport offset change', () => {vi.stubGlobal('CSS', { supports: () => false });vi.stubGlobal('innerHeight', 768);- vi.stubGlobal('visualViewport', {- height: 448,- offsetTop: 0,- addEventListener: vi.fn(),- removeEventListener: vi.fn(),- });+ const renderDialog = (viewport: IMobileKeyboardViewport | null) => (+ <ConfigProvider+ mountContainer={document.body}+ mobileKeyboardViewport={viewport}+ >+ <MobileDialog open title="Rename"><input aria-label="Sheet name" /></MobileDialog>+ </ConfigProvider>+ );+ const { rerender } = render(renderDialog(null));+ const dialog = screen.getByRole('dialog');+ expect(dialog.style.bottom).toBe('0px');+ expect(dialog.style.maxHeight).toBe('80vh');++ rerender(renderDialog({ top: 0, bottom: 448, height: 448, stableHeight: 768 }));+ expect(dialog.style.bottom).toBe('320px');+ expect(dialog.style.maxHeight).toBe('min(80vh, 448px)');++ rerender(renderDialog({ top: 24, bottom: 376, height: 352, stableHeight: 768 }));+ expect(dialog.style.bottom).toBe('392px');+ expect(dialog.style.maxHeight).toBe('min(80vh, 352px)');++ rerender(renderDialog(null));+ expect(dialog.style.bottom).toBe('0px');+ expect(dialog.style.maxHeight).toBe('80vh');+ });++ it('does not lift the dialog twice when the layout viewport already excludes the keyboard', () => {+ vi.stubGlobal('CSS', { supports: () => false });+ vi.stubGlobal('innerHeight', 448);render(<ConfigProvidermountContainer={document.body}mobileKeyboardViewport={{ top: 0, bottom: 448, height: 448, stableHeight: 768 }}>- <MobileDialog open title="Edit">Content</MobileDialog>+ <MobileDialog open title="Rename"><input aria-label="Sheet name" /></MobileDialog></ConfigProvider>);const dialog = screen.getByRole('dialog');expect(dialog.style.bottom).toBe('0px');- expect(dialog.style.maxHeight).toBe('80vh');- expect(dialog.querySelector<HTMLElement>('.univer-overflow-y-auto')?.style.paddingBottom).toBe('');+ expect(dialog.style.maxHeight).toBe('min(80vh, 448px)');});it('keeps the dialog open for IME candidate Escape and closes after composition ends', () => {diff --git a/packages/sheets-ui/src/controllers/mobile/ui-mobile.controller.ts b/packages/sheets-ui/src/controllers/mobile/ui-mobile.controller.tsindex 6f3baf31b9..532ef8e4bc 100644--- a/packages/sheets-ui/src/controllers/mobile/ui-mobile.controller.ts+++ b/packages/sheets-ui/src/controllers/mobile/ui-mobile.controller.ts@@ -189,8 +189,17 @@ export const MobileFormulaBarSubmitCommand: ICommand = {editorBridgeService.refreshEditCellState();editorBridgeService.changeEditorDirty(false);+ const editorService = accessor.get(IEditorService);+ const formulaEditor = editorService.getEditor(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);+ if (editorService.getFocusId() !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {+ editorService.focus(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);+ } else {+ // Refreshing the next cell can reset the active document while the formula bar stays focused.+ formulaEditor?.focus();+ }+const endOffset = Math.max(0, (formulaModel.getBody()?.dataStream.length ?? 2) - 2);- accessor.get(IEditorService).getEditor(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)?.setSelectionRanges([{+ formulaEditor?.setSelectionRanges([{startOffset: endOffset,endOffset,}], false);diff --git a/packages/sheets-ui/src/controllers/render-controllers/mobile/__tests__/mobile-cell-edit.render-controller.spec.ts b/packages/sheets-ui/src/controllers/render-controllers/mobile/__tests__/mobile-cell-edit.render-controller.spec.tsindex 747ffe3d77..d9e2d051df 100644--- a/packages/sheets-ui/src/controllers/render-controllers/mobile/__tests__/mobile-cell-edit.render-controller.spec.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/mobile/__tests__/mobile-cell-edit.render-controller.spec.ts@@ -25,7 +25,7 @@ import { HoverManagerService } from '../../../../services/hover-manager.service'import { MobileCellEditRenderController } from '../mobile-cell-edit.render-controller';describe('MobileCellEditRenderController', () => {- it('opens the current sheet editor from a mobile double tap', () => {+ it('opens the current sheet editor without a cell pointer caret from a mobile double tap', () => {const currentDbClickedCell$ = new Subject<{ location: { unitId: string }; event: { clientX: number; clientY: number } }>();const currentPointerDownCell$ = new Subject<never>();const commandService = { syncExecuteCommand: vi.fn() };@@ -44,7 +44,6 @@ describe('MobileCellEditRenderController', () => {visible: true,eventType: DeviceInputEventType.Dblclick,unitId: 'unit-1',- pointerPosition: { x: 150, y: 180 },});controller.dispose();diff --git a/packages/sheets-ui/src/controllers/render-controllers/mobile/mobile-cell-edit.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/mobile/mobile-cell-edit.render-controller.tsindex e681fab2eb..06d010fa41 100644--- a/packages/sheets-ui/src/controllers/render-controllers/mobile/mobile-cell-edit.render-controller.ts+++ b/packages/sheets-ui/src/controllers/render-controllers/mobile/mobile-cell-edit.render-controller.ts@@ -45,11 +45,11 @@ export class MobileCellEditRenderController extends Disposable implements IRendereturn;}+ // Mobile edits in the formula bar; a cell pointer position would later refocus the hidden cell editor.this._commandService.syncExecuteCommand(SetCellEditVisibleOperation.id, {visible: true,eventType: DeviceInputEventType.Dblclick,unitId: this._context.unitId,- pointerPosition: { x: cell.event.clientX, y: cell.event.clientY },} as IEditorBridgeServiceVisibleParam);}));diff --git a/packages/sheets-ui/src/views/mobile/formula-bar/MobileFormulaBar.tsx b/packages/sheets-ui/src/views/mobile/formula-bar/MobileFormulaBar.tsxindex 726c85d0be..447d681c02 100644--- a/packages/sheets-ui/src/views/mobile/formula-bar/MobileFormulaBar.tsx+++ b/packages/sheets-ui/src/views/mobile/formula-bar/MobileFormulaBar.tsx@@ -86,7 +86,12 @@ export function MobileFormulaBar() {let cursorFrame: number | undefined;const contentFrame = requestAnimationFrame(() => {editorBridgeService.refreshEditCellState();- editorService.focus(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);+ if (editorService.getFocusId() !== DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY) {+ editorService.focus(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);+ } else {+ // Replaying the cell can change the active document while keeping the cached editor id.+ editorService.getEditor(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)?.focus();+ }cursorFrame = requestAnimationFrame(() => {const editor = editorService.getEditor(DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);const end = Math.max(0, (editor?.getDocumentData().body?.dataStream.length ?? 2) - 2);diff --git a/packages/sheets-ui/src/views/mobile/menu-item-input/MobileMenuItemInput.tsx b/packages/sheets-ui/src/views/mobile/menu-item-input/MobileMenuItemInput.tsxindex 920e484b54..ff1772d612 100644--- a/packages/sheets-ui/src/views/mobile/menu-item-input/MobileMenuItemInput.tsx+++ b/packages/sheets-ui/src/views/mobile/menu-item-input/MobileMenuItemInput.tsx@@ -15,10 +15,12 @@*/import type { KeyboardEvent } from 'react';+import type { LocaleKey } from '../../../locale/types';import type { IMenuItemInputProps } from '../../menu-item-input/interface';import { LocaleService } from '@univerjs/core';-import { InputNumber } from '@univerjs/design';+import { Button, InputNumber } from '@univerjs/design';import { useDependency, useObservable } from '@univerjs/ui';+import { useState } from 'react';export function MobileMenuItemInput(props: IMenuItemInputProps) {const {@@ -32,30 +34,52 @@ export function MobileMenuItemInput(props: IMenuItemInputProps) {} = props;const localeService = useDependency(LocaleService);const disabled = useObservable(disabled$ ?? null, false);- const inputValue = Math.min(max, Math.max(min, Number(value)));+ const [draft, setDraft] = useState<{ source: string; value: number | null } | null>(null);+ const inputValue = draft !== null && draft.source === value+ ? draft.value+ : Math.min(max, Math.max(min, Number(value)));++ if (draft !== null && draft.source !== value) {+ setDraft(null);+ }function handleChange(nextValue: number | null) {- if (nextValue == null) {+ setDraft({ source: value, value: nextValue });+ }++ function handleConfirm() {+ if (disabled || inputValue == null || !Number.isFinite(inputValue)) {return;}+ const nextValue = Math.min(max, Math.max(min, inputValue));+ setDraft({ source: value, value: nextValue });onChange(nextValue.toString());}function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {+ if (event.key === 'Escape' && !event.nativeEvent.isComposing) {+ return;+ }event.stopPropagation();+ if (event.key === 'Enter' && !event.nativeEvent.isComposing) {+ event.preventDefault();+ handleConfirm();+ }}return (- <div className="univer-flex univer-min-w-0 univer-flex-1 univer-items-center univer-gap-2">+ <div+ className="univer-flex univer-min-w-0 univer-flex-1 univer-flex-wrap univer-items-center univer-gap-2"+ onClick={(event) => event.stopPropagation()}+ ><span className="univer-shrink-0 univer-text-base univer-font-medium">{localeService.t(prefix)}</span>- <div className="univer-w-20 univer-shrink-0" onClick={(event) => event.stopPropagation()}>+ <div className="univer-w-20 univer-shrink-0"><InputNumbervalue={inputValue}size="small"precision={0}- min={min}- max={max}+ allowEmptydisabled={disabled}onKeyDown={handleKeyDown}onChange={handleChange}@@ -64,6 +88,16 @@ export function MobileMenuItemInput(props: IMenuItemInputProps) {<span className="univer-min-w-0 univer-truncate univer-text-base univer-font-medium">{localeService.t(suffix)}</span>+ <Button+ type="button"+ variant="primary"+ size="large"+ className="univer-shrink-0"+ disabled={disabled || inputValue == null || !Number.isFinite(inputValue)}+ onClick={handleConfirm}+ >+ {localeService.t<LocaleKey>('sheets-ui.button.confirm')}+ </Button></div>);}diff --git a/packages/sheets-ui/src/views/mobile/menu-item-input/__tests__/MobileMenuItemInput.spec.tsx b/packages/sheets-ui/src/views/mobile/menu-item-input/__tests__/MobileMenuItemInput.spec.tsxnew file mode 100644index 0000000000..e5ef09b48f--- /dev/null+++ b/packages/sheets-ui/src/views/mobile/menu-item-input/__tests__/MobileMenuItemInput.spec.tsx@@ -0,0 +1,183 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { IMenuItemInputProps } from '../../../menu-item-input/interface';+import { LocaleService, LocaleType, Univer } from '@univerjs/core';+import { ConfigProvider } from '@univerjs/design';+import designEnUS from '@univerjs/design/locale/en-US';+import { RediContext } from '@univerjs/ui';+import { act } from 'react';+import { createRoot } from 'react-dom/client';+import { afterEach, describe, expect, it, vi } from 'vitest';+import enUS from '../../../../locale/en-US';+import { MobileMenuItemInput } from '../MobileMenuItemInput';++(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++const disposals: Array<() => void> = [];++async function renderInput(props: Partial<IMenuItemInputProps> = {}) {+ const univer = new Univer();+ const injector = univer.__getInjector();+ const localeService = injector.get(LocaleService);+ localeService.load({ [LocaleType.EN_US]: enUS });+ localeService.setLocale(LocaleType.EN_US);+ localeService.setDirection('ltr');+ const onChange = vi.fn();+ const onRowClick = vi.fn();+ const initialProps: IMenuItemInputProps = {+ prefix: 'sheets-ui.rightClick.rowHeight',+ suffix: 'px',+ value: '88',+ min: 2,+ max: 1000,+ onChange,+ ...props,+ };+ const renderWithProps = (nextProps: Partial<IMenuItemInputProps>) => (+ <RediContext.Provider value={{ injector }}>+ <ConfigProvider locale={designEnUS.design} mountContainer={container}>+ <div onClick={onRowClick}>+ <MobileMenuItemInput {...initialProps} {...nextProps} />+ </div>+ </ConfigProvider>+ </RediContext.Provider>+ );+ const container = document.createElement('div');+ document.body.appendChild(container);+ const root = createRoot(container);+ await act(async () => root.render(renderWithProps({})));+ let mounted = true;+ const unmount = () => {+ if (!mounted) {+ return;+ }+ mounted = false;+ act(() => root.unmount());+ container.remove();+ univer.dispose();+ };+ disposals.push(unmount);++ return {+ onChange,+ onRowClick,+ container,+ unmount,+ async rerenderWithProps(nextProps: Partial<IMenuItemInputProps>) {+ await act(async () => root.render(renderWithProps(nextProps)));+ },+ };+}++function getInput(container: HTMLElement): HTMLInputElement {+ const input = container.querySelector('input');+ if (!input) {+ throw new Error('Numeric input not rendered');+ }+ return input;+}++function getConfirmButton(container: HTMLElement): HTMLButtonElement {+ const button = container.querySelector<HTMLButtonElement>('button[data-u-comp="button"]');+ if (!button) {+ throw new Error('Confirmation button not rendered');+ }+ return button;+}++async function setInputText(input: HTMLInputElement, value: string) {+ await act(async () => {+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, value);+ input.dispatchEvent(new Event('input', { bubbles: true }));+ });+}++async function pressEnter(input: HTMLInputElement, isComposing = false) {+ await act(async () => {+ input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', isComposing, bubbles: true }));+ });+}++afterEach(() => {+ disposals.splice(0).forEach((dispose) => dispose());+});++describe('MobileMenuItemInput', () => {+ it('keeps multi-digit typing as a draft until explicit confirmation', async () => {+ const { container, onChange, onRowClick } = await renderInput();+ const input = getInput(container);++ for (const value of ['1', '12', '120']) {+ await setInputText(input, value);+ expect(input.value).toBe(value);+ expect(onChange).not.toHaveBeenCalled();+ }+ await act(async () => {+ input.dispatchEvent(new FocusEvent('focusout', { bubbles: true }));+ });+ await act(async () => container.querySelector('span')?.click());+ expect(onChange).not.toHaveBeenCalled();+ expect(onRowClick).not.toHaveBeenCalled();++ await act(async () => getConfirmButton(container).click());++ expect(onChange).toHaveBeenCalledExactlyOnceWith('120');+ expect(onRowClick).not.toHaveBeenCalled();+ });++ it.each([+ { value: '1', expected: '2' },+ { value: '1200', expected: '1000' },+ ])('clamps $value only when Enter confirms the draft', async ({ value, expected }) => {+ const { container, onChange } = await renderInput();+ const input = getInput(container);+ await setInputText(input, value);+ expect(input.value).toBe(value);+ expect(onChange).not.toHaveBeenCalled();++ await pressEnter(input);++ expect(onChange).toHaveBeenCalledExactlyOnceWith(expected);+ });++ it('does not submit an empty draft or an IME confirmation key', async () => {+ const { container, onChange, unmount } = await renderInput();+ const input = getInput(container);+ await setInputText(input, '');+ expect(getConfirmButton(container).disabled).toBe(true);+ await pressEnter(input);+ expect(onChange).not.toHaveBeenCalled();++ await setInputText(input, '24');+ await pressEnter(input, true);+ unmount();++ expect(onChange).not.toHaveBeenCalled();+ });++ it('drops the previous selection draft when the menu value changes', async () => {+ const { container, onChange, rerenderWithProps } = await renderInput();+ const input = getInput(container);+ await setInputText(input, '120');++ await rerenderWithProps({ value: '32' });+ expect(input.value).toBe('32');+ await act(async () => getConfirmButton(container).click());++ expect(onChange).toHaveBeenCalledExactlyOnceWith('32');+ });+});diff --git a/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx b/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsxindex 818b01ba17..4be7dd8654 100644--- a/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx+++ b/packages/sheets-ui/src/views/mobile/sheet-bar/MobileSheetBar.tsx@@ -318,6 +318,7 @@ function MobileSheetBarImpl(props: { workbook: Workbook }) {<div className="univer-grid univer-gap-2"><InputautoFocus+ size="large"value={renameValue}onChange={(value) => {setRenameValue(value);diff --git a/packages/ui/src/views/components/confirm-part/__tests__/ConfirmPart.spec.tsx b/packages/ui/src/views/components/confirm-part/__tests__/ConfirmPart.spec.tsxindex 8d662e4859..705a88e3ec 100644--- a/packages/ui/src/views/components/confirm-part/__tests__/ConfirmPart.spec.tsx+++ b/packages/ui/src/views/components/confirm-part/__tests__/ConfirmPart.spec.tsx@@ -174,7 +174,7 @@ describe('ConfirmPart', () => {});expect(await screen.findByText('Mobile confirmation')).toBeTruthy();- expect(screen.getByRole('dialog').classList.contains('!univer-bottom-0')).toBe(true);+ expect(screen.getByRole('dialog').style.bottom).toBe('0px');rendered.dispose();});diff --git a/packages/ui/src/views/menu/mobile/MobileMenu.tsx b/packages/ui/src/views/menu/mobile/MobileMenu.tsxindex 8833ca710d..f832e26876 100644--- a/packages/ui/src/views/menu/mobile/MobileMenu.tsx+++ b/packages/ui/src/views/menu/mobile/MobileMenu.tsx@@ -25,7 +25,7 @@ import type {} from '../../../services/menu/menu';import type { IMenuSchema } from '../../../services/menu/menu-manager.service';import type { IBaseMenuProps } from '../types';-import { LocaleService } from '@univerjs/core';+import { isRealNum, LocaleService } from '@univerjs/core';import { borderBottomClassName, clsx } from '@univerjs/design';import { CheckMarkIcon, MoreLeftIcon, MoreRightIcon } from '@univerjs/icons';import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';@@ -35,7 +35,7 @@ import { ComponentManager } from '../../../common/component-manager';import { MenuItemType } from '../../../services/menu/menu';import { IMenuManagerService } from '../../../services/menu/menu-manager.service';import { useDependency, useObservable } from '../../../utils/di';-import { CustomLabel } from '../../custom-label/index';+import { CustomLabel } from '../../custom-label/CustomLabel';type MobileMenuView =| {@@ -660,7 +660,7 @@ function MobileSchemaRow(props: {onExecute?.({commandId: menuItem.commandId,- value: nextValue,+ value: typeof value === 'number' && isRealNum(nextValue) ? Number(nextValue) : nextValue,id: menuItem.id,label: schema.key,params: menuItem.params,diff --git a/packages/ui/src/views/menu/mobile/__tests__/MobileMenu.spec.tsx b/packages/ui/src/views/menu/mobile/__tests__/MobileMenu.spec.tsxindex 4fd0bc6ef5..7174363653 100644--- a/packages/ui/src/views/menu/mobile/__tests__/MobileMenu.spec.tsx+++ b/packages/ui/src/views/menu/mobile/__tests__/MobileMenu.spec.tsx@@ -38,6 +38,10 @@ import { MobileMenu } from '../MobileMenu';const injectors: Injector[] = [];+function TextValueLabel(props: { onChange?: (value: string) => void }) {+ return <button type="button" onClick={() => props.onChange?.('24')}>Submit text value</button>;+}+function renderWithDependencies(schemas: IMenuSchema[],onOptionSelect: NonNullable<ComponentProps<typeof MobileMenu>['onOptionSelect']>,@@ -60,6 +64,7 @@ function renderWithDependencies(</button>));injector.get(ComponentManager).register('plain-custom-label', () => <span>Plain custom action</span>);+ injector.get(ComponentManager).register('text-value-label', TextValueLabel);const renderMenu = (nextSchemas: IMenuSchema[]) => (<RediProvider value={{ injector }}>@@ -82,6 +87,30 @@ afterEach(() => {});describe('MobileMenu', () => {+ it.each([+ { initialValue: 1, expectedValue: 24 },+ { initialValue: '001', expectedValue: '24' },+ ])('preserves the command value type for a custom input starting with $initialValue', ({ initialValue, expectedValue }) => {+ const onOptionSelect = vi.fn();+ renderWithDependencies([{+ key: 'input',+ order: 0,+ item: {+ id: 'input.command',+ type: MenuItemType.BUTTON,+ label: { name: 'text-value-label' },+ value$: new BehaviorSubject(initialValue),+ },+ }], onOptionSelect);++ fireEvent.click(screen.getByRole('button', { name: 'Submit text value' }));++ expect(onOptionSelect).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({+ id: 'input.command',+ value: expectedValue,+ }));+ });+it('shows the selected option label instead of its persisted identifier', () => {const value$ = new BehaviorSubject('wideScreen16By9');renderWithDependencies([{