Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Stop keeping value in state #65

Merged
merged 4 commits into from
Mar 31, 2016

Conversation

CMTegner
Copy link
Collaborator

a.k.a. replace props.initialValue with props.value. This change makes the
behaviour of Autocomplete closer to that of native input elements, i.e. you are
forced to always supply the current value which the input should display, and
the element will provide the updated value via the onChange callback (and
onSelect).

Upgrade path:

Before:

class MyWidget extends Component {
  render() {
    return (
      <Autocomplete
        initialValue="hello"
      />
    )
  }
}

After:

class MyWidget extends Component {
  constructor() {
    this.state = { value: 'hello' }
  }
  render() {
    return (
      <Autocomplete
        value={this.state.value}
        onChange={event => this.setState({ value: event.target.value })}
        onSelect={value => this.setState({ value })}
      />
    )
  }
}

This is obviously a breaking change.

Closes #49

@colepacak
Copy link

+1

1 similar comment
@cakeinpanic
Copy link

+1

@NerdHerd91
Copy link

+1 - any timeline on when this change might occur, realizing this would require a version bump?

@CMTegner
Copy link
Collaborator Author

Looks like @sprjr has been accepting PRs lately. Perhaps he can evaluate whether or not this change aligns with the 1.0 API.

@whichsteveyp
Copy link
Contributor

@CMTegner sure thing - do you want to rebase this branch and we can take a look at it?

@CMTegner CMTegner force-pushed the stop-keeping-value-in-state branch from 4926a24 to 58aa311 Compare February 16, 2016 14:10
@CMTegner
Copy link
Collaborator Author

@sprjr: Rebased and ready to review/discuss :)

@whichsteveyp
Copy link
Contributor

I like it. Since this was said I'd like to see if @ryanflorence can take a look as well. I'm otherwise ok with merging it in and releasing a breaking version soon. I'd like to get out of the 0.x pattern and just go with better semver on it, perhaps we can include some other PRs with it as well since that'd be 1.0.0.

@CMTegner
Copy link
Collaborator Author

Sounds good to me! I know @ryanflorence has some ideas regarding how the API would change before 1.0. I'd be happy to chip in if help is needed.

@NerdHerd91
Copy link

Can we get an update on this?

@whichsteveyp
Copy link
Contributor

@NerdHerd91 I pinged Ryan again to see if he can weigh in (since he had originally asked for things like this. That being said, I'd love to get a bit of progress on this as well - especially now that #77 has been opened. Would love it if we could review that and get it merged in soon so we can follow up on others of these too with a bit more confidence.

@whichsteveyp
Copy link
Contributor

@CMTegner lets plan to move forward on this. We have tests merged in now. Want to rebase off master and verify they are still working (and/or update them)?

a.k.a. replace `props.initialValue` with `props.value`. This change makes the
behaviour of Autocomplete closer to that of native input elements, i.e. you are
forced to always supply the current value which the input should display, and
the element will provide the updated value via the `onChange` callback (and
`onSelect`).

Upgrade path:

Before:
```js
class MyWidget extends Component {
  render() {
    return (
      <Autocomplete
        initialValue="hello"
      />
    )
  }
}
```

After:
```js
class MyWidget extends Component {
  constructor() {
    this.state = { value: 'hello' }
  }
  render() {
    return (
      <Autocomplete
        value={this.state.value}
        onChange={event => this.setState({ value: event.target.value })}
        onSelect={value => this.setState({ value })}
      />
    )
  }
}
```

This is obviously a breaking change.

Closes reactjs#49
@CMTegner CMTegner force-pushed the stop-keeping-value-in-state branch from 58aa311 to 0b8e2d2 Compare March 12, 2016 19:28
@CMTegner
Copy link
Collaborator Author

@sprjr done!

@whichsteveyp whichsteveyp merged commit 16cf53e into reactjs:master Mar 31, 2016
@whichsteveyp
Copy link
Contributor

I pushed and release 1.0.0-rc1 so that this is no longer delayed. I may try to tackle a few other issues in to the final release of 1.0.0 before releasing, but this is done now - sorry for the delay.

@CMTegner
Copy link
Collaborator Author

CMTegner commented Apr 4, 2016

Great! 👍

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

Successfully merging this pull request may close these issues.

How set auto complete to empty
5 participants