forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDropdownMenu.js
More file actions
51 lines (45 loc) · 1.56 KB
/
Copy pathDropdownMenu.js
File metadata and controls
51 lines (45 loc) · 1.56 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
import React, { useState, useRef, useEffect } from "react"
import ReactDOM from "react-dom"
import styled from "styled-components"
import OutlinedInput from "@material-ui/core/OutlinedInput"
import InputLabel from "@material-ui/core/InputLabel"
import MenuItem from "@material-ui/core/MenuItem"
import FormControl from "@material-ui/core/FormControl"
import Select from "@material-ui/core/Select"
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary"
import { withTranslation } from "react-i18next"
const StyledFormControl = styled(FormControl)`
width: 100%;
`
const DropdownMenu = ({ selectedVariant, setSelectedVariant, t }) => {
const [labelWidth, setLabelWidth] = useState(0)
const inputLabelRef = useRef(null)
useEffect(() => {
setLabelWidth(ReactDOM.findDOMNode(inputLabelRef.current).offsetWidth)
})
const handleChange = event => {
setSelectedVariant(event.target.value)
}
return (
<StyledFormControl variant="outlined">
<InputLabel ref={inputLabelRef} htmlFor="course-variant-select">
{t("whichCourse")}
</InputLabel>
<Select
value={selectedVariant}
onChange={handleChange}
input={
<OutlinedInput
labelWidth={labelWidth}
name="course-variant"
id="course-variant-select"
/>
}
>
<MenuItem value="i">Java Programming I</MenuItem>
<MenuItem value="ii">Java Programming II</MenuItem>
</Select>
</StyledFormControl>
)
}
export default withTranslation("user")(withSimpleErrorBoundary(DropdownMenu))