Skip to content

Commit b8b80e3

Browse files
author
Joe Farro
authored
Merge pull request #5 from tiffon/focus-bug-safe-lifecycles
Fix bug in focus handler; use safe lifecycle methods
2 parents 39e5799 + 4ffadb1 commit b8b80e3

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Releases
2+
3+
## v1.1.0 (Unreleased)
4+
5+
6+
- Add PropTypes, React 16 Support ([#2](https://github.com/tiffon/txregions/pull/2), [@richseviora](https://github.com/richseviora))
7+
8+
- Fix bug focus event handler ([#3](https://github.com/tiffon/txregions/pull/3), [@tiffon](https://github.com/tiffon))
9+
10+
- Don't use unsafe lifecycle methods ([#3](https://github.com/tiffon/txregions/pull/3), [@tiffon](https://github.com/tiffon))
11+
12+
13+
### [Changes for 1.0.3 and earlier are not logged here](https://www.youtube.com/watch?v=NoAzpa1x7jU&feature=youtu.be&t=107)

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"build-min": "NODE_ENV=production webpack -p src/index.js umd/TxRegions.min.js",
2323
"lint": "eslint src demo",
2424
"start": "cd demo && node server.js && cd -",
25-
"test-node": "mocha --compilers js:babel-core/register tests.node.js",
2625
"postinstall": "node ./npm-scripts/postinstall.js"
2726
},
2827
"authors": [

src/TxRegionsInput.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export const classNames = {
4646

4747
export default class TxRegionsInput extends Component {
4848

49+
static getDerivedStateFromProps(props, state) {
50+
if (!('value' in props) || state.raw === props.value) {
51+
return null
52+
}
53+
return {raw: props.value == null ? '' : String(props.value)}
54+
}
4955

5056
constructor(props) {
5157
super(props);
@@ -381,8 +387,8 @@ export default class TxRegionsInput extends Component {
381387
this.setState({
382388
hasFocus: true,
383389
rawCaretPos: this._findSelectionOffset()
384-
}, 0);
385-
})
390+
});
391+
}, 0)
386392
}
387393

388394

@@ -440,13 +446,6 @@ export default class TxRegionsInput extends Component {
440446
}
441447

442448

443-
componentWillReceiveProps(nextProps, nextState) {
444-
if ('value' in nextProps) {
445-
this.setState({raw: nextProps.value});
446-
}
447-
}
448-
449-
450449
shouldComponentUpdate(nextProps, nextState) {
451450
return (
452451
nextState.hasFocus !== this.state.hasFocus ||
@@ -457,11 +456,6 @@ export default class TxRegionsInput extends Component {
457456
}
458457

459458

460-
componentWillUpdate(nextProps, nextState) {
461-
this._updateViolations();
462-
}
463-
464-
465459
componentDidUpdate() {
466460
this._forceHtml();
467461

@@ -482,6 +476,8 @@ export default class TxRegionsInput extends Component {
482476

483477

484478
render() {
479+
this._updateViolations();
480+
485481
const
486482
p = this.props,
487483
clean = this.clean,

0 commit comments

Comments
 (0)