Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit cc27c4b

Browse files
committed
fix(plugins/plugin-client-common): sidecar does not resopnd to Escape reliably
1) escape does not close LeftNavSidecar reliably; this is due to an incorrect guard of isFixedWidth() around the onEscape registration Fixes #4774 2) escape closes sidecars in all tabs; we need to pay attention to whether the sidecar is part of the active KuiTab Fixes #4804
1 parent 43863f2 commit cc27c4b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

plugins/plugin-client-common/src/components/Client/TabContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ export default class TabContent extends React.PureComponent<Props, State> {
341341
return React.cloneElement(node, {
342342
key,
343343
uuid: this.props.uuid,
344+
active: this.props.active,
344345
width: this.state.sidecarWidth,
345346
willChangeSize: this.onWillChangeSize.bind(this),
346347
willLoseFocus: this.onWillLoseFocus.bind(this)

plugins/plugin-client-common/src/components/Views/Sidecar/BaseSidecar.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface SidecarOptions {
5252
export type Props = SidecarOptions & {
5353
uuid?: string
5454
tab?: KuiTab
55+
active?: boolean
5556
}
5657

5758
export interface SidecarHistoryEntry extends BaseHistoryEntry {
@@ -88,13 +89,11 @@ export abstract class BaseSidecar<
8889
super(props)
8990

9091
// Interpret Escape key as a toggle of the view's width
91-
if (!this.isFixedWidth()) {
92-
const onEscape = this.onEscape.bind(this)
93-
document.addEventListener('keydown', onEscape)
94-
this.cleaners.push(() => document.removeEventListener('keydown', onEscape))
95-
// ^^^ Note! keydown versus keyup is important (for now at
96-
// least; @starpit 20200408); see https://github.com/IBM/kui/issues/4215
97-
}
92+
const onEscape = this.onEscape.bind(this)
93+
document.addEventListener('keydown', onEscape)
94+
this.cleaners.push(() => document.removeEventListener('keydown', onEscape))
95+
// ^^^ Note! keydown versus keyup is important (for now at
96+
// least; @starpit 20200408); see https://github.com/IBM/kui/issues/4215
9897
}
9998

10099
public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
@@ -189,7 +188,13 @@ export abstract class BaseSidecar<
189188

190189
/** Escape key toggles sidecar visibility */
191190
private onEscape(evt: KeyboardEvent) {
192-
if (evt.key === 'Escape' && !document.getElementById('confirm-dialog') && !isPopup() && this.current) {
191+
if (
192+
evt.key === 'Escape' &&
193+
this.props.active &&
194+
!document.getElementById('confirm-dialog') &&
195+
!isPopup() &&
196+
this.current
197+
) {
193198
if (this.props.willChangeSize) {
194199
this.props.willChangeSize(this.props.width === Width.Closed ? this.defaultWidth() : Width.Closed)
195200
}

0 commit comments

Comments
 (0)