replace jQuery selectors with Refs

pull/1034/head
Vincent 5 years ago
parent 866196315e
commit 0b16f5965b

@ -15,6 +15,8 @@ interface State {
} }
export class SessionPasswordPrompt extends React.PureComponent<{}, State> { export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
private readonly inputRef: React.RefObject<HTMLInputElement>;
constructor(props: any) { constructor(props: any) {
super(props); super(props);
@ -29,10 +31,12 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
this.initLogin = this.initLogin.bind(this); this.initLogin = this.initLogin.bind(this);
this.initClearDataView = this.initClearDataView.bind(this); this.initClearDataView = this.initClearDataView.bind(this);
this.inputRef = React.createRef();
} }
public componentDidMount() { public componentDidMount() {
setTimeout(() => $('#password-prompt-input').focus(), 100); (this.inputRef.current as HTMLInputElement).focus();
} }
public render() { public render() {
@ -65,6 +69,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
onKeyUp={this.onKeyUp} onKeyUp={this.onKeyUp}
maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH} maxLength={window.CONSTANTS.MAX_PASSWORD_LENGTH}
onPaste={this.onPaste} onPaste={this.onPaste}
ref={this.inputRef}
/> />
); );
const infoIcon = this.state.clearDataView ? ( 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; return false;
} }
@ -157,7 +162,7 @@ export class SessionPasswordPrompt extends React.PureComponent<{}, State> {
} }
private async initLogin() { private async initLogin() {
const passPhrase = String($('#password-prompt-input').val()); const passPhrase = String((this.inputRef.current as HTMLInputElement).value);
await this.onLogin(passPhrase); await this.onLogin(passPhrase);
} }

Loading…
Cancel
Save