Skip to content

Commit

Permalink
fix(ui-number-input): fix regression and allow string type for Number…
Browse files Browse the repository at this point in the history
…Input again
  • Loading branch information
balzss committed Nov 19, 2024
1 parent 3ac2582 commit 17685f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/ui-number-input/src/NumberInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 @@ -236,6 +237,7 @@ class NumberInput extends Component<NumberInputProps, NumberInputState> {
showArrows,
value,
width,
allowStringValue,
styles
} = this.props

Expand Down Expand Up @@ -274,7 +276,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 ? 'text' : '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 @@ -220,7 +225,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 @@ -243,7 +249,8 @@ const allowedProps: AllowedPropKeys = [
'onIncrement',
'onKeyDown',
'inputMode',
'textAlign'
'textAlign',
'allowStringValue'
]

export type {
Expand Down

0 comments on commit 17685f8

Please sign in to comment.