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.

6.9.2: Header Filter Input Losing Focus After Keydown

See original GitHub issue

In 6.9.2, the open field text inputs in the header columns are losing focus after you press a key. I believe this came in with the 6.9.0 changes.

As a sidenote, I replaced the regular text inputs with a search input, which is nice because you get the ‘clear’ button and it doesn’t trigger the browser’s autocomplete. Pretty sure that has nothing to do with losing focus, but I’ll keep testing.

FilterComponent={({ filter, onChange, column }) => (
  <input
    className="w-100"
    type="search"
    placeholder={column.Placeholder}
    value={filter ? filter.value : ''}
    onChange={event => onChange(event.target.value)}
  />
)}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

9reactions
boonepcommented, Mar 4, 2019

@tannerlinsley was correct. Moving the custom component from the render phase solved my issues.

const CustomTableFilter = ({filter, onChange}) => {
  return (
    <Input type="search" value={filter ? filter.value : ''}
      onChange={event => (event ? onChange(event.currentTarget.value) : "")}/>
  );
};

render() {
  return (
     <ReactTable
        columns={[
          {
            Filter: CustomTableFilter
          }
        ]}
     />
  );
}
1reaction
technicaltitchcommented, Apr 23, 2019

Moving the columns declaration out of the render method (and using an uncontrolled input) worked for me. (Just refactoring to an external function as @boonep suggested didn’t in my case.)

class AcmeCmp extends Component {
  columns = [
    {
      Header: 'header', accessor: 'acc', 
      Cell: row => (
        <input defaultValue={row.original.colId.value} 
          onChange={event => {
            const newValue = event.target.value;
            if (this.isTableValid(row.column.id, row.index, newValue)) {
              this.setState(({ data }) => ({data: [slice & insert newValue]}));
            } else {  // roll back value, as this is uncontrolled
              event.target.value = this.state.data[index][column].value;
            }
          }} />)
      },
      // other columns...
  ];
  isTableValid = (column, index, proposedValue) => { return true or false };
  render() {
    return (
        <ReactTable
          data={this.state.data}
          columns={this.columns} />
    )
  }
}

Mine wasn’t working because columns was declared within the render() function, so as @tannerlinsley pointed out (if my understanding is right) the original DOM elements were no longer accessible for React to diff with, so it re-rendered everything on every edit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

6.9.2: Header Filter Input Losing Focus After Keydown #1266
In 6.9.2, the open field text inputs in the header columns are losing focus after you press a key. I believe this came...
Read more >
react-table lost focus on filter? - Stack Overflow
Problem is the filter text field will lost focus after we type and even when we just touch the input (I know the...
Read more >
React Text Input Losing Focus After Each Keypress
This bug took me a while to figure out, so I thought I would share the cause and the fix. I had a...
Read more >
React Table Re-Renders, Losing Focus When Input Text In ...
In 6.9.2, the open field text inputs in the header columns are losing focus ... #22 submits the form after each keypress and...
Read more >
User's Guide Avizo Software 2019 | Thermo Fisher Scientific
This manual has been prepared for Thermo Fisher Scientific licensees solely for use in connection with software supplied by Thermo Fisher Scientific and....
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