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.

this.refs.inputRef.focus is not a function

See original GitHub issue

I am using customEditor on TableHeaderColumn. The custom editor is a react-select component instead of any HTML input element.

It throw the following error whenever I click on the cell to render the editor:

TableEditColumn.js:129 Uncaught TypeError: this.refs.inputRef.focus is not a function

I am not sure if I am using customEditor correctly. Thanks for any help!


table.js

  ...

  const Table = React.createClass({
    ...

    cellEditProp: {
      mode: 'click'
    },

    createLocationCell: function(cellData, row) {
      return <div className="tags">{cellData.join(',')}</div>
    },

    createLocationEditor: function(onSave, props) {
      return (
        <SelectEditor
          multi
          options={ [ { value: 'A', label: 'Loc A' }, { value: 'B', label: 'Loc B' }, { value: 'C', label: 'Loc C' } ] }
          value={props.row.locations}
          onSave={onSave}
          {...props}
        />
      )
    },

    render: function() {
      const rows = [ { id: 1, locations: ['B'] }, { id: 2, locations: ['B', 'C'] } ]
      return (
        <BootstrapTable data={rows} striped={true} bordered={false} hover={true} pagination={true} cellEdit={this.cellEditProp}>
          <TableHeaderColumn dataField="id" isKey={true} hidden={true}>ID</TableHeaderColumn>
          <TableHeaderColumn
              dataField="locations"
              dataFormat={this.createLocationCell}
              dataSort={false}
              customEditor={{getElement: this.createLocationEditor}}
              width="150">
            Locations
          </TableHeaderColumn>
        </BootstrapTable>
      )
    }
  })

  module.exports = Table

select-editor.js

import Select from 'react-select'
...

const SelectEditor = React.createClass({
  getInitialState: function() {
    return { value: this.props.value }
  },

  onChange: function(selectedOptions) {
    const value = _.map(selectedOptions, 'value')
    this.setState({ value: selectedOptions })
  },

  onSave: function() {
    this.props.onSave(this.state.value)
  },

  render: function() {
    return (
      <div ref="inputRef" className="select-editor">
        <Select
          multi={this.props.multi}
          placeholder="Pick your options..."
          value={this.state.value}
          options={this.props.options}
          onChange={this.onChange}
        />
        <Button onClick={this.onSave}>Save</Button>
      </div>
    )
  }
})

module.exports = SelectEditor

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
EnriqueAbricotcommented, Feb 3, 2017

@cytim I did what you pointed out but I still get Uncaught TypeError: this.refs.inputRef.focus is not a function at TableEditColumn.componentDidMount, there is something else to solve this problem…

0reactions
AllenFangcommented, Feb 5, 2017

@EnriqueAbricot, which version you use now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ref.current.focus() is not a function - Stack Overflow
I'm assuming <Field /> is a Functional component. And inside <Field /> component there is a input element. If that is the case...
Read more >
'input.focus is not a function' when using a custom component ...
This seems to happen when using a custom renderInputComponent function that returns a custom input component. It doesn't seem to actually break the...
Read more >
How to Set Focus On Element After Rendering With React
In this guide, learn how to set focus on an element after JavaScript's React component renders it, using functional and class components.
Read more >
Template Refs - Vue.js
This may be useful when you want to, for example, programmatically focus an input on component mount, or initialize a 3rd party library...
Read more >
[Solved]-ref.current.focus() is not a function-Reactjs
I'm assuming <Field /> is a Functional component. And inside <Field /> component there is a input element. If that is the case...
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