question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

when entering text the focus of input is lost

See original GitHub issue

Hi, clicking This is what I get.

My code is:

For the step:

const steps = [
    {
      selector: '#campaign_step',
      content: ({ goTo }) => (
        <div>
            <p>{i18n.leaders['Welcome to Leaders Market, start by entering the name of the campaign you\'ll be working on']}</p>
            <p>{i18n.leaders['For example: New sunglasses campaign']}</p>
            
          <button
            className="btn btn-adv-teal"
            onClick={() => goTo(1)} >
            {i18n.leaders['Next step']}
          </button>
        </div>
      ),
    //   stepInteraction:true,
      position:'right',
      action: node => {
        // by using this, focus trap is temporary disabled
        node.children[1].focus()
        console.log(node)
      },
    },
]

The Tour:

<div className="rtl">
    <Tour
            // closeWithMask={true}
            disableKeyboardNavigation={true}
            // disableInteraction={false}
            onAfterOpen={this.disableBody}
            onBeforeClose={this.enableBody}
            steps={steps}
            rounded={5}
            showNavigation={false}
            showButtons={false}
            isOpen={this.state.tourOpen}
            onRequestClose={this.closeTour} 
            />
</div>

For the input:

<div id="campaign_step">
      <h4
        className={this.state.errors.campaign_name && 'help-block-error-bold'}
      >
        {i18n.leaders['Campaign name']}
      </h4>
      <input
        id="campaign_name"
        type="text"
        tabIndex="1"
        onChange={value => {
          if (value) {
            document.getElementById('camp_name').textContent =
              value.target.value
          }
          this.setState({
            activityEdit: {
              ...this.state.activityEdit,
              name: value.target.value,
            },
          })
        }}
        onBlur={value => {
          let campaignError = value.target.value == '' ? true : false

          if (campaignError !== this.state.errors.campaign_name) {
            this.setState({
              errors: {
                ...this.state.errors,
                campaign_name: campaignError,
              },
            })
          }
        }}
        className="form-control form-control-adv adv-input-field"
        name="campaign_name"
        // placeholder={i18n.leaders['Campaign name']}
        value={this.state.activityEdit.name}
      />
    </div>

Thanks a lot!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elrumordelaluzcommented, Apr 7, 2020

Hi @Alpa84, You are re-rendering the Component where the Tour is in, so with each state change, you are re-rendering an open Tour, and this is the reason why you are loosing focus on the input.

Try separating components like in this fork

0reactions
wsz7777commented, Jan 26, 2021

I use disableFocusLock as true can fix this problem. #209

Read more comments on GitHub >

github_iconTop Results From Across the Web

In React ES6, why does the input field lose focus after typing a ...
When your onChange event fires, the callback calls setState with the new title value, which gets passed to your text field as a...
Read more >
React Text Input Losing Focus After Each Keypress
Click back into the text input. Then type the final 'o'. Obviously that is messed up. The problem was, I was defining a...
Read more >
Focusing: focus/blur - The Modern JavaScript Tutorial
Losing the focus generally means: “the data has been entered”, so we can run the code to check it or even to save...
Read more >
React.js loses input focus on typing
I recently stumbled upon an interesting problem. React.js was loosing focus on an input while the user was typing. Here is a video...
Read more >
.focusout() | jQuery API Documentation
Type : Anything ... Watch for a loss of focus to occur inside paragraphs and note the ... "#focus-count" ).text( "focusout fired: "...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found