Skip to content

Commit 2d7e1ab

Browse files
committed
Merge branch 'upstream-development'
2 parents 0b4cae5 + b6fda25 commit 2d7e1ab

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

app/src/ui/app-menu/app-menu.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ export class AppMenu extends React.Component<IAppMenuProps, {}> {
7777
*/
7878
private expandCollapseTimer: number | null = null
7979

80+
/**
81+
* Refs to the menu pane elements, indexed by depth. Used to restore
82+
* focus when navigating back from a submenu with the left arrow key.
83+
*/
84+
private menuPaneRefs: Map<number, HTMLDivElement | null> = new Map()
85+
8086
private onItemClicked = (
8187
depth: number,
8288
item: MenuItem,
@@ -127,6 +133,13 @@ export class AppMenu extends React.Component<IAppMenuProps, {}> {
127133
menu.withClosedMenu(this.props.state[depth])
128134
)
129135

136+
// Restore focus to the parent menu pane to prevent the menu bar
137+
// from detecting focus loss and closing the entire menu
138+
const parentPane = this.menuPaneRefs.get(depth - 1)
139+
if (parentPane) {
140+
parentPane.focus()
141+
}
142+
130143
event.preventDefault()
131144
}
132145
} else if (event.key === 'ArrowRight') {
@@ -211,6 +224,10 @@ export class AppMenu extends React.Component<IAppMenuProps, {}> {
211224
}
212225
}
213226

227+
private onMenuPaneRef = (depth: number, element: HTMLDivElement | null) => {
228+
this.menuPaneRefs.set(depth, element)
229+
}
230+
214231
private renderMenuPane(depth: number, menu: IMenu): JSX.Element {
215232
// If the menu doesn't have an id it's the root menu
216233
const key = menu.id || '@'
@@ -230,6 +247,7 @@ export class AppMenu extends React.Component<IAppMenuProps, {}> {
230247
enableAccessKeyNavigation={this.props.enableAccessKeyNavigation}
231248
onClearSelection={this.onClearSelection}
232249
ariaLabelledby={this.props.ariaLabelledby}
250+
onRef={this.onMenuPaneRef}
233251
/>
234252
)
235253
}

app/src/ui/app-menu/menu-pane.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,16 @@ interface IMenuPaneProps {
9898
readonly allowFirstCharacterNavigation?: boolean
9999

100100
readonly renderLabel?: (item: MenuItem) => JSX.Element | undefined
101+
102+
/** Optional callback for capturing a ref to the menu pane element */
103+
readonly onRef?: (depth: number, element: HTMLDivElement | null) => void
101104
}
102105

103106
export class MenuPane extends React.Component<IMenuPaneProps> {
107+
private onMenuPaneRef = (element: HTMLDivElement | null) => {
108+
this.props.onRef?.(this.props.depth, element)
109+
}
110+
104111
private onRowClick = (
105112
item: MenuItem,
106113
event: React.MouseEvent<HTMLDivElement>
@@ -258,6 +265,7 @@ export class MenuPane extends React.Component<IMenuPaneProps> {
258265
*/
259266
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
260267
<div
268+
ref={this.onMenuPaneRef}
261269
className={className}
262270
onMouseEnter={this.onMouseEnter}
263271
onKeyDown={this.onKeyDown}

app/src/ui/changes/commit-message-avatar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ export class CommitMessageAvatar extends React.Component<
424424
}
425425
anchorPosition={PopoverAnchorPosition.RightBottom}
426426
decoration={PopoverDecoration.Balloon}
427+
onMousedownOutside={this.closePopover}
427428
onClickOutside={this.closePopover}
428429
ariaLabelledby="commit-avatar-popover-header"
429430
>

0 commit comments

Comments
 (0)