diff --git a/packages/ui-number-input/src/NumberInput/README.md b/packages/ui-number-input/src/NumberInput/README.md index 28c4e382c8..278bb2df87 100644 --- a/packages/ui-number-input/src/NumberInput/README.md +++ b/packages/ui-number-input/src/NumberInput/README.md @@ -2,7 +2,9 @@ describes: NumberInput --- -A controlled number input field. Note that this field **does not work +A controlled number input field. +By deafult, it renders a `` to the DOM. However, if you need any string value, use the `allowStringValue` flag. Only use this if absolutely necessary, since it could be confusing for screenreader users. +Note that this field **does not work uncontrolled** - you must pass event handlers if you want it to respond to user input. @@ -300,12 +302,11 @@ type: embed ---
- Use when the input is limited to a number (integer, rational, or irrational expressed with decimal points) + Use when you need increment/decrement functionality Use labels at the top or to the left of the input field
Place labels or text strings to the right of the input field - Use for alphanumeric input
``` diff --git a/packages/ui-number-input/src/NumberInput/index.tsx b/packages/ui-number-input/src/NumberInput/index.tsx index 129c6c320d..a50f1a6491 100644 --- a/packages/ui-number-input/src/NumberInput/index.tsx +++ b/packages/ui-number-input/src/NumberInput/index.tsx @@ -75,7 +75,8 @@ class NumberInput extends Component { size: 'medium', display: 'block', textAlign: 'start', - inputMode: 'numeric' + inputMode: 'numeric', + allowStringValue: false } state: NumberInputState = { hasFocus: false } @@ -236,7 +237,8 @@ class NumberInput extends Component { showArrows, value, width, - styles + styles, + allowStringValue } = this.props const { interaction } = this @@ -274,7 +276,7 @@ class NumberInput extends Component { 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} diff --git a/packages/ui-number-input/src/NumberInput/props.ts b/packages/ui-number-input/src/NumberInput/props.ts index 2cbe96f8ba..d41f03fa75 100644 --- a/packages/ui-number-input/src/NumberInput/props.ts +++ b/packages/ui-number-input/src/NumberInput/props.ts @@ -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 = { @@ -220,7 +225,8 @@ const propTypes: PropValidators = { 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 = [ @@ -243,7 +249,8 @@ const allowedProps: AllowedPropKeys = [ 'onIncrement', 'onKeyDown', 'inputMode', - 'textAlign' + 'textAlign', + 'allowStringValue' ] export type { diff --git a/packages/ui-table/src/Table/Head/index.tsx b/packages/ui-table/src/Table/Head/index.tsx index 5522661b41..80c279e68e 100644 --- a/packages/ui-table/src/Table/Head/index.tsx +++ b/packages/ui-table/src/Table/Head/index.tsx @@ -68,7 +68,7 @@ class Head extends Component { let sortable = false if (firstRow && firstRow.props && firstRow.props.children) { Children.forEach(firstRow.props.children, (grandchild) => { - if (grandchild.props.onRequestSort) { + if (grandchild?.props?.onRequestSort) { sortable = true return }