I've been using the "@material-ui/core": "4.11.2" package with "react": "16.8.6". In the TextField component when the select prop is true, I can't get the name property of the TextField from the event object in handleFocus function.
<TextField
id="standard-select-currency"
name="mySelectBox"
select
label="Select"
value={currency}
onChange={handleChange}
onFocus={handleFocus}
helperText="Please select your currency"
>
{currencies.map((option) => (
<MenuItem key={option.value} value={option.value}>
{option.label}
</MenuItem>
))}
</TextField>
Here is handleFocus and handleChange functions.
const handleChange = (event) => {
console.log(
"event.target ==>",
event.target,
"event.target.name ==>", // mySelectBox
event.target.name
);
};
const handleFocus = (event) => {
console.log(
"event.target ==>",
event.target,
"event.target.name ==>", // undefined
event.target.name
);
};
I create a complete example in this sandbox.