From ed660ccd642240fad8b34aa9a0c3f6981494c62b Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Thu, 5 Dec 2019 10:33:29 +0100 Subject: [PATCH] fixed the `input` focus when the view is activated Signed-off-by: Akos Kitta --- .../src/browser/monitor/monitor-widget.tsx | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx index 3204357d..92661874 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx @@ -88,6 +88,15 @@ export class MonitorWidget extends ReactWidget { this.update(); } + protected onActivateRequest(msg: Message): void { + super.onActivateRequest(msg); + (this.focusNode || this.node).focus(); + } + + protected onFocusResolved = (element: HTMLElement | undefined) => { + this.focusNode = element; + } + protected get lineEndings(): OptionsType> { return [ { @@ -121,7 +130,9 @@ export class MonitorWidget extends ReactWidget { return
- +
void + readonly onSend: (text: string) => void; + readonly resolveFocus: (element: HTMLElement | undefined) => void; } export interface State { value: string; @@ -171,8 +183,6 @@ export namespace SerialMonitorSendField { export class SerialMonitorSendField extends React.Component { - protected inputField: HTMLInputElement | null; - constructor(props: SerialMonitorSendField.Props) { super(props); this.state = { value: '' }; @@ -181,17 +191,11 @@ export class SerialMonitorSendField extends React.Component this.inputField = ref} + ref={this.setRef} id='serial-monitor-send' type='text' autoComplete='off' @@ -201,6 +205,12 @@ export class SerialMonitorSendField extends React.Component } + protected setRef = (element: HTMLElement | null) => { + if (this.props.resolveFocus) { + this.props.resolveFocus(element || undefined); + } + } + protected handleChange(event: React.ChangeEvent) { this.setState({ value: event.target.value }); }