Skip to content

Commit

Permalink
fix(NumberInput): allow value to be outside min/max, show validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan committed Jul 6, 2021
1 parent b551c07 commit dd29392
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const Default = () => {
id="carbon-number"
min={0}
max={100}
value={50}
value={150}
label="NumberInput label"
helperText="Optional helper text."
invalidText="Number is not valid"
Expand Down
6 changes: 4 additions & 2 deletions packages/react/src/components/NumberInput/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class NumberInput extends Component {
translateWithId: (id) => defaultTranslations[id],
};

static getDerivedStateFromProps({ min, max, value }, state) {
static getDerivedStateFromProps({ value }, state) {
const { prevValue } = state;

if (useControlledStateWithValue && value === '' && prevValue !== '') {
Expand All @@ -214,10 +214,12 @@ class NumberInput extends Component {

// If `useControlledStateWithValue` feature flag is on, do nothing here.
// Otherwise, do prop -> state sync with "value capping".
//// Value capping removed in #8965
//// value: capMax(max, capMin(min, value)), (L223)
return useControlledStateWithValue || prevValue === value
? null
: {
value: capMax(max, capMin(min, value)),
value,
prevValue: value,
};
}
Expand Down

0 comments on commit dd29392

Please sign in to comment.