Skip to content

Commit a45f8e3

Browse files
Merge pull request #425 from reactioncommerce/feat-kieckhafer-addMinMaxToTextInput
feat: add number type and number related props to TextInput
2 parents 3291f23 + 4d6262a commit a45f8e3

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

package/src/components/Checkbox/v1/Checkbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const StyledDiv = styled.div`
88
margin-bottom: ${applyTheme("Checkbox.verticalSpacing")};
99
`;
1010

11-
/* eslint-disable max-len */
11+
1212
/* eslint-disable quotes */
1313
// credit https://fontawesome.com/icons/check?style=solid
1414
const checkboxIconSVG = (props) => encodeURIComponent(`<svg aria-hidden='true' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'><path fill='${applyTheme("Checkbox.iconColor")(props)}' d='M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z'></path></svg>`);
1515
/* eslint-enable quotes */
16-
/* eslint-enable max-len */
16+
1717

1818
// Opacity: 0 hides the default input and position: absolute removes it
1919
// from the flow so that it doesn't push the styled checkbox to the right.

package/src/components/TextInput/v1/TextInput.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,18 @@ class TextInput extends Component {
259259
* Enable to make the input read only / disabled, disabled by default
260260
*/
261261
isReadOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
262+
/**
263+
* Maximum value for input when type === number
264+
*/
265+
max: PropTypes.number,
262266
/**
263267
* Max amount of characters allowed in input
264268
*/
265269
maxLength: PropTypes.number,
270+
/**
271+
* Minimum value for input when type === number
272+
*/
273+
min: PropTypes.number,
266274
/**
267275
* Input name
268276
*/
@@ -300,9 +308,13 @@ class TextInput extends Component {
300308
*/
301309
shouldTrimValue: PropTypes.bool,
302310
/**
303-
* The HTML input type for the text input, the input only supports "email", "password", "text", "url" defaults to "text"
311+
* Increment value when type === number
312+
*/
313+
step: PropTypes.string,
314+
/**
315+
* The HTML input type for the text input, the input only supports "email", "number", "password", "text", "url" defaults to "text"
304316
*/
305-
type: PropTypes.oneOf(["email", "password", "text", "url"]),
317+
type: PropTypes.oneOf(["email", "number", "password", "text", "url"]),
306318
/**
307319
* Prepopulate the input's value
308320
*/
@@ -555,10 +567,13 @@ class TextInput extends Component {
555567
id,
556568
isOnDarkBackground,
557569
isReadOnly,
570+
max,
558571
maxLength,
572+
min,
559573
name,
560574
placeholder,
561575
shouldAllowLineBreaks,
576+
step,
562577
type
563578
} = this.props;
564579
const { isButtonFocused, isInputFocused, value } = this.state;
@@ -575,13 +590,16 @@ class TextInput extends Component {
575590
hasBeenValidated={hasBeenValidated}
576591
id={id}
577592
isOnDarkBackground={isOnDarkBackground}
593+
max={max}
578594
maxLength={maxLength}
595+
min={min}
579596
name={name}
580597
onBlur={this.onInputBlur}
581598
onChange={this.onChange}
582599
onFocus={this.onInputFocus}
583600
placeholder={placeholder}
584601
readOnly={isReadOnly}
602+
step={step}
585603
value={value}
586604
/>
587605
{this.showClearButton() ? this.renderClearButton() : null}
@@ -604,14 +622,17 @@ class TextInput extends Component {
604622
hasBeenValidated={hasBeenValidated}
605623
id={id}
606624
isOnDarkBackground={isOnDarkBackground}
625+
max={max}
607626
maxLength={maxLength}
627+
min={min}
608628
name={name}
609629
onBlur={this.onInputBlur}
610630
onChange={this.onChange}
611631
onFocus={this.onInputFocus}
612632
onKeyPress={this.onKeyPress}
613633
placeholder={placeholder}
614634
readOnly={isReadOnly}
635+
step={step}
615636
type={type}
616637
value={value}
617638
/>

package/src/components/TextInput/v1/TextInput.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,31 @@ To enable the multi-line text input, pass the `shouldAllowLineBreaks` prop.
3131
</div>
3232
```
3333

34+
#### Number
35+
To enable the number type text input, use the `type="number"`.
36+
37+
```jsx
38+
<div style={{ width: "50%" }}>
39+
<TextInput name="example" placeholder="0.00" type="number"/>
40+
</div>
41+
```
42+
43+
To set minimum or maximum values allowed, set the `min` and `max` props.
44+
45+
```jsx
46+
<div style={{ width: "50%" }}>
47+
<TextInput name="example" placeholder="0.00" max={10.00} min={0} type="number"/>
48+
</div>
49+
```
50+
51+
To set the increment the input arrows will use, set the `step` prop.
52+
53+
```jsx
54+
<div style={{ width: "50%" }}>
55+
<TextInput name="example" placeholder="0.00" max={10.00} min={0} step="0.01" type="number"/>
56+
</div>
57+
```
58+
3459
### Styles
3560

3661
By default, text inputs are white with dark text on grey backgrounds.

0 commit comments

Comments
 (0)