From 868b5e6dea1758e26936aae224c293430d1362ea Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 30 Jul 2019 20:43:15 -0700 Subject: [PATCH 1/2] feat: add number type and number related props to TextInput Signed-off-by: Erik Kieckhafer --- .../src/components/Checkbox/v1/Checkbox.js | 4 +-- .../src/components/TextInput/v1/TextInput.js | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/package/src/components/Checkbox/v1/Checkbox.js b/package/src/components/Checkbox/v1/Checkbox.js index 228d8c534..28971ac1b 100644 --- a/package/src/components/Checkbox/v1/Checkbox.js +++ b/package/src/components/Checkbox/v1/Checkbox.js @@ -8,12 +8,12 @@ const StyledDiv = styled.div` margin-bottom: ${applyTheme("Checkbox.verticalSpacing")}; `; -/* eslint-disable max-len */ + /* eslint-disable quotes */ // credit https://fontawesome.com/icons/check?style=solid const checkboxIconSVG = (props) => encodeURIComponent(``); /* eslint-enable quotes */ -/* eslint-enable max-len */ + // Opacity: 0 hides the default input and position: absolute removes it // from the flow so that it doesn't push the styled checkbox to the right. diff --git a/package/src/components/TextInput/v1/TextInput.js b/package/src/components/TextInput/v1/TextInput.js index 9d6a1472e..a2e0193dd 100644 --- a/package/src/components/TextInput/v1/TextInput.js +++ b/package/src/components/TextInput/v1/TextInput.js @@ -259,10 +259,18 @@ class TextInput extends Component { * Enable to make the input read only / disabled, disabled by default */ isReadOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]), + /** + * Maximum value for input when type === number + */ + max: PropTypes.number, /** * Max amount of characters allowed in input */ maxLength: PropTypes.number, + /** + * Minimum value for input when type === number + */ + min: PropTypes.number, /** * Input name */ @@ -300,9 +308,13 @@ class TextInput extends Component { */ shouldTrimValue: PropTypes.bool, /** - * The HTML input type for the text input, the input only supports "email", "password", "text", "url" defaults to "text" + * Increment value when type === number + */ + step: PropTypes.string, + /** + * The HTML input type for the text input, the input only supports "email", "number", "password", "text", "url" defaults to "text" */ - type: PropTypes.oneOf(["email", "password", "text", "url"]), + type: PropTypes.oneOf(["email", "number", "password", "text", "url"]), /** * Prepopulate the input's value */ @@ -555,10 +567,13 @@ class TextInput extends Component { id, isOnDarkBackground, isReadOnly, + max, maxLength, + min, name, placeholder, shouldAllowLineBreaks, + step, type } = this.props; const { isButtonFocused, isInputFocused, value } = this.state; @@ -575,13 +590,16 @@ class TextInput extends Component { hasBeenValidated={hasBeenValidated} id={id} isOnDarkBackground={isOnDarkBackground} + max={max} maxLength={maxLength} + min={min} name={name} onBlur={this.onInputBlur} onChange={this.onChange} onFocus={this.onInputFocus} placeholder={placeholder} readOnly={isReadOnly} + step={step} value={value} /> {this.showClearButton() ? this.renderClearButton() : null} @@ -604,7 +622,9 @@ class TextInput extends Component { hasBeenValidated={hasBeenValidated} id={id} isOnDarkBackground={isOnDarkBackground} + max={max} maxLength={maxLength} + min={min} name={name} onBlur={this.onInputBlur} onChange={this.onChange} @@ -612,6 +632,7 @@ class TextInput extends Component { onKeyPress={this.onKeyPress} placeholder={placeholder} readOnly={isReadOnly} + step={step} type={type} value={value} /> From 4d6262a9985230eb861b203a0d832a7d57ab9b91 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 30 Jul 2019 21:52:00 -0700 Subject: [PATCH 2/2] docs: add examples of number input type Signed-off-by: Erik Kieckhafer --- .../src/components/TextInput/v1/TextInput.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/package/src/components/TextInput/v1/TextInput.md b/package/src/components/TextInput/v1/TextInput.md index 6bbfc4cec..b40680313 100644 --- a/package/src/components/TextInput/v1/TextInput.md +++ b/package/src/components/TextInput/v1/TextInput.md @@ -31,6 +31,31 @@ To enable the multi-line text input, pass the `shouldAllowLineBreaks` prop. ``` +#### Number +To enable the number type text input, use the `type="number"`. + +```jsx +
+ +
+``` + +To set minimum or maximum values allowed, set the `min` and `max` props. + +```jsx +
+ +
+``` + +To set the increment the input arrows will use, set the `step` prop. + +```jsx +
+ +
+``` + ### Styles By default, text inputs are white with dark text on grey backgrounds.