forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
52 lines (44 loc) · 1.12 KB
/
index.tsx
File metadata and controls
52 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React from 'react';
import { ENTER } from '../../../utils/keycodes';
import { Container, InputContainer } from './elements';
export interface Props {
onChange: (value: string) => void;
onConfirm: () => void;
url?: string;
}
export default class extends React.PureComponent<Props> {
input: HTMLInputElement | undefined;
onChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
const { onChange } = this.props;
onChange(evt.target.value);
};
handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
const { onConfirm } = this.props;
if (e.keyCode === ENTER) {
onConfirm();
}
};
focus = () => {
if (this.input) {
this.input.focus();
}
};
render() {
const { url = '' } = this.props;
return (
<Container onClick={this.focus}>
<InputContainer>
<input
ref={e => {
this.input = e;
}}
onChange={this.onChange}
onKeyDown={this.handleKeyDown}
value={url}
aria-label="Address Bar Input"
/>
</InputContainer>
</Container>
);
}
}