From 0b16f5965bd380425935a97f49cd0b988b74c474 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 31 Mar 2020 14:49:54 +1100 Subject: [PATCH] replace jQuery selectors with Refs --- ts/components/session/SessionPasswordPrompt.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ts/components/session/SessionPasswordPrompt.tsx b/ts/components/session/SessionPasswordPrompt.tsx index 4ef1ae48d..2c8926dfd 100644 --- a/ts/components/session/SessionPasswordPrompt.tsx +++ b/ts/components/session/SessionPasswordPrompt.tsx @@ -15,6 +15,8 @@ interface State { } export class SessionPasswordPrompt extends React.PureComponent<{}, State> { + private readonly inputRef: React.RefObject; + constructor(props: any) { super(props); @@ -29,10 +31,12 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> { this.initLogin = this.initLogin.bind(this); this.initClearDataView = this.initClearDataView.bind(this); + + this.inputRef = React.createRef(); } public componentDidMount() { - setTimeout(() => $('#password-prompt-input').focus(), 100); + (this.inputRef.current as HTMLInputElement).focus(); } public render() { @@ -65,6 +69,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> { onKeyUp={this.onKeyUp} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} onPaste={this.onPaste} + ref={this.inputRef} /> ); const infoIcon = this.state.clearDataView ? ( @@ -137,7 +142,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> { }); } - // Prevent pating into input + // Prevent pasting into input return false; } @@ -157,7 +162,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> { } private async initLogin() { - const passPhrase = String($('#password-prompt-input').val()); + const passPhrase = String((this.inputRef.current as HTMLInputElement).value); await this.onLogin(passPhrase); }