signavio / react-mentions

@mention people in a textarea
https://react-mentions.vercel.app
Other
2.42k stars 566 forks source link

Cannot manually focus using inputRef #655

Closed fredmanxu closed 1 year ago

fredmanxu commented 1 year ago

I tried this example, But inputRef is null.

My example code

import { MentionsInput, Mention } from 'react-mentions';

export default function MyInputBox() {
      const [inputValue, setInputValue] = useState('')

      let inputRef = React.createRef()

      return (
             <div>
                           <MentionsInput
                                      inputRef={inputRef}
                                      value={inputValue}
                                      a11ySuggestionsListLabel={"Suggested mentions"}
                            >
                                      <Mention
                                          trigger="@"
                                          data={[]}
                                          renderSuggestion={null}
                                       />
                            </MentionsInput>

                            <button onClick={()=>{
                                   inputRef.current.focus()
                            }}>
                                   focus programmatic
                             </button>
             </div>
      )
}

package.json

  "react": "^18.2.0",
  "react-mentions": "^4.4.7",