Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from '@ionic/angular/common';

@Directive({
selector: 'ion-input[type=number]',
selector: 'ion-input[type=number],ion-range',
providers: [
{
provide: NG_VALUE_ACCESSOR,
Expand All @@ -13,18 +13,22 @@ import { ValueAccessor } from '@ionic/angular/common';
],
})
export class NumericValueAccessorDirective extends ValueAccessor {
constructor(injector: Injector, el: ElementRef) {
constructor(injector: Injector, private el: ElementRef<HTMLInputElement | HTMLIonRangeElement>) {
super(injector, el);
}

@HostListener('ionInput', ['$event.target'])
handleInputEvent(el: HTMLIonInputElement): void {
handleInputEvent(el: HTMLIonInputElement | HTMLIonRangeElement): void {
this.handleValueChange(el, el.value);
}

registerOnChange(fn: (_: number | null) => void): void {
super.registerOnChange((value: string) => {
fn(value === '' ? null : parseFloat(value));
});
if (this.el.nativeElement.tagName === 'ION-INPUT') {
super.registerOnChange((value: string) => {
fn(value === '' ? null : parseFloat(value));
});
} else {
super.registerOnChange(fn);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { ElementRef, Injector, Directive, HostListener } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { ValueAccessor } from '@ionic/angular/common';

// TODO(FW-5495): rename class since range isn't a text component
@Directive({
selector: 'ion-input:not([type=number]),ion-textarea,ion-searchbar,ion-range',
selector: 'ion-input:not([type=number]),ion-textarea,ion-searchbar',
providers: [
{
provide: NG_VALUE_ACCESSOR,
Expand All @@ -19,9 +18,7 @@ export class TextValueAccessorDirective extends ValueAccessor {
}

@HostListener('ionInput', ['$event.target'])
_handleInputEvent(
el: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement | HTMLIonRangeElement
): void {
_handleInputEvent(el: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement): void {
this.handleValueChange(el, el.value);
}
}
3 changes: 3 additions & 0 deletions packages/angular/test/base/e2e/src/lazy/inputs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Inputs', () => {
cy.get('ion-input').should('have.prop', 'value').and('equal', 'some text');
cy.get('ion-datetime').should('have.prop', 'value').and('equal', '1994-03-15');
cy.get('ion-select').should('have.prop', 'value').and('equal', 'nes');
cy.get('ion-range').should('have.prop', 'value').and('equal', 50);
});

it('should have reset value', () => {
Expand All @@ -27,6 +28,7 @@ describe('Inputs', () => {
cy.get('ion-input').should('not.have.prop', 'value');
cy.get('ion-datetime').should('not.have.prop', 'value');
cy.get('ion-select').should('not.have.prop', 'value');
cy.get('ion-range').should('not.have.prop', 'value');
});

it('should get some value', () => {
Expand All @@ -39,6 +41,7 @@ describe('Inputs', () => {
cy.get('ion-input').should('have.prop', 'value').and('equal', 'some text');
cy.get('ion-datetime').should('have.prop', 'value').and('equal', '1994-03-15');
cy.get('ion-select').should('have.prop', 'value').and('equal', 'nes');
cy.get('ion-range').should('have.prop', 'value').and('equal', 50);
});

it('change values should update angular', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<ion-note slot="end">{{radio}}</ion-note>
</ion-item>

<ion-item>
<ion-range [(ngModel)]="range" min="0" max="100" id="first-range">
<ion-label slot="start">Range</ion-label>
</ion-range>
</ion-item>

</ion-list>
<p>
<ion-button (click)="setValues()" id="set-button">Set values</ion-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class InputsComponent {
toggle = true;
select? = 'nes';
changes = 0;
range? = 50;

setValues() {
console.log('set values');
Expand All @@ -22,6 +23,7 @@ export class InputsComponent {
this.radio = 'nes';
this.toggle = true;
this.select = 'nes';
this.range = 50;
}

resetValues() {
Expand All @@ -32,6 +34,7 @@ export class InputsComponent {
this.radio = undefined;
this.toggle = false;
this.select = undefined;
this.range = undefined;
}

counter() {
Expand Down