mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix crash in test mode for Dialog
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
4dd3f9d3fd
commit
b30ad5aa04
@ -11,7 +11,9 @@ import { disposeOnUnmount, observer } from "mobx-react";
|
|||||||
import { reaction } from "mobx";
|
import { reaction } from "mobx";
|
||||||
import { Animate } from "../animate";
|
import { Animate } from "../animate";
|
||||||
import { cssNames, noop, stopPropagation } from "../../utils";
|
import { cssNames, noop, stopPropagation } from "../../utils";
|
||||||
import { navigation } from "../../navigation";
|
import type { ObservableHistory } from "mobx-observable-history";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
|
||||||
|
|
||||||
// todo: refactor + handle animation-end in props.onClose()?
|
// todo: refactor + handle animation-end in props.onClose()?
|
||||||
|
|
||||||
@ -33,12 +35,16 @@ interface DialogState {
|
|||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
interface Dependencies {
|
||||||
export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
navigation: ObservableHistory<unknown>;
|
||||||
private contentElem: HTMLElement | null = null;
|
}
|
||||||
ref = React.createRef<HTMLDivElement>();
|
|
||||||
|
|
||||||
static defaultProps: DialogProps = {
|
@observer
|
||||||
|
class NonInjectedDialog extends React.PureComponent<DialogProps & Dependencies & typeof NonInjectedDialog.defaultProps, DialogState> {
|
||||||
|
private readonly contentElem = React.createRef<HTMLDivElement>();
|
||||||
|
private readonly ref = React.createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
open: noop,
|
open: noop,
|
||||||
close: noop,
|
close: noop,
|
||||||
@ -67,7 +73,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => navigation.toString(), () => this.close()),
|
reaction(() => this.props.navigation.toString(), () => this.close()),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +137,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
|||||||
onClickOutside = (evt: MouseEvent) => {
|
onClickOutside = (evt: MouseEvent) => {
|
||||||
const target = evt.target as HTMLElement;
|
const target = evt.target as HTMLElement;
|
||||||
|
|
||||||
if (!this.contentElem?.contains(target)) {
|
if (!this.contentElem.current?.contains(target)) {
|
||||||
this.close();
|
this.close();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
}
|
}
|
||||||
@ -149,7 +155,10 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
|||||||
ref={this.ref}
|
ref={this.ref}
|
||||||
data-testid={testId}
|
data-testid={testId}
|
||||||
>
|
>
|
||||||
<div className="box" ref={e => this.contentElem = e}>
|
<div
|
||||||
|
className="box"
|
||||||
|
ref={this.contentElem}
|
||||||
|
>
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -168,3 +177,10 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
|
|||||||
return createPortal(dialog, document.body);
|
return createPortal(dialog, document.body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Dialog = withInjectables<Dependencies, DialogProps>((props) => <NonInjectedDialog {...props} />, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
navigation: di.inject(observableHistoryInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user