Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot automatically focus TextInput within DialogExtension modal #330

Closed
heyitstowler opened this issue Nov 5, 2019 · 2 comments
Closed
Assignees
Labels
bug Something isn't working as expected needs review Proposal/bug that needs to be reviewed by maintainers v4 Changes that will be delivered in the version 4

Comments

@heyitstowler
Copy link
Contributor

It seems that you cannot automatically focus a TextInput component within a DialogExtension modal.

Repro:

  • Create a sidebar extension using create-contentful-extension and begin development

Using autoFocus prop

  • In the generated DialogExtension component, add a TextInput component, passing the prop autoFocus
  • When extension rebuilds, click the button that opens the dialog

Expected: TextInput automatically focuses, enabling typing immediately
Actual: TextInput does not focus, requiring a click to begin typing

Using inputRef and focusing in componentDidMount

  • In the generated DialogExtension component, add a constructor:
 constructor() {
    super()
    this.input = React.createRef()
  }
  • and a componentDidMount:
  componentDidMount(){
    this.input.current.focus()
  }
  • In the Text input, pass this.input as the inputRef prop to the TextInput component

  • When extension rebuilds, click the button that opens the dialog

Expected: TextInput automatically focuses, enabling typing immediately
Actual: TextInput does not focus, requiring a click to begin typing

You can confirm refs are passing correctly by adding a Button component with the following onClick prop:
() => this.input.current.focus()
Expected: On click, input gains focus
Actual: On click, input gains focus

@wichniowski
Copy link
Contributor

Hey, @heyitstowler thanks for bringing this up! It seems like some other element is taking away the focus after this component is mounted. I'll look into this and let you know as soon as this is fixed!

@wichniowski wichniowski added the bug Something isn't working as expected label Nov 12, 2019
@gui-santos gui-santos added the needs review Proposal/bug that needs to be reviewed by maintainers label Apr 8, 2021
@burakukula burakukula added the v4 Changes that will be delivered in the version 4 label Jun 25, 2021
@suevalov
Copy link
Contributor

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected needs review Proposal/bug that needs to be reviewed by maintainers v4 Changes that will be delivered in the version 4
Projects
None yet
Development

No branches or pull requests

5 participants