fix autofocus on session passowrd login

pull/1884/head
audric 4 years ago
parent 728d5adda1
commit 3cdc5f1551

@ -5,6 +5,7 @@ import { SessionIcon, SessionIconType } from './icon';
import { SessionButton, SessionButtonColor, SessionButtonType } from './SessionButton';
import { Constants } from '../../session';
import { DefaultTheme, withTheme } from 'styled-components';
import autoBind from 'auto-bind';
interface State {
error: string;
@ -15,7 +16,7 @@ interface State {
export const MAX_LOGIN_TRIES = 3;
class SessionPasswordPromptInner extends React.PureComponent<{ theme: DefaultTheme }, State> {
private readonly inputRef: React.RefObject<HTMLInputElement>;
private inputRef?: any;
constructor(props: any) {
super(props);
@ -26,16 +27,14 @@ class SessionPasswordPromptInner extends React.PureComponent<{ theme: DefaultThe
clearDataView: false,
};
this.onKeyUp = this.onKeyUp.bind(this);
this.initLogin = this.initLogin.bind(this);
this.initClearDataView = this.initClearDataView.bind(this);
this.inputRef = React.createRef();
autoBind(this);
}
public componentDidMount() {
(this.inputRef.current as HTMLInputElement).focus();
console.warn('this.inputRef', this.inputRef);
setTimeout(() => {
this.inputRef?.focus();
}, 100);
}
public render() {
@ -63,7 +62,9 @@ class SessionPasswordPromptInner extends React.PureComponent<{ theme: DefaultThe
defaultValue=""
placeholder={' '}
onKeyUp={this.onKeyUp}
ref={this.inputRef}
ref={input => {
this.inputRef = input;
}}
/>
);
const infoIcon = this.state.clearDataView ? (
@ -138,7 +139,7 @@ class SessionPasswordPromptInner extends React.PureComponent<{ theme: DefaultThe
}
private async initLogin() {
const passPhrase = String((this.inputRef.current as HTMLInputElement).value);
const passPhrase = String((this.inputRef as HTMLInputElement).value);
await this.onLogin(passPhrase);
}

Loading…
Cancel
Save