Skip to content

Commit

Permalink
[A11y] Add move left/right operation to tab context menu
Browse files Browse the repository at this point in the history
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 <szuend@chromium.org>
Reviewed-by: Nancy Li <nancyly@chromium.org>
Commit-Queue: Yanling Wang <yanlingwang@microsoft.com>
  • Loading branch information
yanlingwang23 authored and Devtools-frontend LUCI CQ committed Dec 13, 2024
1 parent 0326038 commit e4ab20d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions front_end/ui/legacy/TabbedPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ const UIStrings = {
*@description Indicates that a tab contains a preview feature (i.e., a beta / experimental feature).
*/
previewFeature: 'Preview feature',
/**
* @description Text to move a tab forwar.
*/
moveTabRight: 'Move right',
/**
* @description Text to move a tab backward.
*/
moveTabLeft: 'Move left',
};
const str_ = i18n.i18n.registerUIStrings('ui/legacy/TabbedPane.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
Expand Down Expand Up @@ -387,6 +395,21 @@ export class TabbedPane extends Common.ObjectWrapper.eventMixin<EventTypes, type
this.selectTab(this.tabs[nextIndex].id, true);
}

getTabIndex(id: string): number {
const index = this.tabs.indexOf((this.tabsById.get(id) as TabbedPaneTab));
return index;
}

moveTabBackward(id: string, index: number): void {
this.insertBefore((this.tabsById.get(id) as TabbedPaneTab), index - 1);
this.updateTabSlider();
}

moveTabForward(id: string, index: number): void {
this.insertBefore((this.tabsById.get(id) as TabbedPaneTab), index + 2);
this.updateTabSlider();
}

lastOpenedTabIds(tabsCount: number): string[] {
function tabToTabId(tab: TabbedPaneTab): string {
return tab.id;
Expand Down Expand Up @@ -1317,6 +1340,14 @@ export class TabbedPaneTab {
this.closeTabs(this.tabbedPane.tabsToTheRight(this.id));
}

function moveTabForward(this: TabbedPaneTab, tabIndex: number): void {
this.tabbedPane.moveTabForward(this.id, tabIndex);
}

function moveTabBackward(this: TabbedPaneTab, tabIndex: number): void {
this.tabbedPane.moveTabBackward(this.id, tabIndex);
}

const contextMenu = new ContextMenu(event);
if (this.closeable) {
contextMenu.defaultSection().appendItem(i18nString(UIStrings.close), close.bind(this), {jslogContext: 'close'});
Expand All @@ -1331,6 +1362,15 @@ export class TabbedPaneTab {
if (this.delegate) {
this.delegate.onContextMenu(this.id, contextMenu);
}
const tabIndex = this.tabbedPane.getTabIndex(this.id);
if (tabIndex > 0) {
contextMenu.defaultSection().appendItem(
i18nString(UIStrings.moveTabLeft), moveTabBackward.bind(this, tabIndex), {jslogContext: 'move-tab-backward'});
}
if (tabIndex < this.tabbedPane.tabsElement.childNodes.length - 1) {
contextMenu.defaultSection().appendItem(
i18nString(UIStrings.moveTabRight), moveTabForward.bind(this, tabIndex), {jslogContext: 'move-tab-forward'});
}
void contextMenu.show();
}

Expand Down
2 changes: 2 additions & 0 deletions front_end/ui/visual_logging/KnownContextValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,8 @@ export const knownContextValues = new Set([
'mouseover',
'mouseup',
'mousewheel',
'move-tab-backward',
'move-tab-forward',
'move-to-bottom',
'move-to-top',
'mr',
Expand Down

0 comments on commit e4ab20d

Please sign in to comment.