Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete Converting Simple Input to Uncontrolled Component #677

Open
paniclater opened this issue Oct 23, 2017 · 1 comment
Open

Complete Converting Simple Input to Uncontrolled Component #677

paniclater opened this issue Oct 23, 2017 · 1 comment

Comments

@paniclater
Copy link
Collaborator

Simple input is currently partially converted to an uncontrolled component, but it still manages its internal text state.

This requires users to grab a dom ref of the input and manually clear it with a ref:

        this.searchRef.input.value = ''
        this.searchRef.input.focus()
        this.props.resetInstitutions()

The component should be converted to handle either case: controlled or uncontrolled or both, but not be in the current situation where it is partially controlled and partially uncontrolled.

@markstewy
Copy link
Contributor

markstewy commented Feb 4, 2018

@paniclater Am I understanding this issue correctly?

SimpleInput.js
control input value by assigning it to props value and pass in a handlechange method via props to input's onChange event:

static propTypes ={
	handleInputChange: PropType.func,
	inputValue: PropTypes.string
}
<input
	onChange={e => this.props.handleInputChange(e)}
	value = this.props.inputValue
/>
static defaultProps = {
	inputValue = ‘’
}

ParentComponent.js
parent component will have to pass in the handle change method and setState on inputValue

let parentHandleChange = (e) => {
	setState({
		searchTerm: e.target.value
	})
}

<SimpleInput 
	handleInputChange={this.parentHandleChange}
	inputValue={this.state.searchTerm}
/>

I have a feeling I completely misunderstood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants