Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export default class Container extends Component {
return (
<ControlledInput
// filter only numberic characters
onChangeText={(value) => this.setState({ value: value.replace(/\D/g, '') })}
onChangeText={(value) => {
const newValue = value.replace(/\D/g, '');
this.setState({ value: newValue });
return newValue; // must return a value
}
value={this.state.value}
style={{ width: 300, height: 70, borderWidth: 1 }}
/>
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export class ControlledInput extends PureComponent {
const nextSelection = this.getNextSelection(value, nextValue, selection);
this.setState({ selection: nextSelection });
if (onChangeText) {
onChangeText(nextValue);
const _nextValue = onChangeText(nextValue);
const _nextSelection = this.getNextSelection(nextValue, _nextValue, nextSelection);
this.setState({selection: _nextSelection});
}
return this.props.onKeyPress && this.props.onKeyPress(event);
}
Expand Down