0

I have two MUI Select elements. After the user makes a selection on the first, I'd like the second to automatically get activated.

Here's the pseudo-code:

<Select native value={region}      onChange={selectRegion()}>
  {regions.map((r,i) => <option value={r.value} key={`${r.value}-${r.index}`}>)
</Select>
<Select multiple value={zone}>
  {zones.map((z,i) => <option value={z.value} key={`${z.value}-${z.index}`}>)
</Select>
...
const selectRegion(e) => {
  setRegion(e.target.value)
  let z = getZones(e.target.value)
  setZones(z)
  // This is where I want to focus on the Zone input
}
Travis Heeter
  • 13,002
  • 13
  • 87
  • 129

1 Answers1

0

Can you add a ref to the select component?

const selectRef = useRef(null)

<Select inputRef={selectRef} multiple value={zone}>
  {zones.map((z,i) => <option value={z.value} key={`${z.value}-${z.index}`}>)
</Select>
const selectRegion(e) => {
  setRegion(e.target.value)
  let z = getZones(e.target.value)
  setZones(z)
  // This is where I want to focus on the Zone input
  selectRef.current.focus()
}
coot3
  • 516
  • 3
  • 7