Skip to content

Commit 95523d3

Browse files
lzeimlnuke-ellingtondanielleroux
authored
feat(core/number-input): ix-number-input scientific values (#2062)
Co-authored-by: Lukas Maurer <[email protected]> Co-authored-by: Daniel Leroux <[email protected]>
1 parent 73ebf49 commit 95523d3

File tree

13 files changed

+450
-88
lines changed

13 files changed

+450
-88
lines changed

.changeset/hot-oranges-jump.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@siemens/ix-angular': minor
3+
'@siemens/ix': minor
4+
'@siemens/ix-react': minor
5+
'@siemens/ix-vue': minor
6+
---
7+
8+
Add support for numbers in scientific notation (e.g. 1E-2) for **ix-number-input**.

.changeset/tough-donuts-fail.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@siemens/ix-angular': minor
3+
'@siemens/ix': minor
4+
'@siemens/ix-react': minor
5+
'@siemens/ix-vue': minor
6+
---
7+
8+
Add temporary property `allowEmptyValueChange` to **ix-number-input**. Setting this property enables `valueChange` to emit null values.
9+
10+
Fixes #1968.

BREAKING_CHANGES/v4.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,8 @@ themeSwitcher.setVariant('light');
540540
### ix-flip-tile
541541

542542
- Rename property `state` to `variant`
543-
- Rename `FlipTileState` to `FlipTileVariant`
543+
- Rename `FlipTileState` to `FlipTileVariant`
544+
545+
### ix-number-input
546+
547+
- The `valueChange` event type has been changed to `number | undefined`.

packages/angular/src/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,15 +2002,15 @@ Can be prevented, in which case only the event is triggered, and the modal remai
20022002

20032003

20042004
@ProxyCmp({
2005-
inputs: ['allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
2005+
inputs: ['allowEmptyValueChange', 'allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
20062006
methods: ['getNativeInputElement', 'focusInput']
20072007
})
20082008
@Component({
20092009
selector: 'ix-number-input',
20102010
changeDetection: ChangeDetectionStrategy.OnPush,
20112011
template: '<ng-content></ng-content>',
20122012
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
2013-
inputs: ['allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
2013+
inputs: ['allowEmptyValueChange', 'allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
20142014
outputs: ['valueChange', 'validityStateChange', 'ixBlur'],
20152015
standalone: false
20162016
})

packages/angular/standalone/src/components.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,15 +2103,15 @@ Can be prevented, in which case only the event is triggered, and the modal remai
21032103

21042104
@ProxyCmp({
21052105
defineCustomElementFn: defineIxNumberInput,
2106-
inputs: ['allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
2106+
inputs: ['allowEmptyValueChange', 'allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
21072107
methods: ['getNativeInputElement', 'focusInput']
21082108
})
21092109
@Component({
21102110
selector: 'ix-number-input',
21112111
changeDetection: ChangeDetectionStrategy.OnPush,
21122112
template: '<ng-content></ng-content>',
21132113
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
2114-
inputs: ['allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
2114+
inputs: ['allowEmptyValueChange', 'allowedCharactersPattern', 'disabled', 'helperText', 'infoText', 'invalidText', 'label', 'max', 'min', 'name', 'pattern', 'placeholder', 'readonly', 'required', 'showStepperButtons', 'showTextAsTooltip', 'step', 'suppressSubmitOnEnter', 'textAlignment', 'validText', 'value', 'warningText'],
21152115
outputs: ['valueChange', 'validityStateChange', 'ixBlur'],
21162116
})
21172117
export class IxNumberInput {

packages/core/src/components.d.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,6 +2505,12 @@ export namespace Components {
25052505
* @form-ready
25062506
*/
25072507
interface IxNumberInput {
2508+
/**
2509+
* If true, the valueChange event will return null instead of 0 for an empty input state. This property will be removed in 5.0.0 and this behaviour will be default.
2510+
* @since 4.1.0
2511+
* @default false
2512+
*/
2513+
"allowEmptyValueChange": boolean;
25082514
/**
25092515
* The allowed characters pattern for the input field
25102516
*/
@@ -2570,7 +2576,7 @@ export namespace Components {
25702576
*/
25712577
"readonly": boolean;
25722578
/**
2573-
* Indicates if the field is required
2579+
* Indicates if the field is required. When required, empty values (undefined) are not accepted.
25742580
* @default false
25752581
*/
25762582
"required": boolean;
@@ -2583,8 +2589,8 @@ export namespace Components {
25832589
*/
25842590
"showTextAsTooltip"?: boolean;
25852591
/**
2586-
* Step value to increment or decrement the input value
2587-
* @since 3.0.0
2592+
* Step value to increment or decrement the input value. Default step value is 1.
2593+
* @default 1
25882594
*/
25892595
"step"?: string | number;
25902596
/**
@@ -2602,10 +2608,10 @@ export namespace Components {
26022608
*/
26032609
"validText"?: string;
26042610
/**
2605-
* The value of the input field
2611+
* The value of the input field. Supports numeric values, scientific notation (1E6, 1E-6), or undefined for empty.
26062612
* @default 0
26072613
*/
2608-
"value": number;
2614+
"value"?: number;
26092615
/**
26102616
* The warning text for the input field
26112617
*/
@@ -8425,6 +8431,12 @@ declare namespace LocalJSX {
84258431
* @form-ready
84268432
*/
84278433
interface IxNumberInput {
8434+
/**
8435+
* If true, the valueChange event will return null instead of 0 for an empty input state. This property will be removed in 5.0.0 and this behaviour will be default.
8436+
* @since 4.1.0
8437+
* @default false
8438+
*/
8439+
"allowEmptyValueChange"?: boolean;
84288440
/**
84298441
* The allowed characters pattern for the input field
84308442
*/
@@ -8488,7 +8500,7 @@ declare namespace LocalJSX {
84888500
*/
84898501
"readonly"?: boolean;
84908502
/**
8491-
* Indicates if the field is required
8503+
* Indicates if the field is required. When required, empty values (undefined) are not accepted.
84928504
* @default false
84938505
*/
84948506
"required"?: boolean;
@@ -8501,8 +8513,8 @@ declare namespace LocalJSX {
85018513
*/
85028514
"showTextAsTooltip"?: boolean;
85038515
/**
8504-
* Step value to increment or decrement the input value
8505-
* @since 3.0.0
8516+
* Step value to increment or decrement the input value. Default step value is 1.
8517+
* @default 1
85068518
*/
85078519
"step"?: string | number;
85088520
/**
@@ -8520,7 +8532,7 @@ declare namespace LocalJSX {
85208532
*/
85218533
"validText"?: string;
85228534
/**
8523-
* The value of the input field
8535+
* The value of the input field. Supports numeric values, scientific notation (1E6, 1E-6), or undefined for empty.
85248536
* @default 0
85258537
*/
85268538
"value"?: number;

packages/core/src/components/input/input.fc.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export function InputElement(
8383
textAlignment?: 'start' | 'end';
8484
inputRef: (el: HTMLInputElement | undefined) => void;
8585
onKeyPress: (event: KeyboardEvent) => void;
86+
onKeyDown?: (event: KeyboardEvent) => void;
87+
onBeforeInput?: (event: InputEvent) => void;
88+
onPaste?: (event: ClipboardEvent) => void;
8689
valueChange: (value: string) => void;
8790
updateFormInternalValue: (value: string) => void;
8891
onBlur: () => void;
@@ -115,16 +118,25 @@ export function InputElement(
115118
value={props.value}
116119
placeholder={props.placeholder}
117120
onKeyPress={(event) => props.onKeyPress(event)}
121+
onKeyDown={(e) => {
122+
props.onKeyDown?.(e);
123+
handleSubmitOnEnterKeydown(
124+
e,
125+
!!props.suppressSubmitOnEnter,
126+
props.form
127+
);
128+
}}
129+
{...({
130+
onBeforeInput: (event: InputEvent) => props.onBeforeInput?.(event),
131+
} as any)}
132+
onPaste={(event) => props.onPaste?.(event)}
118133
onInput={(inputEvent) => {
119134
const target = inputEvent.target as HTMLInputElement;
120135
props.updateFormInternalValue(target.value);
121136
props.valueChange(target.value);
122137
}}
123138
onBlur={() => props.onBlur()}
124139
{...props.ariaAttributes}
125-
onKeyDown={(e) =>
126-
handleSubmitOnEnterKeydown(e, !!props.suppressSubmitOnEnter, props.form)
127-
}
128140
></input>
129141
);
130142
}

0 commit comments

Comments
 (0)