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(sheets-formula-ui): reposition help card as formula text grows (#7744)
Y.B.a77bd5d48c17
diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsxindex a8bcab17c2..a67632fc57 100644--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/HelpFunction.tsx@@ -99,7 +99,7 @@ export function HelpFunction(props: {const required = localeService.t<LocaleKey>('sheets-formula-ui.prompt.required');const optional = localeService.t<LocaleKey>('sheets-formula-ui.prompt.optional');const editorId = editor.getEditorId();- const [position$] = useEditorPosition(editorId, !!functionInfo, [functionInfo, paramIndex]);+ const [position$] = useEditorPosition(editorId, !!functionInfo, [functionInfo, paramIndex, formulaText]);function handleSwitchActive(paramIndex: number) {onParamsSwitch && onParamsSwitch(paramIndex);}diff --git a/packages/sheets-formula-ui/src/views/formula-editor/help-function/__tests__/HelpFunction.spec.tsx b/packages/sheets-formula-ui/src/views/formula-editor/help-function/__tests__/HelpFunction.spec.tsxindex 7627d99f6f..a4b9105776 100644--- a/packages/sheets-formula-ui/src/views/formula-editor/help-function/__tests__/HelpFunction.spec.tsx+++ b/packages/sheets-formula-ui/src/views/formula-editor/help-function/__tests__/HelpFunction.spec.tsx@@ -101,10 +101,12 @@ class HelpState {static editor: Editor;static switched: number[] = [];static closed = 0;+ static pageHeight = 24;static reset(): void {this.switched = [];this.closed = 0;+ this.pageHeight = 24;}}@@ -118,7 +120,7 @@ function createEditor(): Editor {getDocumentData: () => ({ documentStyle: { marginTop: 0, marginBottom: 0 } }),getSkeleton: () => ({getSkeletonData: () => ({- pages: [{ height: 24 }],+ pages: [{ height: HelpState.pageHeight }],}),}),} as unknown as Editor;@@ -180,6 +182,21 @@ async function showHelpForSum(editor: Editor) {});}+function getHelpPopupTop(): string {+ const popup = document.body.querySelector<HTMLElement>('[data-u-comp="rect-popup"]');+ if (!popup) {+ throw new TypeError('Help popup was not rendered');+ }++ return popup.style.top;+}++async function waitForPopupLayout(): Promise<void> {+ await act(async () => {+ await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()));+ });+}+function getHelpControls(): HTMLElement[] {return Array.from(document.body.querySelectorAll('div')).filter((node) => node.className.includes('univer-size-6'));@@ -342,4 +359,33 @@ describe('HelpFunction', () => {expect(editorBridgeService.helpFunctionVisible$.getValue()).toBe(true);expect(document.body.textContent).toContain('SUM(number1,[number2,...])');});++ it('moves the help card down when the formula wraps onto another line', async () => {+ const { injector, editor } = createHelpFunctionTestBed();+ const renderHelp = (formulaText: string) => renderWithInjector(+ root,+ injector, (+ <HelpFunction+ isFocus+ editor={editor}+ formulaText={formulaText}+ />+ ));++ renderHelp('=SUM(');+ await showHelpForSum(editor);++ expect(document.body.textContent).toContain('SUM(number1,[number2,...])');+ // Editor top is 20 and a single line is 24px high, so the card sits below y = 44 (+1 gap).+ expect(getHelpPopupTop()).toBe('45px');++ // Keep typing inside the same argument until the text wraps and the editor grows to three lines.+ // The function and the active parameter stay the same.+ HelpState.pageHeight = 72;+ const longFormula = `=SUM(${'1'.repeat(40)}`;+ renderHelp(longFormula);+ await waitForPopupLayout();++ expect(getHelpPopupTop()).toBe('93px');+ });});