Skip to content

Commit b56c448

Browse files
authored
Input: improve inputs of type number (#735)
* * Support native step attribute * * Support entering decimal numbers via keyboard on number inputs
1 parent c86f3fc commit b56c448

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.68.1 (2025-02-04)
2+
3+
### Improvements
4+
5+
- **Input**:
6+
- Support input native `step` attribute
7+
- Support entering decimal numbers via keyboard when input type is `number`
8+
19
# 2.68.0 (2025-01-02)
210

311
### Breaking change

projects/demo/src/app/demo/pages/input-page/input-page.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ <h3>Inputs</h3>
128128
<dt>min</dt>
129129
<dd>Set native min attribute on the input</dd>
130130

131+
<dt>step</dt>
132+
<dd>Set native step attribute on the input</dd>
133+
131134
<dt>type</dt>
132135
<dd>
133136
Input type:

projects/pastanaga-angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@guillotinaweb/pastanaga-angular",
33
"description": "Provides Pastanaga UI elements as Angular components",
4-
"version": "2.68.0",
4+
"version": "2.68.1",
55
"license": "MIT",
66
"keywords": [
77
"angular",

projects/pastanaga-angular/src/lib/controls/textfield/input-formatter.directive.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Directive, ElementRef, forwardRef, HostListener, Input, Provider } from '@angular/core';
1+
import { booleanAttribute, Directive, ElementRef, forwardRef, HostListener, Input, Provider } from '@angular/core';
22
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
33

44
const FORMATTER_CONTROL_VALUE_ACCESSOR: Provider = {
@@ -14,15 +14,16 @@ const FORMATTER_CONTROL_VALUE_ACCESSOR: Provider = {
1414
})
1515
export class InputFormatterDirective implements ControlValueAccessor {
1616
@Input() paInputFormatter!: (value: any) => any;
17-
@Input() paInputFormatterSkip = false;
17+
@Input({ transform: booleanAttribute }) paInputFormatterUpdateInput = true;
18+
@Input({ transform: booleanAttribute }) paInputFormatterSkip = false;
1819

1920
private _writeToFormControl: (value: any) => void = () => {
2021
// Will be instantiated by registerOnChange
2122
};
2223

2324
@HostListener('input') onKeyup() {
2425
const val = this.formatValue(this.el.nativeElement.value);
25-
if (val !== this.el.nativeElement.value) {
26+
if (this.paInputFormatterUpdateInput && val !== this.el.nativeElement.value) {
2627
this.el.nativeElement.value = val;
2728
}
2829
this._writeToFormControl(val);

projects/pastanaga-angular/src/lib/controls/textfield/input/input.component.html

+2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
[attr.autocapitalize]="autocapitalize || undefined"
2626
[min]="min"
2727
[max]="max"
28+
[step]="step"
2829
[readonly]="readonly"
2930
[paInputFormatter]="sanitizeHtmlTags"
31+
[paInputFormatterUpdateInput]="type !== 'number'"
3032
(focus)="onFocus($event)"
3133
(blur)="onBlur()"
3234
(keyup)="onKeyUp($event)" />

projects/pastanaga-angular/src/lib/controls/textfield/input/input.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class InputComponent extends NativeTextFieldDirective implements OnChange
4242
@Input({ transform: trimString }) icon = '';
4343
@Input({ transform: numberAttribute }) min?: number;
4444
@Input({ transform: numberAttribute }) max?: number;
45+
@Input({ transform: numberAttribute }) step?: number;
4546
@Input({ transform: booleanAttribute }) iconOnRight = false;
4647
@Input({ transform: trimString }) autocapitalize = '';
4748

0 commit comments

Comments
 (0)