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.

inputbox in customFilterComponent lose focus

See original GitHub issue

in fact this is a repetition of another issue, which was closed without a solution: https://github.com/GriddleGriddle/Griddle/issues/475

Griddle version

1.9.0

Expected Behavior

input should not lose focus.

Actual Behavior

input loses focus

Steps to reproduce


export class SearchStringFilter extends React.Component<TProps, {}> {

  render() {

    return (
      <input
        value={this.props.searchString}
        onChange={this.props.onChange} //dispatch("SOME_ACTION_FOR_CHANGE_VALUE") 
      /> 
    );
  }
}

<Griddle
    components={{
        Filter: SomeCustomFilter
    }}

I use my own redux store and every time I send a new searchString to onChange event. But unfortunately the focus of the filter is lost. What could be the problem? maybe there is some kind of workaround?

note: I’ve read that re-initializing HOC inside a render function often leads to this problem, but that’s just my guess.

Don’t Use HOCs Inside the render Method React’s diffing algorithm (called reconciliation) uses component identity to determine whether it should update the existing subtree or throw it away and mount a new one. If the component returned from render is identical (===) to the component from the previous render, React recursively updates the subtree by diffing it with the new one. If they’re not equal, the previous subtree is unmounted completely. https://reactjs.org/docs/higher-order-components.html

I tried to find a problem with HOC in griddle but did not find it. At first sight everything is all right.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
radzikshcommented, Nov 14, 2017

@dahlbykI I found the reason:

  1. I had an event in my application that worked 1 time per second. (telemetry for a some timer)
  2. I used griddle version 1.9.0 since this is for some reason the last of the releases https://www.npmjs.com/package/griddle-react

when I started to look at the source code in my node_modules I noticed that componentWillReceiveProps looks like this: (raw)

 _createClass(Griddle, [{
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(nextProps) {
      var data = nextProps.data,
          pageProperties = nextProps.pageProperties,
          sortProperties = nextProps.sortProperties;


      this.store.dispatch(actions.updateState({ data: data, pageProperties: pageProperties, sortProperties: sortProperties }));
    }

so if an event occurs (and I have it happen 1 time per second), then the grid updates its state automatically and the focus is lost.

but in github it looks like this:

  componentWillReceiveProps(nextProps) {
    debugger;
    const newState = _.pickBy(nextProps, (value, key) => {
      return this.props[key] !== value;
    })

    // Only update the state if something has changed.
    if (Object.keys(newState).length > 0) {
     this.store.dispatch(actions.updateState(newState));
    }
  }

in this case, the state of the grid is updated only if some of the props has changed.

at this point I realized that my version is not the last and there is not this important update. I updated the version to 1.10.1 and the focus stopped being lost 😃

perhaps it is worth making a new release https://www.npmjs.com/package/griddle-react to version 1.10.1?

ps: @dahlbyk thanks a lot, your advice helped me narrow down the search.

0reactions
radzikshcommented, Nov 10, 2017
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 ...
In my component below, the input field loses focus after typing a character. While using Chrome's Inspector, it looks like the whole form...
Read more >
Input loses focus after each character typed [#3018362] - Drupal
Now the input loses focus after each character you type, so the autocomplete list pops up briefly and then disappears, and you have...
Read more >
onfocusout Event - W3Schools
The onfocusout event occurs when an element looses focus. The onfocusout event is often used on input fields. The onfocosout event is often...
Read more >
Textbox loses focus while composing emails
While using outlook.office.com to compose emails, the composition text-box will frequently lose focus, turning my text input into hotkeys ...
Read more >
Mysql lookup when input box loses focus - PHP - SitePoint
Hi! I'm creating a order sheet for my business using PHP and Mysql but I'm not sure of how to do something. My...
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