-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input): better handling of attributes
- Loading branch information
1 parent
8041eed
commit 9f86e10
Showing
11 changed files
with
164 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
import { RootPage } from '../pages/root-page/root-page'; | ||
|
||
@Component({ | ||
template: '<ion-nav [root]="root"></ion-nav>' | ||
}) | ||
export class AppComponent { | ||
root = RootPage; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { IonicApp, IonicModule } from '../../../../..'; | ||
|
||
import { AppComponent } from './app.component'; | ||
import { RootPageModule } from '../pages/root-page/root-page.module'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
BrowserModule, | ||
IonicModule.forRoot(AppComponent), | ||
RootPageModule | ||
], | ||
bootstrap: [IonicApp] | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | ||
|
||
import { AppModule } from './app.module'; | ||
|
||
platformBrowserDynamic().bootstrapModule(AppModule); |
Empty file.
39 changes: 39 additions & 0 deletions
39
src/components/input/test/attributes/pages/root-page/root-page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<ion-header> | ||
|
||
<ion-toolbar> | ||
<ion-title>Input attributes</ion-title> | ||
</ion-toolbar> | ||
|
||
</ion-header> | ||
|
||
<ion-content> | ||
<ion-list> | ||
<ion-item> | ||
<ion-label stacked>Stacked</ion-label> | ||
<ion-input #input1 | ||
type="number" | ||
placeholder="Placeholder" | ||
value="1234" | ||
id="mystackinput" | ||
name="holaa" | ||
min="0" | ||
max="10000" | ||
step="2" | ||
autocomplete="on" | ||
autocorrect="on" | ||
autocapitalize="on" | ||
spellcheck="true" | ||
maxlength="4" | ||
disabled | ||
readonly | ||
></ion-input> | ||
</ion-item> | ||
|
||
<ion-list> | ||
<ion-item *ngIf="input1Valid" color="secondary">Test passed</ion-item> | ||
<ion-item *ngIf="!input1Valid" color="danger">Test FAILED</ion-item> | ||
</ion-list> | ||
|
||
</ion-list> | ||
|
||
</ion-content> |
14 changes: 14 additions & 0 deletions
14
src/components/input/test/attributes/pages/root-page/root-page.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { IonicPageModule } from '../../../../../..'; | ||
|
||
import { RootPage } from './root-page'; | ||
|
||
@NgModule({ | ||
declarations: [ | ||
RootPage, | ||
], | ||
imports: [ | ||
IonicPageModule.forChild(RootPage) | ||
] | ||
}) | ||
export class RootPageModule {} |
59 changes: 59 additions & 0 deletions
59
src/components/input/test/attributes/pages/root-page/root-page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { TextInput } from '../../../../../../'; | ||
|
||
@Component({ | ||
templateUrl: 'root-page.html' | ||
}) | ||
export class RootPage { | ||
|
||
input1Valid: boolean; | ||
input2Valid: boolean; | ||
|
||
@ViewChild('input1') input1: TextInput; | ||
|
||
ionViewDidEnter() { | ||
this.input1Valid = this.checkInput1(); | ||
} | ||
|
||
checkInput1(): boolean { | ||
const nativeEle = <HTMLElement>this.input1._native.nativeElement; | ||
|
||
return testAttributes(nativeEle, { | ||
id: null, | ||
type: 'number', | ||
placeholder: 'Placeholder', | ||
name: 'holaa', | ||
min: '0', | ||
max: '10000', | ||
step: '2', | ||
autocomplete: 'on', | ||
autocorrect: 'on', | ||
autocapitalize: 'on', | ||
spellcheck: 'true', | ||
maxLength: '4', | ||
'aria-labelledby': 'lbl-0', | ||
readOnly: true, | ||
disabled: true | ||
}); | ||
} | ||
} | ||
|
||
function testAttributes(ele: HTMLElement, attributes: any): boolean { | ||
for (let attr in attributes) { | ||
const expected = attributes[attr]; | ||
const value = (<any>ele)[attr]; | ||
|
||
if (expected === null) { | ||
if (ele.hasAttribute(attr) || value !== '') { | ||
console.error(`Element should NOT have "${attr}"`); | ||
return false; | ||
} | ||
} else { | ||
if (expected !== value && expected !== ele.getAttribute(attr)) { | ||
console.error(`Value "${attr}" does not match: ${expected} != ${value}`); | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9f86e10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
9f86e10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the native input property
maxlength
is now handled by a utility function calledcopyInputAttributes
. Does this mean thatmaxlength
(as well as other properties) are now static? Should I post this as an issue?