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(ui): align font picker padding with other pickers (#7947)
白熱2edd8e7e304d
diff --git a/packages/ui/src/views/components/ribbon/TooltipButtonWrapper.tsx b/packages/ui/src/views/components/ribbon/TooltipButtonWrapper.tsxindex 28469145ab..c8e8829458 100644--- a/packages/ui/src/views/components/ribbon/TooltipButtonWrapper.tsx+++ b/packages/ui/src/views/components/ribbon/TooltipButtonWrapper.tsx@@ -17,7 +17,6 @@import type { Workbook } from '@univerjs/core';import type { IDropdownMenuProps, IDropdownProps, ITooltipProps } from '@univerjs/design';import type { ComponentType, ReactNode } from 'react';-import type { IMenuItem, IValueOption } from '../../../services/menu/menu';import { FOCUSING_SHEET, IContextService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import {clsx,@@ -39,12 +38,14 @@ import {useState,} from 'react';import { combineLatest, map, merge, of, scan, startWith, switchMap } from 'rxjs';+import type { IMenuItem, IValueOption } from '../../../services/menu/menu';import { ILayoutService } from '../../../services/layout/layout.service';import { IMenuManagerService } from '../../../services/menu/menu-manager.service';import { IShortcutService } from '../../../services/shortcut/shortcut.service';import { useDependency, useObservable } from '../../../utils/di';import { getEmbedBoundaryOwner, keepInteractionInsideSameEmbedBoundary } from '../../../utils/embed-boundary';import { CustomLabel } from '../../custom-label/CustomLabel';+import { FONT_FAMILY_ITEM_COMPONENT } from '../../font-family/FontFamilyItem';const TooltipWrapperContext = createContext({dropdownVisible: false,@@ -507,7 +508,8 @@ export function DropdownMenuWrapper({className: clsx({'focus:univer-bg-gray-0 dark:focus:!univer-bg-gray-800':typeof option.label !== 'string' && option.label?.hoverable === false,- '!univer-p-0': isSingleEmbeddedCustomPanel,+ '!univer-p-0': isSingleEmbeddedCustomPanel ||+ (typeof option.label === 'object' && option.label.name === FONT_FAMILY_ITEM_COMPONENT),}),children: (<DropdownMenuLabeldiff --git a/packages/ui/src/views/components/ribbon/__tests__/TooltipButtonWrapper.spec.tsx b/packages/ui/src/views/components/ribbon/__tests__/TooltipButtonWrapper.spec.tsxindex 005c637a29..ac3b18e2d3 100644--- a/packages/ui/src/views/components/ribbon/__tests__/TooltipButtonWrapper.spec.tsx+++ b/packages/ui/src/views/components/ribbon/__tests__/TooltipButtonWrapper.spec.tsx@@ -42,6 +42,7 @@ import { useState } from 'react';import { afterEach, describe, expect, it, vi } from 'vitest';import { ComponentManager } from '../../../../common/component-manager';import { IconManager } from '../../../../common/icon-manager';+import { FontService, IFontService } from '../../../../services/font.service';import { DesktopLayoutService, ILayoutService } from '../../../../services/layout/layout.service';import { MenuItemType } from '../../../../services/menu/menu';import { IMenuManagerService, MenuManagerService } from '../../../../services/menu/menu-manager.service';@@ -49,6 +50,7 @@ import { IPlatformService, PlatformService } from '../../../../services/platformimport { IUIRuntimeScopeService, UIRuntimeScopeService } from '../../../../services/runtime-scope/ui-runtime-scope.service';import { IShortcutService, ShortcutService } from '../../../../services/shortcut/shortcut.service';import { connectInjector } from '../../../../utils/di';+import { FONT_FAMILY_ITEM_COMPONENT, FontFamilyItem } from '../../../font-family/FontFamilyItem';import {DropdownMenuLabel,DropdownMenuWrapper,@@ -115,6 +117,7 @@ afterEach(() => {cleanup();testInjectors.forEach((injector) => injector.dispose());testInjectors.length = 0;+ vi.restoreAllMocks();});describe('ToolbarTooltip', () => {@@ -484,6 +487,41 @@ describe('DropdownMenuWrapper', () => {await waitFor(() => expect(disposeShortcutEscape).toHaveBeenCalledOnce());});+ it('uses only the shared menu padding around the font list and selects its font value', async () => {+ vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null);+ const onOptionSelect = vi.fn();+ const { findByRole, getByRole, queryByRole, injector } = renderWithDependencies(+ <ToolbarDropdownProvider>+ <TooltipWrapper dropdownKey="font-family">+ <DropdownMenuWrapper+ menuId="test-menu"+ options={[{+ label: {+ name: FONT_FAMILY_ITEM_COMPONENT,+ hoverable: false,+ selectable: false,+ },+ }]}+ onOptionSelect={onOptionSelect}+ >+ <button type="button">Open fonts</button>+ </DropdownMenuWrapper>+ </TooltipWrapper>+ </ToolbarDropdownProvider>+ );+ injector.add([IFontService, { useClass: FontService }]);+ injector.get(ComponentManager).register(FONT_FAMILY_ITEM_COMPONENT, FontFamilyItem);++ fireEvent.pointerDown(getByRole('button', { name: 'Open fonts' }), { button: 0, ctrlKey: false });+ const option = await findByRole('button', { name: 'Courier New' });+ expect(option.closest('[data-slot="dropdown-menu-item"]')?.className).toContain('!univer-p-0');+ expect(getByRole('menu').className).not.toContain('!univer-p-0');++ fireEvent.click(option);+ expect(onOptionSelect).toHaveBeenCalledWith(expect.objectContaining({ value: 'Courier New' }));+ await waitFor(() => expect(queryByRole('menu')).toBeNull());+ });+it('keeps padding around a non-embedded custom panel', async () => {const { findByRole, getByRole } = renderWithDependencies(<ToolbarDropdownProvider>