this.refs.inputRef.focus is not a function
See original GitHub issueI 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:
- Created 7 years ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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…
@EnriqueAbricot, which version you use now?