Skip to content

Commit

Permalink
fix(ui-number-input): add back options for string input
Browse files Browse the repository at this point in the history
Closes: INSTUI-4337
  • Loading branch information
HerrTopi committed Oct 18, 2024
1 parent 7658231 commit 1ddaf59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/ui-number-input/src/NumberInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
size: 'medium',
display: 'block',
textAlign: 'start',
inputMode: 'numeric'
inputMode: 'numeric',
allowStringValue: false
}

state: NumberInputState = { hasFocus: false }
Expand Down Expand Up @@ -232,7 +233,8 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
isRequired,
showArrows,
value,
width
width,
allowStringValue
} = this.props

const { interaction } = this
Expand All @@ -258,7 +260,7 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
css={this.props.styles?.input}
aria-invalid={this.invalid ? 'true' : undefined}
id={this.id}
type="number"
type={allowStringValue ? 'string' : 'number'}
inputMode={this.props.inputMode}
placeholder={placeholder}
ref={this.handleInputRef}
Expand Down
11 changes: 9 additions & 2 deletions packages/ui-number-input/src/NumberInput/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ type NumberInputOwnProps = {
* The text alignment of the input.
*/
textAlign?: 'start' | 'center'

/**
* sets the input type to string and allows string as value
*/
allowStringValue?: boolean
}

type NumberInputState = {
Expand Down Expand Up @@ -219,7 +224,8 @@ const propTypes: PropValidators<PropKeys> = {
onIncrement: PropTypes.func,
onKeyDown: PropTypes.func,
inputMode: PropTypes.oneOf(['numeric', 'decimal', 'tel']),
textAlign: PropTypes.oneOf(['start', 'center'])
textAlign: PropTypes.oneOf(['start', 'center']),
allowStringValue: PropTypes.bool
}

const allowedProps: AllowedPropKeys = [
Expand All @@ -242,7 +248,8 @@ const allowedProps: AllowedPropKeys = [
'onIncrement',
'onKeyDown',
'inputMode',
'textAlign'
'textAlign',
'allowStringValue'
]

export type {
Expand Down

0 comments on commit 1ddaf59

Please sign in to comment.