Skip to content

Commit e4ab20d

Browse files
yanlingwang23Devtools-frontend LUCI CQ
authored andcommitted
[A11y] Add move left/right operation to tab context menu
Currently, users are unable to change the position of tab items in tab component using single point mode of operation. This fix introduces a "move left/right" option in the context menu, allowing users who have difficulty dragging tab items to change their positions with a click. Screenshot: https://imgur.com/a/cNAr7qE Bug: 383164782 Change-Id: I98e61c224b60f2be0d17e9f44599b783bac4fc66 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6086108 Reviewed-by: Simon Zünd <[email protected]> Reviewed-by: Nancy Li <[email protected]> Commit-Queue: Yanling Wang <[email protected]>
1 parent 0326038 commit e4ab20d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

front_end/ui/legacy/TabbedPane.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ const UIStrings = {
7575
*@description Indicates that a tab contains a preview feature (i.e., a beta / experimental feature).
7676
*/
7777
previewFeature: 'Preview feature',
78+
/**
79+
* @description Text to move a tab forwar.
80+
*/
81+
moveTabRight: 'Move right',
82+
/**
83+
* @description Text to move a tab backward.
84+
*/
85+
moveTabLeft: 'Move left',
7886
};
7987
const str_ = i18n.i18n.registerUIStrings('ui/legacy/TabbedPane.ts', UIStrings);
8088
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -387,6 +395,21 @@ export class TabbedPane extends Common.ObjectWrapper.eventMixin<EventTypes, type
387395
this.selectTab(this.tabs[nextIndex].id, true);
388396
}
389397

398+
getTabIndex(id: string): number {
399+
const index = this.tabs.indexOf((this.tabsById.get(id) as TabbedPaneTab));
400+
return index;
401+
}
402+
403+
moveTabBackward(id: string, index: number): void {
404+
this.insertBefore((this.tabsById.get(id) as TabbedPaneTab), index - 1);
405+
this.updateTabSlider();
406+
}
407+
408+
moveTabForward(id: string, index: number): void {
409+
this.insertBefore((this.tabsById.get(id) as TabbedPaneTab), index + 2);
410+
this.updateTabSlider();
411+
}
412+
390413
lastOpenedTabIds(tabsCount: number): string[] {
391414
function tabToTabId(tab: TabbedPaneTab): string {
392415
return tab.id;
@@ -1317,6 +1340,14 @@ export class TabbedPaneTab {
13171340
this.closeTabs(this.tabbedPane.tabsToTheRight(this.id));
13181341
}
13191342

1343+
function moveTabForward(this: TabbedPaneTab, tabIndex: number): void {
1344+
this.tabbedPane.moveTabForward(this.id, tabIndex);
1345+
}
1346+
1347+
function moveTabBackward(this: TabbedPaneTab, tabIndex: number): void {
1348+
this.tabbedPane.moveTabBackward(this.id, tabIndex);
1349+
}
1350+
13201351
const contextMenu = new ContextMenu(event);
13211352
if (this.closeable) {
13221353
contextMenu.defaultSection().appendItem(i18nString(UIStrings.close), close.bind(this), {jslogContext: 'close'});
@@ -1331,6 +1362,15 @@ export class TabbedPaneTab {
13311362
if (this.delegate) {
13321363
this.delegate.onContextMenu(this.id, contextMenu);
13331364
}
1365+
const tabIndex = this.tabbedPane.getTabIndex(this.id);
1366+
if (tabIndex > 0) {
1367+
contextMenu.defaultSection().appendItem(
1368+
i18nString(UIStrings.moveTabLeft), moveTabBackward.bind(this, tabIndex), {jslogContext: 'move-tab-backward'});
1369+
}
1370+
if (tabIndex < this.tabbedPane.tabsElement.childNodes.length - 1) {
1371+
contextMenu.defaultSection().appendItem(
1372+
i18nString(UIStrings.moveTabRight), moveTabForward.bind(this, tabIndex), {jslogContext: 'move-tab-forward'});
1373+
}
13341374
void contextMenu.show();
13351375
}
13361376

front_end/ui/visual_logging/KnownContextValues.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,8 @@ export const knownContextValues = new Set([
23142314
'mouseover',
23152315
'mouseup',
23162316
'mousewheel',
2317+
'move-tab-backward',
2318+
'move-tab-forward',
23172319
'move-to-bottom',
23182320
'move-to-top',
23192321
'mr',

0 commit comments

Comments
 (0)