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
37 changes: 32 additions & 5 deletions lib/react-currency-input.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-currency-input.cjs.js.map

Large diffs are not rendered by default.

37 changes: 32 additions & 5 deletions lib/react-currency-input.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-currency-input.es.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/react-currency-input.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-currency-input.min.js.map

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ Number.parseFloat = parseFloat;
class CurrencyInput extends Component {
constructor(props) {
super(props);

this.prepareProps = this.prepareProps.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleFocus = this.handleFocus.bind(this);
this.setSelectionRange = this.setSelectionRange.bind(this);

this.state = this.prepareProps(this.props);

this.inputSelectionStart = 1;
Expand Down Expand Up @@ -52,9 +54,11 @@ class CurrencyInput extends Component {
delete customProps.suffix;
delete customProps.selectAllOnFocus;
delete customProps.autoFocus;
delete customProps.maxValue;
delete customProps.minValue;

let initialValue = props.value;
if (initialValue === null) {
if (initialValue == null) {
initialValue = props.allowEmpty? null : '';
}else{

Expand Down Expand Up @@ -217,6 +221,12 @@ class CurrencyInput extends Component {
this.props.suffix
);

if ((this.props.maxValue && value > this.props.maxValue)
|| (this.props.minValue && value < this.props.maxValue)) {
// if value exceeds min & max limits, do nothing...
return;
}

event.persist(); // fixes issue #23

this.setState({ maskedValue, value }, () => {
Expand Down Expand Up @@ -287,7 +297,9 @@ CurrencyInput.propTypes = {
allowEmpty: PropTypes.bool,
prefix: PropTypes.string,
suffix: PropTypes.string,
selectAllOnFocus: PropTypes.bool
selectAllOnFocus: PropTypes.bool,
maxValue: PropTypes.number,
minValue: PropTypes.number
};


Expand All @@ -303,7 +315,9 @@ CurrencyInput.defaultProps = {
allowNegative: false,
prefix: '',
suffix: '',
selectAllOnFocus: false
selectAllOnFocus: false,
maxValue: undefined,
minValue: undefined
};


Expand Down
Loading