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(ui): replace grid ribbon scrolling with compact overflow menu (#7970)

白熱d78369540358
diff --git a/packages/ui/src/locale/ar-SA.ts b/packages/ui/src/locale/ar-SA.ts
index 624a325538..9edf019631 100644
--- a/packages/ui/src/locale/ar-SA.ts
+++ b/packages/ui/src/locale/ar-SA.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'أخرى',
othersDesc: 'الوظائف والإعدادات الأخرى.',
more: 'المزيد',
+ groups: {
+ clipboard: 'الحافظة',
+ font: 'الخط',
+ layout: 'المحاذاة والتخطيط',
+ number: 'تنسيق الأرقام',
+ tools: 'الأدوات',
+ editing: 'التحرير',
+ media: 'الوسائط',
+ cells: 'الخلايا',
+ formulas: 'الصيغ',
+ rules: 'القواعد',
+ organization: 'تنظيم البيانات',
+ display: 'العرض',
+ visibility: 'الظهور',
+ },
},
fontFamily: {
'not-supported': 'لم يُعثر على هذا الخط في النظام، وسيتم استخدام الخط الافتراضي.',
diff --git a/packages/ui/src/locale/ca-ES.ts b/packages/ui/src/locale/ca-ES.ts
index 284a6b360f..a70a3060e0 100644
--- a/packages/ui/src/locale/ca-ES.ts
+++ b/packages/ui/src/locale/ca-ES.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Altres',
othersDesc: 'Altres funcions i configuracions.',
more: 'Més',
+ groups: {
+ clipboard: 'Porta-retalls',
+ font: 'Tipus de lletra',
+ layout: 'Alineació i disposició',
+ number: 'Format de nombre',
+ tools: 'Eines',
+ editing: 'Edició',
+ media: 'Multimèdia',
+ cells: 'Cel·les',
+ formulas: 'Fórmules',
+ rules: 'Regles',
+ organization: 'Organització de dades',
+ display: 'Visualització',
+ visibility: 'Visibilitat',
+ },
},
fontFamily: {
'not-supported': 'No s\'ha trobat aquesta font al sistema, s\'utilitza la font per defecte.',
diff --git a/packages/ui/src/locale/de-DE.ts b/packages/ui/src/locale/de-DE.ts
index f32cf7d3c7..919d594ff6 100644
--- a/packages/ui/src/locale/de-DE.ts
+++ b/packages/ui/src/locale/de-DE.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Sonstiges',
othersDesc: 'Weitere Funktionen und Einstellungen.',
more: 'Mehr',
+ groups: {
+ clipboard: 'Zwischenablage',
+ font: 'Schriftart',
+ layout: 'Ausrichtung und Layout',
+ number: 'Zahlenformat',
+ tools: 'Werkzeuge',
+ editing: 'Bearbeitung',
+ media: 'Medien',
+ cells: 'Zellen',
+ formulas: 'Formeln',
+ rules: 'Regeln',
+ organization: 'Datenorganisation',
+ display: 'Anzeige',
+ visibility: 'Sichtbarkeit',
+ },
},
fontFamily: {
'not-supported': 'Schriftart nicht im System gefunden, Standard-Schriftart wird verwendet.',
diff --git a/packages/ui/src/locale/en-US.ts b/packages/ui/src/locale/en-US.ts
index a153f76b2d..10953eb4e7 100644
--- a/packages/ui/src/locale/en-US.ts
+++ b/packages/ui/src/locale/en-US.ts
@@ -138,6 +138,21 @@ const locale = {
others: 'Others',
othersDesc: 'Other functions and settings.',
more: 'More',
+ groups: {
+ clipboard: 'Clipboard',
+ font: 'Font',
+ layout: 'Alignment and layout',
+ number: 'Number format',
+ tools: 'Tools',
+ editing: 'Editing',
+ media: 'Media',
+ cells: 'Cells',
+ formulas: 'Formulas',
+ rules: 'Rules',
+ organization: 'Data organization',
+ display: 'Display',
+ visibility: 'Visibility',
+ },
},
fontFamily: {
'not-supported': 'No such font found in the system, using default font.',
diff --git a/packages/ui/src/locale/es-ES.ts b/packages/ui/src/locale/es-ES.ts
index 679436c193..b8c297f9c7 100644
--- a/packages/ui/src/locale/es-ES.ts
+++ b/packages/ui/src/locale/es-ES.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Otros',
othersDesc: 'Otras funciones y configuraciones.',
more: 'Más',
+ groups: {
+ clipboard: 'Portapapeles',
+ font: 'Fuente',
+ layout: 'Alineación y diseño',
+ number: 'Formato de número',
+ tools: 'Herramientas',
+ editing: 'Edición',
+ media: 'Multimedia',
+ cells: 'Celdas',
+ formulas: 'Fórmulas',
+ rules: 'Reglas',
+ organization: 'Organización de datos',
+ display: 'Visualización',
+ visibility: 'Visibilidad',
+ },
},
fontFamily: {
'not-supported': 'No se encontró esta fuente en el sistema, se utiliza la fuente predeterminada.',
diff --git a/packages/ui/src/locale/fa-IR.ts b/packages/ui/src/locale/fa-IR.ts
index 0f5244436e..82b329ecf3 100644
--- a/packages/ui/src/locale/fa-IR.ts
+++ b/packages/ui/src/locale/fa-IR.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'دیگر',
othersDesc: 'سایر عملکردها و تنظیمات.',
more: 'بیشتر',
+ groups: {
+ clipboard: 'کلیپ‌بورد',
+ font: 'قلم',
+ layout: 'تراز و چیدمان',
+ number: 'قالب عدد',
+ tools: 'ابزارها',
+ editing: 'ویرایش',
+ media: 'رسانه',
+ cells: 'سلول‌ها',
+ formulas: 'فرمول‌ها',
+ rules: 'قواعد',
+ organization: 'سازمان‌دهی داده‌ها',
+ display: 'نمایش',
+ visibility: 'قابلیت مشاهده',
+ },
},
fontFamily: {
'not-supported': 'هیچ فونتی با این نام در سیستم یافت نشد، از فونت پیش‌فرض استفاده می‌شود.',
diff --git a/packages/ui/src/locale/fr-FR.ts b/packages/ui/src/locale/fr-FR.ts
index 7664fad225..24d25b4b9f 100644
--- a/packages/ui/src/locale/fr-FR.ts
+++ b/packages/ui/src/locale/fr-FR.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Autres',
othersDesc: 'Autres fonctions et paramètres.',
more: 'Plus',
+ groups: {
+ clipboard: 'Presse-papiers',
+ font: 'Police',
+ layout: 'Alignement et disposition',
+ number: 'Format des nombres',
+ tools: 'Outils',
+ editing: 'Édition',
+ media: 'Médias',
+ cells: 'Cellules',
+ formulas: 'Formules',
+ rules: 'Règles',
+ organization: 'Organisation des données',
+ display: 'Affichage',
+ visibility: 'Visibilité',
+ },
},
fontFamily: {
'not-supported': 'Aucune police de ce type trouvée dans le système, utilisation de la police par défaut.',
diff --git a/packages/ui/src/locale/id-ID.ts b/packages/ui/src/locale/id-ID.ts
index c311837ba2..9314a1c23a 100644
--- a/packages/ui/src/locale/id-ID.ts
+++ b/packages/ui/src/locale/id-ID.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Lainnya',
othersDesc: 'Fungsi dan pengaturan lainnya.',
more: 'Lebih Banyak',
+ groups: {
+ clipboard: 'Papan klip',
+ font: 'Font',
+ layout: 'Perataan dan tata letak',
+ number: 'Format angka',
+ tools: 'Alat',
+ editing: 'Pengeditan',
+ media: 'Media',
+ cells: 'Sel',
+ formulas: 'Rumus',
+ rules: 'Aturan',
+ organization: 'Penataan data',
+ display: 'Tampilan',
+ visibility: 'Visibilitas',
+ },
},
fontFamily: {
'not-supported': 'Font tidak ditemukan di sistem, menggunakan font default.',
diff --git a/packages/ui/src/locale/it-IT.ts b/packages/ui/src/locale/it-IT.ts
index 829619c9a7..d981dfb1d0 100644
--- a/packages/ui/src/locale/it-IT.ts
+++ b/packages/ui/src/locale/it-IT.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Altri',
othersDesc: 'Altre funzioni e impostazioni.',
more: 'Altro',
+ groups: {
+ clipboard: 'Appunti',
+ font: 'Carattere',
+ layout: 'Allineamento e layout',
+ number: 'Formato numerico',
+ tools: 'Strumenti',
+ editing: 'Modifica',
+ media: 'Contenuti multimediali',
+ cells: 'Celle',
+ formulas: 'Formule',
+ rules: 'Regole',
+ organization: 'Organizzazione dei dati',
+ display: 'Visualizzazione',
+ visibility: 'Visibilità',
+ },
},
fontFamily: {
'not-supported': 'Carattere non trovato nel sistema, verrà utilizzato il carattere predefinito.',
diff --git a/packages/ui/src/locale/ja-JP.ts b/packages/ui/src/locale/ja-JP.ts
index 0d9de50653..2cdc7d14e3 100644
--- a/packages/ui/src/locale/ja-JP.ts
+++ b/packages/ui/src/locale/ja-JP.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'その他',
othersDesc: 'その他の機能と設定。',
more: 'もっと見る',
+ groups: {
+ clipboard: 'クリップボード',
+ font: 'フォント',
+ layout: '配置とレイアウト',
+ number: '表示形式',
+ tools: 'ツール',
+ editing: '編集',
+ media: 'メディア',
+ cells: 'セル',
+ formulas: '数式',
+ rules: 'ルール',
+ organization: 'データ整理',
+ display: '表示',
+ visibility: '表示設定',
+ },
},
fontFamily: {
'not-supported': 'システムにそのようなフォントが見つからないため、デフォルトのフォントを使用しています。',
diff --git a/packages/ui/src/locale/ko-KR.ts b/packages/ui/src/locale/ko-KR.ts
index 06b335a203..966fce01d4 100644
--- a/packages/ui/src/locale/ko-KR.ts
+++ b/packages/ui/src/locale/ko-KR.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: '기타',
othersDesc: '기타 함수와 설정.',
more: '더 보기',
+ groups: {
+ clipboard: '클립보드',
+ font: '글꼴',
+ layout: '맞춤 및 레이아웃',
+ number: '표시 형식',
+ tools: '도구',
+ editing: '편집',
+ media: '미디어',
+ cells: '셀',
+ formulas: '수식',
+ rules: '규칙',
+ organization: '데이터 정리',
+ display: '표시',
+ visibility: '표시 여부',
+ },
},
fontFamily: {
'not-supported': '시스템에 해당 폰트가 없어 기본 폰트를 사용합니다.',
diff --git a/packages/ui/src/locale/pl-PL.ts b/packages/ui/src/locale/pl-PL.ts
index 93996b9206..9b1a9b4ebb 100644
--- a/packages/ui/src/locale/pl-PL.ts
+++ b/packages/ui/src/locale/pl-PL.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Inne',
othersDesc: 'Inne funkcje i ustawienia.',
more: 'Więcej',
+ groups: {
+ clipboard: 'Schowek',
+ font: 'Czcionka',
+ layout: 'Wyrównanie i układ',
+ number: 'Format liczb',
+ tools: 'Narzędzia',
+ editing: 'Edycja',
+ media: 'Multimedia',
+ cells: 'Komórki',
+ formulas: 'Formuły',
+ rules: 'Reguły',
+ organization: 'Organizacja danych',
+ display: 'Wyświetlanie',
+ visibility: 'Widoczność',
+ },
},
fontFamily: {
'not-supported': 'Nie znaleziono takiej czcionki w systemie, używana jest czcionka domyślna.',
diff --git a/packages/ui/src/locale/pt-BR.ts b/packages/ui/src/locale/pt-BR.ts
index cd8ce6d5e4..a0088a6cb2 100644
--- a/packages/ui/src/locale/pt-BR.ts
+++ b/packages/ui/src/locale/pt-BR.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Outros',
othersDesc: 'Outras funções e configurações.',
more: 'Mais',
+ groups: {
+ clipboard: 'Área de transferência',
+ font: 'Fonte',
+ layout: 'Alinhamento e layout',
+ number: 'Formato de número',
+ tools: 'Ferramentas',
+ editing: 'Edição',
+ media: 'Mídia',
+ cells: 'Células',
+ formulas: 'Fórmulas',
+ rules: 'Regras',
+ organization: 'Organização de dados',
+ display: 'Exibição',
+ visibility: 'Visibilidade',
+ },
},
fontFamily: {
'not-supported': 'Fonte não encontrada no sistema, usando a fonte padrão.',
diff --git a/packages/ui/src/locale/ru-RU.ts b/packages/ui/src/locale/ru-RU.ts
index 3b2bc04a47..f662f17d60 100644
--- a/packages/ui/src/locale/ru-RU.ts
+++ b/packages/ui/src/locale/ru-RU.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Другие',
othersDesc: 'Другие функции и настройки.',
more: 'Больше',
+ groups: {
+ clipboard: 'Буфер обмена',
+ font: 'Шрифт',
+ layout: 'Выравнивание и макет',
+ number: 'Числовой формат',
+ tools: 'Инструменты',
+ editing: 'Редактирование',
+ media: 'Медиа',
+ cells: 'Ячейки',
+ formulas: 'Формулы',
+ rules: 'Правила',
+ organization: 'Организация данных',
+ display: 'Отображение',
+ visibility: 'Видимость',
+ },
},
fontFamily: {
'not-supported': 'В системе не найден такой шрифт, используется шрифт по умолчанию.',
diff --git a/packages/ui/src/locale/sk-SK.ts b/packages/ui/src/locale/sk-SK.ts
index 6518aba29f..7adf18b187 100644
--- a/packages/ui/src/locale/sk-SK.ts
+++ b/packages/ui/src/locale/sk-SK.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Ostatné',
othersDesc: 'Ďalšie funkcie a nastavenia.',
more: 'Viac',
+ groups: {
+ clipboard: 'Schránka',
+ font: 'Písmo',
+ layout: 'Zarovnanie a rozloženie',
+ number: 'Formát čísla',
+ tools: 'Nástroje',
+ editing: 'Úpravy',
+ media: 'Médiá',
+ cells: 'Bunky',
+ formulas: 'Vzorce',
+ rules: 'Pravidlá',
+ organization: 'Usporiadanie údajov',
+ display: 'Zobrazenie',
+ visibility: 'Viditeľnosť',
+ },
},
fontFamily: {
'not-supported': 'Toto písmo sa v systéme nenašlo, používa sa predvolené písmo.',
diff --git a/packages/ui/src/locale/vi-VN.ts b/packages/ui/src/locale/vi-VN.ts
index 129bef4d32..b8a62a7aa7 100644
--- a/packages/ui/src/locale/vi-VN.ts
+++ b/packages/ui/src/locale/vi-VN.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: 'Khác',
othersDesc: 'Các chức năng và cài đặt khác.',
more: 'Thêm',
+ groups: {
+ clipboard: 'Bảng tạm',
+ font: 'Phông chữ',
+ layout: 'Căn chỉnh và bố cục',
+ number: 'Định dạng số',
+ tools: 'Công cụ',
+ editing: 'Chỉnh sửa',
+ media: 'Đa phương tiện',
+ cells: 'Ô',
+ formulas: 'Công thức',
+ rules: 'Quy tắc',
+ organization: 'Tổ chức dữ liệu',
+ display: 'Hiển thị',
+ visibility: 'Chế độ hiển thị',
+ },
},
fontFamily: {
'not-supported': 'Không tìm thấy phông chữ này trong hệ thống, sử dụng phông chữ mặc định.',
diff --git a/packages/ui/src/locale/zh-CN.ts b/packages/ui/src/locale/zh-CN.ts
index b00ba46477..4769c4a484 100644
--- a/packages/ui/src/locale/zh-CN.ts
+++ b/packages/ui/src/locale/zh-CN.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: '其他',
othersDesc: '其他功能和设置。',
more: '更多',
+ groups: {
+ clipboard: '剪贴板',
+ font: '字体',
+ layout: '对齐与布局',
+ number: '数字格式',
+ tools: '工具',
+ editing: '编辑',
+ media: '媒体',
+ cells: '单元格',
+ formulas: '公式',
+ rules: '规则',
+ organization: '数据整理',
+ display: '显示',
+ visibility: '可见性',
+ },
},
fontFamily: {
'not-supported': '系统中未找到该字体,使用默认字体。',
diff --git a/packages/ui/src/locale/zh-HK.ts b/packages/ui/src/locale/zh-HK.ts
index 2f688d8594..192975be82 100644
--- a/packages/ui/src/locale/zh-HK.ts
+++ b/packages/ui/src/locale/zh-HK.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: '其他',
othersDesc: '其他功能和設定。',
more: '更多',
+ groups: {
+ clipboard: '剪貼簿',
+ font: '字型',
+ layout: '對齊與版面配置',
+ number: '數字格式',
+ tools: '工具',
+ editing: '編輯',
+ media: '媒體',
+ cells: '儲存格',
+ formulas: '公式',
+ rules: '規則',
+ organization: '資料整理',
+ display: '顯示',
+ visibility: '可見性',
+ },
},
fontFamily: {
'not-supported': '系統中未找到該字型,使用預設字型。',
diff --git a/packages/ui/src/locale/zh-TW.ts b/packages/ui/src/locale/zh-TW.ts
index 4f2fc4fa9f..b321d2789f 100644
--- a/packages/ui/src/locale/zh-TW.ts
+++ b/packages/ui/src/locale/zh-TW.ts
@@ -139,6 +139,21 @@ const locale: typeof enUS = {
others: '其他',
othersDesc: '其他功能和設定。',
more: '更多',
+ groups: {
+ clipboard: '剪貼簿',
+ font: '字型',
+ layout: '對齊與版面配置',
+ number: '數字格式',
+ tools: '工具',
+ editing: '編輯',
+ media: '媒體',
+ cells: '儲存格',
+ formulas: '公式',
+ rules: '規則',
+ organization: '資料整理',
+ display: '顯示',
+ visibility: '可見性',
+ },
},
fontFamily: {
'not-supported': '系統中未找到該字體,使用預設字體。',
diff --git a/packages/ui/src/services/menu/menu-manager.service.ts b/packages/ui/src/services/menu/menu-manager.service.ts
index c1ed4546b2..02183e2daa 100644
--- a/packages/ui/src/services/menu/menu-manager.service.ts
+++ b/packages/ui/src/services/menu/menu-manager.service.ts
@@ -16,9 +16,9 @@
import type { IAccessor } from '@univerjs/core';
import type { Observable } from 'rxjs';
-import type { IMenuItem, MenuConfig } from './menu';
import { createIdentifier, Disposable, IConfigService, Inject, Injector, merge } from '@univerjs/core';
import { Subject } from 'rxjs';
+import type { IMenuItem, MenuConfig } from './menu';
import { mergeMenuConfigs } from '../../common/menu-merge-configs';
import {
ContextMenuGroup,
@@ -114,18 +114,23 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.start',
[RibbonStartGroup.HISTORY]: {
order: 0,
+ title: 'ui.ribbon.groups.clipboard',
},
[RibbonStartGroup.FORMAT]: {
order: 1,
+ title: 'ui.ribbon.groups.font',
},
[RibbonStartGroup.LAYOUT]: {
order: 2,
+ title: 'ui.ribbon.groups.layout',
},
[RibbonStartGroup.NUMBER]: {
order: 3,
+ title: 'ui.ribbon.groups.number',
},
[RibbonStartGroup.OTHERS]: {
order: 4,
+ title: 'ui.ribbon.groups.tools',
},
},
[RibbonPosition.INSERT]: {
@@ -133,15 +138,19 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.insert',
[RibbonInsertGroup.EDIT]: {
order: 0,
+ title: 'ui.ribbon.groups.editing',
},
[RibbonInsertGroup.MEDIA]: {
order: 1,
+ title: 'ui.ribbon.groups.media',
},
[RibbonInsertGroup.CELL]: {
order: 2,
+ title: 'ui.ribbon.groups.cells',
},
[RibbonInsertGroup.OTHERS]: {
order: 3,
+ title: 'ui.ribbon.groups.tools',
},
},
[RibbonPosition.FORMULAS]: {
@@ -149,9 +158,11 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.formulas',
[RibbonFormulasGroup.BASIC]: {
order: 0,
+ title: 'ui.ribbon.groups.formulas',
},
[RibbonFormulasGroup.OTHERS]: {
order: 1,
+ title: 'ui.ribbon.groups.tools',
},
},
[RibbonPosition.DATA]: {
@@ -159,15 +170,19 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.data',
[RibbonDataGroup.FORMULAS]: {
order: 0,
+ title: 'ui.ribbon.groups.formulas',
},
[RibbonDataGroup.RULES]: {
order: 1,
+ title: 'ui.ribbon.groups.rules',
},
[RibbonDataGroup.ORGANIZATION]: {
order: 2,
+ title: 'ui.ribbon.groups.organization',
},
[RibbonDataGroup.OTHERS]: {
order: 3,
+ title: 'ui.ribbon.groups.tools',
},
},
[RibbonPosition.VIEW]: {
@@ -175,12 +190,15 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.view',
[RibbonViewGroup.DISPLAY]: {
order: 0,
+ title: 'ui.ribbon.groups.display',
},
[RibbonViewGroup.VISIBILITY]: {
order: 0,
+ title: 'ui.ribbon.groups.visibility',
},
[RibbonViewGroup.OTHERS]: {
order: 0,
+ title: 'ui.ribbon.groups.tools',
},
},
[RibbonPosition.OTHERS]: {
@@ -188,6 +206,7 @@ export class MenuManagerService extends Disposable implements IMenuManagerServic
title: 'ui.ribbon.others',
[RibbonOthersGroup.OTHERS]: {
order: 0,
+ title: 'ui.ribbon.groups.tools',
},
},
},
diff --git a/packages/ui/src/services/menu/menu.ts b/packages/ui/src/services/menu/menu.ts
index 2164ae893e..24282c08e6 100644
--- a/packages/ui/src/services/menu/menu.ts
+++ b/packages/ui/src/services/menu/menu.ts
@@ -16,7 +16,6 @@
import type { IAccessor } from '@univerjs/core';
import type { Observable } from 'rxjs';
-
import type { IRibbonGridLayout } from './menu-manager.service';
export type OneOrMany<T> = T | T[];
diff --git a/packages/ui/src/views/components/ribbon/Ribbon.tsx b/packages/ui/src/views/components/ribbon/Ribbon.tsx
index 26b8b1c850..49077ec8a8 100644
--- a/packages/ui/src/views/components/ribbon/Ribbon.tsx
+++ b/packages/ui/src/views/components/ribbon/Ribbon.tsx
@@ -15,12 +15,11 @@
*/
import type { ComponentType, ReactNode } from 'react';
-import type { RibbonType } from '../../../controllers/ui/ui.controller';
-import type { IMenuSchema } from '../../../services/menu/menu-manager.service';
import { LocaleService, throttle } from '@univerjs/core';
-import { borderBottomClassName, clsx, ConfigContext, ConfigProvider, divideXClassName, Dropdown } from '@univerjs/design';
-import { MoreVerticalIcon } from '@univerjs/icons';
+import { borderBottomClassName, clsx, ConfigContext, ConfigProvider, divideXClassName } from '@univerjs/design';
import { Fragment, useCallback, useContext, useLayoutEffect, useMemo, useRef } from 'react';
+import type { RibbonType } from '../../../controllers/ui/ui.controller';
+import type { IMenuSchema } from '../../../services/menu/menu-manager.service';
import { RibbonPosition } from '../../../services/menu/types';
import { IRibbonOverrideService } from '../../../services/ribbon/ribbon-override.service';
import { IRibbonService } from '../../../services/ribbon/ribbon.service';
@@ -30,7 +29,7 @@ import { ClassicMenu } from './ribbon-menu/ClassicMenu';
import { DefaultMenu } from './ribbon-menu/DefaultMenu';
import { RibbonGridMenu } from './ribbon-menu/RibbonGridMenu';
import { RibbonGrid } from './RibbonGrid';
-import { toolbarButtonClassName } from './ToolbarButton';
+import { RibbonOverflow } from './RibbonOverflow';
import { ToolbarItem } from './ToolbarItem';
import { ToolbarDropdownProvider } from './TooltipButtonWrapper';
@@ -292,6 +291,7 @@ export function Ribbon(props: IRibbonProps) {
{!hideToolbar && ribbonType === 'grid' && (
<RibbonGrid
+ key={effectiveActivatedTab}
{...embedRibbonOverrideAttributes}
groups={activeGroup.allGroups}
title={activatedTabTitle}
@@ -356,54 +356,7 @@ export function Ribbon(props: IRibbonProps) {
rtl:univer-pr-2
`}
>
- <Dropdown
- collisionPadding={{ right: 12, left: 12 }}
- onOpenAutoFocus={(e) => e.preventDefault()}
- overlay={(
- <div
- className={`
- univer-box-border univer-grid
- univer-max-w-[--radix-popper-available-width] univer-gap-2 univer-p-2
- `}
- >
- {activeGroup.hiddenGroups.map((groupItem) => (
- <div
- key={groupItem.key}
- className="univer-flex univer-items-center univer-gap-2"
- >
- <div className="univer-flex univer-flex-wrap univer-gap-2">
- {groupItem.children
- ? groupItem.children?.map((child) => (
- child.item && (
- <ToolbarItem
- key={child.key}
- {...child.item}
- preserveStrokeWidth
- />
- )
- ))
- : (
- groupItem.item && (
- <ToolbarItem
- key={groupItem.key}
- {...groupItem.item}
- preserveStrokeWidth
- />
- )
- )}
- </div>
- </div>
- ))}
- </div>
- )}
- >
- <button
- type="button"
- className={toolbarButtonClassName}
- >
- <MoreVerticalIcon preserveStrokeWidth />
- </button>
- </Dropdown>
+ <RibbonOverflow groups={activeGroup.hiddenGroups} />
</div>
)}
</ToolbarDropdownProvider>
diff --git a/packages/ui/src/views/components/ribbon/RibbonGrid.tsx b/packages/ui/src/views/components/ribbon/RibbonGrid.tsx
index 83c57dbff0..9485ffc374 100644
--- a/packages/ui/src/views/components/ribbon/RibbonGrid.tsx
+++ b/packages/ui/src/views/components/ribbon/RibbonGrid.tsx
@@ -15,11 +15,13 @@
*/
import type { HTMLAttributes } from 'react';
-import type { IMenuSchema } from '../../../services/menu/menu-manager.service';
import { LocaleService } from '@univerjs/core';
-import { borderBottomClassName, borderRightClassName, clsx, scrollbarClassName } from '@univerjs/design';
+import { borderBottomClassName, borderRightClassName, clsx } from '@univerjs/design';
+import { useLayoutEffect, useRef, useState } from 'react';
+import type { IMenuSchema } from '../../../services/menu/menu-manager.service';
import { useDependency } from '../../../utils/di';
import { placeRibbonGridItems } from './ribbon-grid-layout';
+import { RibbonOverflow } from './RibbonOverflow';
import { ToolbarItem } from './ToolbarItem';
import { ToolbarDropdownProvider } from './TooltipButtonWrapper';
@@ -30,81 +32,136 @@ interface IRibbonGridProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'>
export function RibbonGrid({ groups, title, className, ...props }: IRibbonGridProps) {
const localeService = useDependency(LocaleService);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const moreRef = useRef<HTMLDivElement>(null);
+ const groupsRef = useRef(new Map<string, HTMLDivElement>());
+ const [visibleGroupCount, setVisibleGroupCount] = useState(groups.length);
+
+ useLayoutEffect(() => {
+ const container = containerRef.current;
+ if (!container) return;
+
+ const measure = () => {
+ const style = getComputedStyle(container);
+ const availableWidth = container.clientWidth - Number.parseFloat(style.paddingLeft || '0') - Number.parseFloat(style.paddingRight || '0');
+ const widths = groups.map((group) => groupsRef.current.get(group.key)?.getBoundingClientRect().width ?? 0);
+ const totalWidth = widths.reduce((sum, width) => sum + width, 0);
+ const limit = totalWidth <= availableWidth ? availableWidth : availableWidth - (moreRef.current?.getBoundingClientRect().width ?? 0);
+ let used = 0;
+ let count = 0;
+ for (const width of widths) {
+ if (used + width > limit) break;
+ used += width;
+ count += 1;
+ }
+ setVisibleGroupCount(count);
+ };
+
+ const observer = new ResizeObserver(measure);
+ observer.observe(container);
+ groupsRef.current.forEach((element) => observer.observe(element));
+ if (moreRef.current) observer.observe(moreRef.current);
+ return () => observer.disconnect();
+ }, [groups, visibleGroupCount]);
+
+ const hiddenGroups = groups.slice(visibleGroupCount);
return (
<div
{...props}
+ ref={containerRef}
data-testid="ribbon-grid-toolbar"
data-u-comp="ribbon-grid-toolbar"
className={clsx(`
- univer-box-border univer-flex univer-overflow-x-auto univer-overflow-y-hidden univer-bg-gray-50
- univer-px-2 univer-text-sm
+ univer-relative univer-box-border univer-flex univer-h-[73px] univer-min-w-0 univer-overflow-hidden
+ univer-bg-gray-50 univer-px-2 univer-text-sm
dark:!univer-bg-gray-900
- `, borderBottomClassName, scrollbarClassName, className)}
+ `, borderBottomClassName, className)}
role="toolbar"
aria-label={localeService.t(title)}
>
- <ToolbarDropdownProvider>
- {groups.map((group) => {
- const placements = placeRibbonGridItems(group.children ?? []);
- return (
- <div
- key={group.key}
- data-u-comp="ribbon-grid-group"
- className="
- univer-relative univer-box-border univer-flex univer-shrink-0 univer-flex-col univer-px-2
- "
- >
+ <ToolbarDropdownProvider key={visibleGroupCount}>
+ <div className="univer-flex univer-min-w-0 univer-overflow-hidden">
+ {groups.map((group, index) => {
+ const placements = placeRibbonGridItems(group.children ?? []);
+ return (
<div
- data-testid="ribbon-grid-group-grid"
- className="
- univer-grid univer-min-h-0 univer-flex-1 univer-grid-flow-col
- univer-grid-rows-[repeat(2,1.5rem)] univer-content-center univer-gap-2 univer-py-2
- [&>div>span>span]:univer-h-full
- "
+ key={group.key}
+ ref={(element) => {
+ if (element) groupsRef.current.set(group.key, element);
+ else groupsRef.current.delete(group.key);
+ }}
+ data-u-comp="ribbon-grid-group"
+ data-group-key={group.key}
+ aria-hidden={index >= visibleGroupCount || undefined}
+ className={clsx(`
+ univer-relative univer-box-border univer-flex univer-w-max univer-shrink-0
+ univer-flex-col univer-px-2
+ `, index >= visibleGroupCount && `
+ univer-pointer-events-none univer-invisible univer-absolute
+ `)}
>
- {placements.map((placement) => placement.item.item && (
- <div
- key={placement.item.key}
- className={clsx(`
- univer-flex univer-items-stretch
- [&>span>button]:univer-h-full
- [&>span]:univer-h-full
- `, placement.width && `
- [&>span>span]:univer-w-full
- [&>span]:univer-w-full
- [&_[data-u-command]]:univer-w-full
- `)}
- style={{
- gridRow: `${placement.row} / span ${placement.rowSpan}`,
- gridColumn: `${placement.column} / span ${placement.columnSpan}`,
- width: placement.width,
- }}
- >
- <ToolbarItem
- {...placement.item.item}
- grid
- large={placement.rowSpan > 1}
- showLabel={placement.showLabel}
- iconSize={placement.iconSize}
- fullWidth={placement.width !== undefined}
- preserveStrokeWidth
- />
- </div>
- ))}
+ <div
+ data-testid="ribbon-grid-group-grid"
+ className="
+ univer-grid univer-min-h-0 univer-flex-1 univer-grid-flow-col
+ univer-grid-rows-[repeat(2,1.5rem)] univer-content-center univer-gap-2 univer-py-2
+ [&>div>span>span]:univer-h-full
+ "
+ >
+ {placements.map((placement) => placement.item.item && (
+ <div
+ key={placement.item.key}
+ className={clsx(`
+ univer-flex univer-items-stretch
+ [&>span>button]:univer-h-full
+ [&>span]:univer-h-full
+ `, placement.width && `
+ [&>span>span]:univer-w-full
+ [&>span]:univer-w-full
+ [&_[data-u-command]]:univer-w-full
+ `)}
+ style={{
+ gridRow: `${placement.row} / span ${placement.rowSpan}`,
+ gridColumn: `${placement.column} / span ${placement.columnSpan}`,
+ width: placement.width,
+ }}
+ >
+ <ToolbarItem
+ {...placement.item.item}
+ grid
+ large={placement.rowSpan > 1}
+ showLabel={placement.showLabel}
+ iconSize={placement.iconSize}
+ fullWidth={placement.width !== undefined}
+ preserveStrokeWidth
+ />
+ </div>
+ ))}
+ </div>
+ <span
+ data-testid="ribbon-grid-group-divider"
+ className={clsx(`
+ univer-pointer-events-none univer-absolute univer-bottom-1.5 univer-right-0
+ univer-top-3.5 !univer-border-gray-300 univer-opacity-50
+ rtl:univer-left-0 rtl:univer-right-auto
+ `, borderRightClassName)}
+ aria-hidden="true"
+ />
</div>
- <span
- data-testid="ribbon-grid-group-divider"
- className={clsx(`
- univer-pointer-events-none univer-absolute univer-bottom-1.5 univer-right-0
- univer-top-3.5 !univer-border-gray-300 univer-opacity-50
- rtl:univer-left-0 rtl:univer-right-auto
- `, borderRightClassName)}
- aria-hidden="true"
- />
- </div>
- );
- })}
+ );
+ })}
+ </div>
+ <div
+ ref={moreRef}
+ aria-hidden={hiddenGroups.length === 0 || undefined}
+ className={clsx(`
+ univer-box-border univer-w-16 univer-shrink-0 univer-py-2 univer-pl-2
+ rtl:univer-pl-0 rtl:univer-pr-2
+ `, hiddenGroups.length === 0 && 'univer-invisible univer-absolute')}
+ >
+ {hiddenGroups.length > 0 && <RibbonOverflow groups={hiddenGroups} grid />}
+ </div>
</ToolbarDropdownProvider>
</div>
);
diff --git a/packages/ui/src/views/components/ribbon/RibbonOverflow.tsx b/packages/ui/src/views/components/ribbon/RibbonOverflow.tsx
new file mode 100644
index 0000000000..62643f7a09
--- /dev/null
+++ b/packages/ui/src/views/components/ribbon/RibbonOverflow.tsx
@@ -0,0 +1,162 @@
+/**
+ * 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 { LocaleService } from '@univerjs/core';
+import { borderTopClassName, clsx, ConfigContext, Dropdown } from '@univerjs/design';
+import { MoreDownIcon, MoreHorizontalIcon, MoreVerticalIcon } from '@univerjs/icons';
+import { useContext, useEffect, useRef, useState } from 'react';
+import type { IMenuSchema } from '../../../services/menu/menu-manager.service';
+import { IDialogService } from '../../../services/dialog/dialog.service';
+import { ISidebarService } from '../../../services/sidebar/sidebar.service';
+import { useDependency } from '../../../utils/di';
+import { toolbarButtonClassName } from './ToolbarButton';
+import { ToolbarItem } from './ToolbarItem';
+import { ToolbarDropdownProvider } from './TooltipButtonWrapper';
+
+interface IRibbonOverflowProps {
+ groups: IMenuSchema[];
+ grid?: boolean;
+}
+
+export function RibbonOverflow({ groups, grid = false }: IRibbonOverflowProps) {
+ const localeService = useDependency(LocaleService);
+ const dialogService = useDependency(IDialogService);
+ const sidebarService = useDependency(ISidebarService);
+ const { direction } = useContext(ConfigContext);
+ const [openedGroups, setOpenedGroups] = useState<IMenuSchema[] | null>(null);
+ const open = openedGroups === groups;
+ const keyboardRef = useRef(false);
+ const restoreFocusRef = useRef(true);
+ const label = localeService.t('ui.ribbon.more');
+
+ useEffect(() => {
+ if (!open) return;
+ const closeForPanel = () => {
+ restoreFocusRef.current = false;
+ setOpenedGroups(null);
+ };
+ const sidebar = sidebarService.sidebarOptions$.subscribe((options) => {
+ if (options.visible) closeForPanel();
+ });
+ const dialogs = dialogService.getDialogs$().subscribe((options) => {
+ if (options.some((dialog) => dialog.open)) closeForPanel();
+ });
+ return () => {
+ sidebar.unsubscribe();
+ dialogs.unsubscribe();
+ };
+ }, [open, dialogService, sidebarService]);
+
+ return (
+ <Dropdown
+ open={open}
+ onOpenChange={(visible) => {
+ if (visible) restoreFocusRef.current = true;
+ setOpenedGroups(visible ? groups : null);
+ }}
+ align={direction === 'rtl' ? 'start' : 'end'}
+ collisionPadding={12}
+ aria-label={label}
+ data-u-comp="ribbon-overflow"
+ className="univer-w-80 univer-max-w-[--radix-popper-available-width] univer-overflow-x-hidden"
+ onOpenAutoFocus={(event) => {
+ if (!keyboardRef.current) event.preventDefault();
+ }}
+ onFocusOutside={(event) => {
+ // Formatting commands focus the editor; keep More available for the next adjustment.
+ event.preventDefault();
+ }}
+ onCloseAutoFocus={(event) => {
+ if (!restoreFocusRef.current) event.preventDefault();
+ }}
+ overlay={(
+ <ToolbarDropdownProvider>
+ <div className="univer-px-2 univer-py-1">
+ {groups.map((group, index) => (
+ <section
+ key={group.key}
+ aria-label={group.title ? localeService.t(group.title) : undefined}
+ className={clsx('univer-py-1.5', index > 0 && borderTopClassName)}
+ >
+ {group.title && (
+ <h3
+ className="
+ univer-m-0 univer-mb-1 univer-px-1 univer-text-xs univer-font-medium
+ univer-text-gray-500
+ dark:!univer-text-gray-400
+ "
+ >
+ {localeService.t(group.title)}
+ </h3>
+ )}
+ <div className="univer-flex univer-flex-wrap univer-items-center univer-gap-1">
+ {(group.children ?? [group]).map((child) => child.item && (
+ <div
+ key={child.key}
+ className="
+ univer-min-w-0 univer-max-w-full
+ [&>span]:univer-block [&>span]:univer-h-full
+ "
+ style={{ width: child.item.label && !child.item.icon ? child.gridLayout?.width : undefined }}
+ >
+ <ToolbarItem
+ {...child.item}
+ grid
+ showLabel={child.gridLayout?.showLabel}
+ fullWidth
+ overflow
+ preserveStrokeWidth
+ />
+ </div>
+ ))}
+ </div>
+ </section>
+ ))}
+ </div>
+ </ToolbarDropdownProvider>
+ )}
+ >
+ <button
+ type="button"
+ aria-label={label}
+ onPointerDown={() => { keyboardRef.current = false; }}
+ onKeyDown={() => { keyboardRef.current = true; }}
+ className={clsx(toolbarButtonClassName, `
+ data-[state=open]:univer-bg-primary-50 data-[state=open]:univer-text-primary-600
+ focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
+ dark:data-[state=open]:!univer-bg-gray-700 dark:data-[state=open]:!univer-text-primary-300
+ `, grid && '!univer-h-14 !univer-w-14 univer-flex-col univer-gap-1.5 univer-text-xs')}
+ >
+ {grid
+ ? (
+ <>
+ <MoreHorizontalIcon className="univer-size-5" preserveStrokeWidth />
+ <span
+ className="univer-flex univer-items-center univer-gap-0.5"
+ >
+ {label}
+ <MoreDownIcon
+ className="univer-size-3"
+ preserveStrokeWidth
+ />
+ </span>
+ </>
+ )
+ : <MoreVerticalIcon preserveStrokeWidth />}
+ </button>
+ </Dropdown>
+ );
+}
diff --git a/packages/ui/src/views/components/ribbon/ToolbarItem.tsx b/packages/ui/src/views/components/ribbon/ToolbarItem.tsx
index ceae85f67c..f6b9586d95 100644
--- a/packages/ui/src/views/components/ribbon/ToolbarItem.tsx
+++ b/packages/ui/src/views/components/ribbon/ToolbarItem.tsx
@@ -16,13 +16,13 @@
import type { IDropdownMenuProps, IDropdownProps } from '@univerjs/design';
import type { ComponentType } from 'react';
-import type { IDisplayMenuItem, IMenuItem, IMenuSelectorItem, IValueOption } from '../../../services/menu/menu';
-import type { ITooltipWrapperRef } from './TooltipButtonWrapper';
import { ICommandService, LocaleService } from '@univerjs/core';
import { borderClassName, clsx, cva } from '@univerjs/design';
import { MoreDownIcon } from '@univerjs/icons';
import { forwardRef, useMemo } from 'react';
import { isObservable, Observable } from 'rxjs';
+import type { IDisplayMenuItem, IMenuItem, IMenuSelectorItem, IValueOption } from '../../../services/menu/menu';
+import type { ITooltipWrapperRef } from './TooltipButtonWrapper';
import { ComponentManager } from '../../../common/component-manager';
import { ILayoutService } from '../../../services/layout/layout.service';
import { MenuItemType } from '../../../services/menu/menu';
@@ -34,6 +34,7 @@ import { DropdownMenuWrapper, TooltipWrapper } from './TooltipButtonWrapper';
export type IToolbarItemProps = IDisplayMenuItem<IMenuItem> & {
grid?: boolean;
+ overflow?: boolean;
large?: boolean;
showLabel?: boolean;
iconSize?: number;
@@ -206,7 +207,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
const executeCommand = (commandId: string, params?: Record<string, unknown>) => {
layoutService.focus();
- commandService.executeCommand(commandId, params);
+ return commandService.executeCommand(commandId, params);
};
const {
@@ -221,6 +222,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
slot,
params,
grid,
+ overflow,
large,
showLabel,
iconSize,
@@ -233,7 +235,8 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
const gridLabel = title ?? tooltip;
const shortcutDisplay = useToolbarShortcutDisplay({ id, commandId, shortcut });
- let tooltipTitle = tooltip ? localeService.t(tooltip) : '';
+ const tooltipLabel = tooltip ?? (overflow ? title : undefined);
+ let tooltipTitle = typeof tooltipLabel === 'string' ? localeService.t(tooltipLabel) : '';
if (shortcutDisplay) {
tooltipTitle += ` (${shortcutDisplay})`;
}
@@ -268,13 +271,16 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
const selectionsCommandId = (props as IDisplayMenuItem<IMenuSelectorItem>).selectionsCommandId;
const bId = commandId ?? id;
const sId = selectionsCommandId ?? commandId ?? id;
- const titleToDisplay = grid ? (showLabel ? gridLabel : large ? undefined : title) : title;
const customLabelName = typeof label === 'string' ? label : label?.name ?? '';
const hasCustomLabel = Boolean(componentManager.get(customLabelName));
+ let titleToDisplay = grid ? (showLabel ? gridLabel : large ? undefined : title) : title;
+ if (overflow) {
+ titleToDisplay = hasCustomLabel || (iconToDisplay && !showLabel) ? undefined : gridLabel;
+ }
const selectorAriaLabel = tooltip
? localeService.t(tooltip)
- : typeof titleToDisplay === 'string'
- ? localeService.t(titleToDisplay)
+ : typeof title === 'string'
+ ? localeService.t(title)
: undefined;
function handleSelect(option: IValueOption) {
@@ -286,12 +292,12 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
}
const commandParams = typeof option.params === 'function' ? option.params(option.value) : option.params;
- executeCommand(commandId, commandParams ?? { value: option.value });
+ return executeCommand(commandId, commandParams ?? { value: option.value });
}
function handleSelectionsValueChange(value: string | number) {
if (disabled) return;
- executeCommand(sId, { value });
+ return executeCommand(sId, { value });
}
function handleClick() {
@@ -299,7 +305,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
if (menuType === MenuItemType.BUTTON_SELECTOR) {
const commandParams = typeof params === 'function' ? params() : params;
- executeCommand(bId, commandParams ?? { value });
+ return executeCommand(bId, commandParams ?? { value });
}
}
@@ -312,12 +318,21 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
className={clsx(toolbarButtonSelectorRootVariants({ disabled }), {
'univer-box-border univer-h-full univer-min-w-14 univer-flex-col !univer-pr-0': grid && large,
'univer-box-border univer-h-full': grid && !large,
+ '!univer-h-auto univer-min-h-7 univer-w-full univer-text-xs': overflow,
})}
>
- <div
- className={clsx(toolbarButtonSelectorMainVariants({ active: activated, disabled }), {
+ <button
+ type="button"
+ disabled={disabled}
+ aria-label={selectorAriaLabel}
+ aria-pressed={props.activated$ ? activated : undefined}
+ className={clsx(`
+ univer-border-0 univer-bg-transparent univer-text-inherit
+ focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
+ `, toolbarButtonSelectorMainVariants({ active: activated, disabled }), {
'univer-h-full univer-w-full univer-flex-col univer-justify-center univer-rounded univer-px-1 univer-pb-4 [&>svg]:univer-size-6': grid && large,
'[&>svg]:univer-size-4': grid && !large,
+ 'univer-min-h-7 univer-min-w-0 univer-flex-1 univer-gap-1.5 univer-whitespace-normal univer-px-1.5 univer-text-start': overflow,
})}
onClick={handleClick}
>
@@ -330,7 +345,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
label={label}
onChange={handleSelectionsValueChange}
/>
- </div>
+ </button>
<DropdownMenuWrapper
menuId={id}
@@ -343,15 +358,21 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
dropdownComponent={dropdownComponent}
dropdownMenuComponent={dropdownMenuComponent}
>
- <div
- className={clsx(toolbarButtonSelectorTriggerVariants({ disabled, active: activated }), {
+ <button
+ type="button"
+ disabled={disabled}
+ aria-label={`${selectorAriaLabel ?? ''} ${localeService.t('ui.ribbon.more')}`}
+ className={clsx(`
+ univer-border-0 univer-bg-transparent univer-text-inherit
+ focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
+ `, toolbarButtonSelectorTriggerVariants({ disabled, active: activated }), {
'!univer-top-auto univer-bottom-0 univer-h-4 univer-w-full univer-rounded-b univer-rounded-t-none': grid && large,
'univer-h-full': grid && !large,
})}
data-disabled={disabled}
>
<MoreDownIcon preserveStrokeWidth={preserveStrokeWidth} />
- </div>
+ </button>
</DropdownMenuWrapper>
</div>
);
@@ -379,6 +400,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
'univer-box-border univer-h-full': grid && !large,
'univer-bg-gray-0 dark:!univer-bg-gray-800': grid && !large && !icon,
'[&>svg]:univer-size-4': grid && !large,
+ '!univer-h-auto univer-min-h-7 univer-w-full univer-min-w-0 univer-gap-1.5 univer-whitespace-normal univer-px-1.5 univer-text-start univer-text-xs focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600 [&>span]:univer-min-w-0 [&>span]:univer-whitespace-normal': overflow,
}, grid && !large && !icon && borderClassName)}
>
{grid && large
@@ -445,7 +467,11 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
`
: showLabel
? 'univer-gap-1 univer-px-1.5 univer-text-sm'
- : 'univer-text-sm', grid && fullWidth && isCustomComponent && '!univer-px-0');
+ : 'univer-text-sm', grid && fullWidth && isCustomComponent && '!univer-px-0', overflow && `
+ !univer-h-auto univer-min-h-7 univer-w-full univer-justify-start univer-gap-1.5
+ univer-whitespace-normal univer-px-1.5 univer-py-1 univer-text-start univer-text-xs
+ focus-visible:univer-ring-2 focus-visible:univer-ring-primary-600
+ `);
const buttonStyle = grid && large ? { textAlign: 'center', whiteSpace: 'normal' } as const : undefined;
if (isCustomComponent) {
@@ -468,7 +494,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
>
<CustomLabel
className={grid && fullWidth ? '!univer-w-full' : undefined}
- title={grid && showLabel ? gridLabel! : title!}
+ title={overflow ? undefined : grid && showLabel ? gridLabel! : title!}
value={value}
label={label}
/>
@@ -492,7 +518,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
return;
}
const commandParams = typeof params === 'function' ? params() : params;
- executeCommand(props.commandId ?? props.id, commandParams ?? (typeof value === 'undefined' ? undefined : { value }));
+ return executeCommand(props.commandId ?? props.id, commandParams ?? (typeof value === 'undefined' ? undefined : { value }));
}}
onDoubleClick={() => props.subId && executeCommand(props.subId)}
>
@@ -505,7 +531,7 @@ export const ToolbarItem = forwardRef<ITooltipWrapperRef, IToolbarItemProps>((pr
title={grid && (large || showLabel) ? gridLabel : undefined}
/>
)
- : <CustomLabel title={title!} />}
+ : <CustomLabel title={overflow ? gridLabel : title!} />}
</ToolbarButton>
);
}
diff --git a/packages/ui/src/views/components/ribbon/__tests__/Ribbon.spec.tsx b/packages/ui/src/views/components/ribbon/__tests__/Ribbon.spec.tsx
index 6300eaa317..497563d411 100644
--- a/packages/ui/src/views/components/ribbon/__tests__/Ribbon.spec.tsx
+++ b/packages/ui/src/views/components/ribbon/__tests__/Ribbon.spec.tsx
@@ -19,20 +19,22 @@
*/
import type { ComponentType } from 'react';
-import type { IMenuSchema } from '../../../../services/menu/menu-manager.service';
import { act, cleanup, render } from '@testing-library/react';
import { ICommandService, Injector, LocaleService } from '@univerjs/core';
import { connectInjector } from '@wendellhu/redi/react-bindings';
import { BehaviorSubject, of, Subject } from 'rxjs';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { IMenuSchema } from '../../../../services/menu/menu-manager.service';
import { ComponentManager } from '../../../../common/component-manager';
import { IconManager } from '../../../../common/icon-manager';
+import { IDialogService } from '../../../../services/dialog/dialog.service';
import { ILayoutService } from '../../../../services/layout/layout.service';
import { MenuItemType } from '../../../../services/menu/menu';
import { RibbonPosition } from '../../../../services/menu/types';
import { IRibbonOverrideService } from '../../../../services/ribbon/ribbon-override.service';
import { IRibbonService } from '../../../../services/ribbon/ribbon.service';
import { IShortcutService } from '../../../../services/shortcut/shortcut.service';
+import { ISidebarService } from '../../../../services/sidebar/sidebar.service';
import { Ribbon } from '../Ribbon';
describe('Ribbon override chrome', () => {
@@ -58,6 +60,8 @@ describe('Ribbon override chrome', () => {
it('renders a title-only placeholder without the empty toolbar row', () => {
const injector = new Injector([
[ComponentManager],
+ [IDialogService, { useValue: { getDialogs$: () => new Subject() } }],
+ [ISidebarService, { useValue: { sidebarOptions$: new Subject() } }],
[LocaleService, { useValue: { t: (key: string) => key } }],
[IRibbonService, { useValue: createEmptyRibbonService() }],
[IRibbonOverrideService, {
@@ -97,6 +101,8 @@ describe('Ribbon override chrome', () => {
}];
const injector = new Injector([
[ComponentManager],
+ [IDialogService, { useValue: { getDialogs$: () => new Subject() } }],
+ [ISidebarService, { useValue: { sidebarOptions$: new Subject() } }],
[LocaleService, { useValue: { t: (key: string) => key } }],
[IRibbonService, { useValue: createRibbonService(ribbon, RibbonPosition.INSERT) }],
[IRibbonOverrideService, {
@@ -185,6 +191,8 @@ describe('Ribbon override chrome', () => {
};
const injector = new Injector([
[ComponentManager],
+ [IDialogService, { useValue: { getDialogs$: () => new Subject() } }],
+ [ISidebarService, { useValue: { sidebarOptions$: new Subject() } }],
[IconManager, { useValue: { get: () => null } }],
[ICommandService, { useValue: { executeCommand: () => {} } }],
[ILayoutService, { useValue: { focus: () => {} } }],
diff --git a/packages/ui/src/views/components/ribbon/__tests__/RibbonGrid.spec.tsx b/packages/ui/src/views/components/ribbon/__tests__/RibbonGrid.spec.tsx
new file mode 100644
index 0000000000..54fc1563fb
--- /dev/null
+++ b/packages/ui/src/views/components/ribbon/__tests__/RibbonGrid.spec.tsx
@@ -0,0 +1,145 @@
+/**
+ * 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.
+ */
+
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { ComponentType } from 'react';
+import { act, cleanup, fireEvent, render, within } from '@testing-library/react';
+import { ICommandService, Injector, LocaleService } from '@univerjs/core';
+import { Subject } from 'rxjs';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { IMenuSchema } from '../../../../services/menu/menu-manager.service';
+import { ComponentManager } from '../../../../common/component-manager';
+import { IconManager } from '../../../../common/icon-manager';
+import { IDialogService } from '../../../../services/dialog/dialog.service';
+import { ILayoutService } from '../../../../services/layout/layout.service';
+import { MenuItemType } from '../../../../services/menu/menu';
+import { IShortcutService } from '../../../../services/shortcut/shortcut.service';
+import { ISidebarService } from '../../../../services/sidebar/sidebar.service';
+import { connectInjector } from '../../../../utils/di';
+import { RibbonGrid } from '../RibbonGrid';
+
+const injectors: Injector[] = [];
+let availableWidth = 250;
+let resizeCallbacks: ResizeObserverCallback[] = [];
+let groupWidths: Record<string, number> = {};
+
+function mountGrid(groups: IMenuSchema[]) {
+ const injector = new Injector([
+ [ComponentManager],
+ [IconManager, { useValue: { get: () => null } }],
+ [LocaleService, { useValue: { t: (key: string) => key } }],
+ [ICommandService, { useValue: { executeCommand: async () => true } }],
+ [ILayoutService, { useValue: { focus: () => {} } }],
+ [IShortcutService, { useValue: { shortcutChanged$: new Subject(), getShortcutDisplayOfCommand: () => null } }],
+ [IDialogService, { useValue: { getDialogs$: () => new Subject() } }],
+ [ISidebarService, { useValue: { sidebarOptions$: new Subject() } }],
+ ]);
+ injectors.push(injector);
+ const ConnectedGrid = connectInjector(RibbonGrid, injector) as ComponentType<{ groups: IMenuSchema[]; title: string }>;
+ const result = render(<ConnectedGrid groups={groups} title="Start" />);
+ resize();
+ return { ...result, ConnectedGrid };
+}
+
+function createGroups(): IMenuSchema[] {
+ return ['clipboard', 'font', 'layout'].map((key, index) => ({
+ key,
+ title: key,
+ order: index,
+ children: [0, 1].map((i) => ({
+ key: `${key}-${i}`,
+ order: i,
+ item: { id: `${key}-${i}`, type: MenuItemType.BUTTON, title: `${key}-${i}` },
+ gridLayout: { row: 1, column: i + 1, rowSpan: 2 },
+ })),
+ }));
+}
+
+function resize() {
+ act(() => resizeCallbacks.forEach((callback) => callback([], {} as ResizeObserver)));
+}
+
+beforeEach(() => {
+ availableWidth = 250;
+ resizeCallbacks = [];
+ groupWidths = {};
+ vi.stubGlobal('ResizeObserver', class {
+ constructor(callback: ResizeObserverCallback) { resizeCallbacks.push(callback); }
+ observe() {}
+ disconnect() {}
+ });
+ vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockImplementation(function (this: HTMLElement) {
+ return this.dataset.uComp === 'ribbon-grid-toolbar' ? availableWidth : 0;
+ });
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(function (this: HTMLElement) {
+ return { width: this.dataset.groupKey ? groupWidths[this.dataset.groupKey] ?? 100 : 64 } as DOMRect;
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ injectors.splice(0).forEach((injector) => injector.dispose());
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+describe('RibbonGrid overflow', () => {
+ it('reserves More space, moves whole groups, and restores them when space returns', () => {
+ const { getByRole, queryByRole } = mountGrid(createGroups());
+ const toolbar = getByRole('toolbar');
+ expect(within(toolbar).getByRole('button', { name: 'clipboard-1' })).toBeTruthy();
+ expect(within(toolbar).queryByRole('button', { name: 'font-0' })).toBeNull();
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ const popup = getByRole('dialog', { name: 'ui.ribbon.more' });
+ for (const name of ['font-0', 'font-1', 'layout-0', 'layout-1']) {
+ expect(within(popup).getByRole('button', { name })).toBeTruthy();
+ }
+ expect(within(popup).queryByRole('button', { name: 'clipboard-0' })).toBeNull();
+
+ availableWidth = 300;
+ resize();
+ expect(queryByRole('button', { name: 'ui.ribbon.more' })).toBeNull();
+ expect(queryByRole('dialog')).toBeNull();
+ expect(within(toolbar).getAllByRole('button')).toHaveLength(6);
+ });
+
+ it('remeasures changing group widths without dropping later groups', () => {
+ availableWidth = 300;
+ const { getByRole, queryByRole } = mountGrid(createGroups());
+ groupWidths.font = 180;
+ resize();
+ expect(within(getByRole('toolbar')).queryByRole('button', { name: 'font-0' })).toBeNull();
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ expect(within(getByRole('dialog')).getByRole('button', { name: 'layout-1' })).toBeTruthy();
+ groupWidths.font = 100;
+ resize();
+ expect(queryByRole('button', { name: 'ui.ribbon.more' })).toBeNull();
+ });
+
+ it('removes stale overflow when the active menu changes, including an empty menu', () => {
+ const { getByRole, queryByRole, rerender, ConnectedGrid } = mountGrid(createGroups());
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ rerender(<ConnectedGrid groups={[createGroups()[2]]} title="View" />);
+ resize();
+ expect(queryByRole('dialog')).toBeNull();
+ expect(getByRole('button', { name: 'layout-0' })).toBeTruthy();
+ rerender(<ConnectedGrid groups={[]} title="View" />);
+ expect(queryByRole('button')).toBeNull();
+ });
+});
diff --git a/packages/ui/src/views/components/ribbon/__tests__/RibbonOverflow.spec.tsx b/packages/ui/src/views/components/ribbon/__tests__/RibbonOverflow.spec.tsx
new file mode 100644
index 0000000000..b5d54518e6
--- /dev/null
+++ b/packages/ui/src/views/components/ribbon/__tests__/RibbonOverflow.spec.tsx
@@ -0,0 +1,147 @@
+/**
+ * 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.
+ */
+
+/**
+ * @vitest-environment jsdom
+ */
+
+import type { ComponentType } from 'react';
+import { act, cleanup, fireEvent, render, waitFor, within } from '@testing-library/react';
+import { ContextService, ICommandService, IContextService, ILogService, Injector, IUniverInstanceService, LocaleService, UniverInstanceService } from '@univerjs/core';
+import { BehaviorSubject, Subject } from 'rxjs';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import type { IMenuSchema } from '../../../../services/menu/menu-manager.service';
+import { ComponentManager } from '../../../../common/component-manager';
+import { IconManager } from '../../../../common/icon-manager';
+import { IDialogService } from '../../../../services/dialog/dialog.service';
+import { ILayoutService } from '../../../../services/layout/layout.service';
+import { MenuItemType } from '../../../../services/menu/menu';
+import { IMenuManagerService } from '../../../../services/menu/menu-manager.service';
+import { IShortcutService } from '../../../../services/shortcut/shortcut.service';
+import { ISidebarService } from '../../../../services/sidebar/sidebar.service';
+import { connectInjector } from '../../../../utils/di';
+import { RibbonOverflow } from '../RibbonOverflow';
+
+const injectors: Injector[] = [];
+
+function mountOverflow(groups: IMenuSchema[]) {
+ const sidebarOptions$ = new Subject<{ visible: boolean }>();
+ const dialogs$ = new Subject<Array<{ id: string; open: boolean }>>();
+ const executeCommand = vi.fn(async () => true);
+ const injector = new Injector([
+ [ComponentManager],
+ [IconManager, { useValue: { get: () => null } }],
+ [LocaleService, { useValue: { t: (key: string) => key } }],
+ [ICommandService, { useValue: { executeCommand } }],
+ [ILayoutService, { useValue: { focus: () => document.getElementById('editor')?.focus() } }],
+ [IContextService, { useClass: ContextService }],
+ [ILogService, { useValue: { warn: () => {} } }],
+ [IUniverInstanceService, { useClass: UniverInstanceService }],
+ [IMenuManagerService, { useValue: { menuChanged$: new Subject(), getMenuByPositionKey: () => [] } }],
+ [IShortcutService, { useValue: { shortcutChanged$: new Subject(), getShortcutDisplayOfCommand: () => null, forceEscape: () => ({ dispose: () => {} }) } }],
+ [IDialogService, { useValue: { getDialogs$: () => dialogs$ } }],
+ [ISidebarService, { useValue: { sidebarOptions$ } }],
+ ]);
+ injectors.push(injector);
+ injector.get(ComponentManager).register('FontField', () => <input aria-label="Font" defaultValue="Arial" />);
+ const ConnectedOverflow = connectInjector(RibbonOverflow, injector) as ComponentType<{ groups: IMenuSchema[]; grid?: boolean }>;
+ return { ...render(
+ <>
+ <input id="editor" aria-label="Editor" />
+ <ConnectedOverflow groups={groups} grid />
+ </>
+ ), executeCommand, sidebarOptions$, dialogs$, ConnectedOverflow };
+}
+
+function createGroups(disabled$ = new BehaviorSubject(false)): IMenuSchema[] {
+ return [{
+ key: 'format',
+ title: 'Formatting',
+ order: 0,
+ children: [
+ { key: 'bold', order: 0, item: { id: 'bold', type: MenuItemType.BUTTON, title: 'Bold', disabled$ } },
+ { key: 'font', order: 1, item: { id: 'font', type: MenuItemType.SELECTOR, tooltip: 'Font family', label: 'FontField' } },
+ { key: 'alignment', order: 2, item: { id: 'alignment', type: MenuItemType.SELECTOR, title: 'Alignment', selections: [{ label: 'Left', value: 'left' }] } },
+ ],
+ }];
+}
+
+afterEach(() => {
+ cleanup();
+ injectors.splice(0).forEach((injector) => injector.dispose());
+});
+
+describe('RibbonOverflow', () => {
+ it('keeps formatting available after editor focus and respects live disabled state', () => {
+ const disabled$ = new BehaviorSubject(false);
+ const { getByRole, executeCommand } = mountOverflow(createGroups(disabled$));
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ fireEvent.click(getByRole('button', { name: 'Bold' }));
+ expect(executeCommand).toHaveBeenCalledWith('bold', undefined);
+ expect(document.activeElement).toBe(getByRole('textbox', { name: 'Editor' }));
+ expect(getByRole('dialog', { name: 'ui.ribbon.more' })).toBeTruthy();
+ act(() => disabled$.next(true));
+ fireEvent.click(getByRole('button', { name: 'Bold' }));
+ expect(executeCommand).toHaveBeenCalledTimes(1);
+ });
+
+ it('preserves custom controls without duplicating their label', () => {
+ const { getByRole, queryByText } = mountOverflow(createGroups());
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ expect(getByRole('textbox', { name: 'Font' }).getAttribute('value')).toBe('Arial');
+ expect(queryByText('Font family')).toBeNull();
+ });
+
+ it('closes nested selectors before More and returns keyboard focus to their triggers', async () => {
+ const { getByRole, queryByRole } = mountOverflow(createGroups());
+ const more = getByRole('button', { name: 'ui.ribbon.more' });
+ more.focus();
+ fireEvent.keyDown(more, { key: 'Enter' });
+ fireEvent.click(more);
+ const alignment = getByRole('button', { name: 'Alignment' });
+ alignment.focus();
+ fireEvent.keyDown(alignment, { key: 'Enter' });
+ expect(getByRole('menuitem', { name: 'Left' })).toBeTruthy();
+ fireEvent.keyDown(getByRole('menu'), { key: 'Escape' });
+ await waitFor(() => expect(queryByRole('menu')).toBeNull());
+ await waitFor(() => expect(document.activeElement).toBe(alignment));
+ expect(getByRole('dialog', { name: 'ui.ribbon.more' })).toBeTruthy();
+ fireEvent.keyDown(alignment, { key: 'Escape' });
+ await waitFor(() => expect(queryByRole('dialog')).toBeNull());
+ await waitFor(() => expect(document.activeElement).toBe(more));
+ });
+
+ it.each(['sidebar', 'dialog'] as const)('closes when an independent %s opens', async (surface) => {
+ const { getByRole, queryByRole, sidebarOptions$, dialogs$ } = mountOverflow(createGroups());
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ act(() => {
+ if (surface === 'sidebar') sidebarOptions$.next({ visible: true });
+ else dialogs$.next([{ id: 'format', open: true }]);
+ });
+ await waitFor(() => expect(queryByRole('dialog')).toBeNull());
+ });
+
+ it('replaces an open menu when its groups change', () => {
+ const { getByRole, queryByRole, rerender, ConnectedOverflow } = mountOverflow(createGroups());
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ rerender(<ConnectedOverflow groups={[{ key: 'new', order: 0, title: 'New group', children: [{ key: 'new-action', order: 0, item: { id: 'new-action', type: MenuItemType.BUTTON, title: 'New action' } }] }]} />);
+ expect(queryByRole('dialog')).toBeNull();
+ fireEvent.click(getByRole('button', { name: 'ui.ribbon.more' }));
+ const popup = getByRole('dialog');
+ expect(within(popup).queryByRole('button', { name: 'Bold' })).toBeNull();
+ expect(within(popup).getByRole('button', { name: 'New action' })).toBeTruthy();
+ });
+});
diff --git a/packages/ui/src/views/components/ribbon/__tests__/ToolbarItem.spec.tsx b/packages/ui/src/views/components/ribbon/__tests__/ToolbarItem.spec.tsx
index 364e07166c..ddf76e8769 100644
--- a/packages/ui/src/views/components/ribbon/__tests__/ToolbarItem.spec.tsx
+++ b/packages/ui/src/views/components/ribbon/__tests__/ToolbarItem.spec.tsx
@@ -15,7 +15,6 @@
*/
import type { ComponentType, ReactElement } from 'react';
-import type { IIconProps } from '../../../../common/icon-manager';
import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react';
import {
ContextService,
@@ -29,6 +28,7 @@ import {
} from '@univerjs/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { afterEach, describe, expect, it } from 'vitest';
+import type { IIconProps } from '../../../../common/icon-manager';
import { ComponentManager } from '../../../../common/component-manager';
import { IconManager } from '../../../../common/icon-manager';
import { ILayoutService } from '../../../../services/layout/layout.service';
@@ -252,6 +252,25 @@ describe('ToolbarItem', () => {
expect(getByText('Financial')).toBeTruthy();
});
+ it('keeps icon-only overflow selectors named and keyboard-operable without visible titles', async () => {
+ const { getByRole, findByText } = renderWithDependencies(
+ <ToolbarItem
+ id="test-overflow-selector"
+ type={MenuItemType.SELECTOR}
+ icon="TestIcon"
+ title="Alignment"
+ selections={[{ label: 'Align left', value: 'left' }]}
+ grid
+ overflow
+ />
+ );
+ const trigger = getByRole('button', { name: 'Alignment' });
+ expect(trigger.textContent).toBe('');
+ trigger.focus();
+ fireEvent.keyDown(trigger, { key: 'Enter' });
+ expect(await findByText('Align left')).toBeTruthy();
+ });
+
it('does not wrap an interactive custom button label in another button', () => {
const { container } = renderWithDependencies(
<ToolbarItem
diff --git a/packages/ui/src/views/components/ribbon/hook.ts b/packages/ui/src/views/components/ribbon/hook.ts
index b825fda00e..c9783d31e1 100644
--- a/packages/ui/src/views/components/ribbon/hook.ts
+++ b/packages/ui/src/views/components/ribbon/hook.ts
@@ -15,21 +15,19 @@
*/
import type { Observable } from 'rxjs';
-import type { IDisplayMenuItem, IMenuItem } from '../../../services/menu/menu';
import { useMemo } from 'react';
import { EMPTY, map, merge, of, startWith } from 'rxjs';
+import type { IDisplayMenuItem, IMenuItem } from '../../../services/menu/menu';
import { isMenuButtonSelectorItem } from '../../../services/menu/menu';
import { IShortcutService } from '../../../services/shortcut/shortcut.service';
import { useDependency, useObservable } from '../../../utils/di';
export interface IToolbarItemStatus {
disabled: boolean;
- // eslint-disable-next-line ts/no-explicit-any
- value: any;
+ value: string | number | undefined;
activated: boolean;
hidden: boolean;
- // eslint-disable-next-line ts/no-explicit-any
- selectionsValue: any;
+ selectionsValue: string | number | undefined;
}
/**
@@ -40,8 +38,7 @@ export interface IToolbarItemStatus {
export function useToolbarItemStatus(menuItem: IDisplayMenuItem<IMenuItem>): IToolbarItemStatus {
const { disabled$, hidden$, activated$, value$ } = menuItem;
- // eslint-disable-next-line ts/no-explicit-any
- let selectionsValue$: Observable<any> | undefined;
+ let selectionsValue$: Observable<string | number | undefined> | undefined;
if (isMenuButtonSelectorItem(menuItem)) {
const { selections } = menuItem;
diff --git a/packages/ui/src/views/components/ribbon/ribbon-grid-layout.ts b/packages/ui/src/views/components/ribbon/ribbon-grid-layout.ts
index e45e52aa41..4e2cb1a1b8 100644
--- a/packages/ui/src/views/components/ribbon/ribbon-grid-layout.ts
+++ b/packages/ui/src/views/components/ribbon/ribbon-grid-layout.ts
@@ -46,10 +46,7 @@ export function placeRibbonGridItems(items: IMenuSchema[]): IRibbonGridPlacement
const cells = getCells(layout.row, layout.column, rowSpan, columnSpan);
if (!isValidGridGeometry(layout, rowSpan, cells)) {
- // eslint-disable-next-line node/prefer-global/process
- if (process.env.NODE_ENV !== 'production') {
- globalThis.console.warn(`[RibbonGrid] Invalid gridLayout for "${item.key}"; using fallback placement.`);
- }
+ globalThis.console.warn(`[RibbonGrid] Invalid gridLayout for "${item.key}"; using fallback placement.`);
fallbackItems.push({ item });
continue;
}