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(sheets-ui): ensure context menu does not open on sheets tab when `contextMenu` is set to false (#2654)

白熱a5ecccc74f35
diff --git a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
index be709e45fa..75cc4ce9eb 100644
--- a/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/SheetBar.tsx
@@ -15,7 +15,7 @@
*/
import type { Workbook } from '@univerjs/core';
-import { ICommandService, IPermissionService, IUniverInstanceService, UniverInstanceType, UserManagerService } from '@univerjs/core';
+import { ICommandService, IPermissionService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { IncreaseSingle, MoreSingle } from '@univerjs/icons';
import { InsertSheetCommand, WorkbookCreateSheetPermission, WorkbookEditablePermission } from '@univerjs/sheets';
import { useDependency } from '@wendellhu/redi/react-bindings';
@@ -40,8 +40,6 @@ export const SheetBar = () => {
const permissionService = useDependency(IPermissionService);
const univerInstanceService = useDependency(IUniverInstanceService);
- const userManagerService = useDependency(UserManagerService);
- const currentUser = useObservable(userManagerService.currentUser$);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const unitId = workbook.getUnitId();
diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
index b64c872f3a..74cb121992 100644
--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx
@@ -15,7 +15,7 @@
*/
import type { ICommandInfo, Workbook } from '@univerjs/core';
-import { ICommandService, IPermissionService, IUniverInstanceService, LocaleService, nameCharacterCheck, UniverInstanceType } from '@univerjs/core';
+import { ICommandService, IConfigService, IPermissionService, IUniverInstanceService, LocaleService, nameCharacterCheck, UniverInstanceType } from '@univerjs/core';
import { Dropdown } from '@univerjs/design';
import {
InsertSheetMutation,
@@ -32,7 +32,7 @@ import {
WorkbookRenameSheetPermission,
WorksheetProtectionRuleModel,
} from '@univerjs/sheets';
-import { IConfirmService, Menu, useObservable } from '@univerjs/ui';
+import { IConfirmService, Menu, UI_CONFIG_KEY, useObservable } from '@univerjs/ui';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useCallback, useEffect, useRef, useState } from 'react';
@@ -73,6 +73,11 @@ export function SheetBarTabs() {
const workbook = useActiveWorkbook()!;
const permissionService = useDependency(IPermissionService);
+ const configService = useDependency(IConfigService);
+ const uiConfigs = configService.getConfig<{ contextMenu?: boolean }>(UI_CONFIG_KEY);
+
+ const contextMenu = uiConfigs?.contextMenu ?? true;
+
const updateSheetItems = useCallback(() => {
const currentSubUnitId = workbook.getActiveSheet()?.getSheetId() || '';
setActiveKey(currentSubUnitId);
@@ -387,6 +392,8 @@ export function SheetBarTabs() {
};
const onVisibleChange = (visible: boolean) => {
+ if (!contextMenu) return;
+
if (editorBridgeService?.isForceKeepVisible()) {
return;
}
@@ -410,6 +417,7 @@ export function SheetBarTabs() {
visible={visible}
align={{ offset }}
trigger={['contextMenu']}
+ disabled={!contextMenu}
overlay={(
<Menu
menuType={SheetMenuPosition.SHEET_BAR}
@@ -422,7 +430,12 @@ export function SheetBarTabs() {
)}
onVisibleChange={onVisibleChange}
>
- <div className={styles.slideTabBarContainer} ref={slideTabBarContainerRef} onDragStart={(e) => e.preventDefault()}>
+ <div
+ className={styles.slideTabBarContainer}
+ ref={slideTabBarContainerRef}
+ onDragStart={(e) => e.preventDefault()}
+ onContextMenu={(e) => e.preventDefault()}
+ >
<div className={styles.slideTabBar} style={{ boxShadow }}>
{sheetList.map((item) => (
<SheetBarItem {...item} key={item.sheetId} selected={activeKey === item.sheetId} />
diff --git a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx
index 2d09e86a61..55ae96ff81 100644
--- a/packages/ui/src/controllers/ui/ui-desktop.controller.tsx
+++ b/packages/ui/src/controllers/ui/ui-desktop.controller.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { Disposable, isInternalEditorID, LifecycleService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
+import { Disposable, IConfigService, isInternalEditorID, LifecycleService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IDisposable } from '@wendellhu/redi';
import { Inject, Injector, Optional } from '@wendellhu/redi';
@@ -27,7 +27,7 @@ import { DesktopApp } from '../../views/DesktopApp';
import { BuiltInUIPart, IUIPartsService } from '../../services/parts/parts.service';
import { CanvasPopup } from '../../views/components/popup/CanvasPopup';
import { FloatDom } from '../../views/components/dom/FloatDom';
-import type { IUniverUIConfig, IWorkbenchOptions } from './ui.controller';
+import { type IUniverUIConfig, type IWorkbenchOptions, UI_CONFIG_KEY } from './ui.controller';
const STEADY_TIMEOUT = 3000;
@@ -39,10 +39,12 @@ export class DesktopUIController extends Disposable {
@Inject(Injector) private readonly _injector: Injector,
@Inject(LifecycleService) private readonly _lifecycleService: LifecycleService,
@IUIPartsService private readonly _uiPartsService: IUIPartsService,
+ @IConfigService private readonly _configService: IConfigService,
@Optional(ILayoutService) private readonly _layoutService?: ILayoutService
) {
super();
+ this._configService.setConfig(UI_CONFIG_KEY, this._config);
this._initBuiltinComponents();
Promise.resolve().then(() => this._bootstrapWorkbench());
diff --git a/packages/ui/src/controllers/ui/ui.controller.ts b/packages/ui/src/controllers/ui/ui.controller.ts
index 44b85a57fa..2f9490dc7c 100644
--- a/packages/ui/src/controllers/ui/ui.controller.ts
+++ b/packages/ui/src/controllers/ui/ui.controller.ts
@@ -39,3 +39,5 @@ export interface IUniverUIConfig extends IWorkbenchOptions {
menu?: MenuConfig;
}
+
+export const UI_CONFIG_KEY = 'UNIVER_UI_CONFIG_KEY';
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
index 495a9cb340..63e000efc8 100644
--- a/packages/ui/src/index.ts
+++ b/packages/ui/src/index.ts
@@ -27,7 +27,7 @@ export {
SharedController,
UndoShortcutItem,
} from './controllers/shared-shortcut.controller';
-export { IUIController, type IWorkbenchOptions } from './controllers/ui/ui.controller';
+export { UI_CONFIG_KEY, IUIController, type IWorkbenchOptions } from './controllers/ui/ui.controller';
export { DesktopUIController } from './controllers/ui/ui-desktop.controller';
export { IUIPartsService, BuiltInUIPart, UIPartsService } from './services/parts/parts.service';
export { DesktopBeforeCloseService, IBeforeCloseService } from './services/before-close/before-close.service';
diff --git a/packages/ui/src/views/DesktopApp.tsx b/packages/ui/src/views/DesktopApp.tsx
index 7809ca5f7c..b73701568d 100644
--- a/packages/ui/src/views/DesktopApp.tsx
+++ b/packages/ui/src/views/DesktopApp.tsx
@@ -144,7 +144,7 @@ export function DesktopApp(props: IUniverAppProps) {
{/* footer */}
{footer && (
<footer className={styles.appFooter}>
- <ComponentContainer key="footer" components={footerComponents} />
+ <ComponentContainer key="footer" components={footerComponents} sharedProps={{ contextMenu }} />
</footer>
)}