Skip to content

Commit f844f6c

Browse files
committed
fix(keyboard): big keyboard/input refactor
1 parent bb57474 commit f844f6c

27 files changed

+761
-950
lines changed

scripts/gulp/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ export function runAppScriptsServe(testOrDemoName: string, appEntryPoint: string
205205
'--ionicAngularDir', ionicAngularDir,
206206
'--sass', sassConfigPath,
207207
'--copy', copyConfigPath,
208-
'--enableLint', 'false'
208+
'--enableLint', 'false',
209+
'--bonjour'
209210
];
210211

211212
if (watchConfigPath) {

src/components/app/app.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class App {
3030
private _titleSrv: Title = new Title(DOCUMENT);
3131
private _rootNav: NavController = null;
3232
private _disableScrollAssist: boolean;
33+
private _didScroll = false;
3334

3435
/**
3536
* @hidden
@@ -87,6 +88,11 @@ export class App {
8788
_plt.registerBackButtonAction(this.goBack.bind(this));
8889
this._disableScrollAssist = _config.getBoolean('disableScrollAssist', false);
8990

91+
const blurring = _config.getBoolean('inputBlurring', false);
92+
if (blurring) {
93+
this._enableInputBlurring();
94+
}
95+
9096
runInDev(() => {
9197
// During developement, navPop can be triggered by calling
9298
const win = <any>_plt.win();
@@ -179,6 +185,7 @@ export class App {
179185
*/
180186
setScrolling() {
181187
this._scrollTime = Date.now() + ACTIVE_SCROLLING_TIME;
188+
this._didScroll = true;
182189
}
183190

184191
/**
@@ -289,6 +296,54 @@ export class App {
289296
return recursivePop(this.getActiveNav());
290297
}
291298

299+
/**
300+
* @hidden
301+
*/
302+
_enableInputBlurring() {
303+
console.debug('App: _enableInputBlurring');
304+
let focused = true;
305+
const self = this;
306+
const platform = this._plt;
307+
308+
platform.registerListener(platform.doc(), 'focusin', onFocusin, { capture: true, zone: false, passive: true });
309+
platform.registerListener(platform.doc(), 'touchend', onTouchend, { capture: false, zone: false, passive: true });
310+
311+
function onFocusin(ev: any) {
312+
focused = true;
313+
}
314+
function onTouchend(ev: any) {
315+
// if app did scroll return early
316+
if (self._didScroll) {
317+
self._didScroll = false;
318+
return;
319+
}
320+
const active = <HTMLElement> self._plt.getActiveElement();
321+
if (!active) {
322+
return;
323+
}
324+
// only blur if the active element is a text-input or a textarea
325+
const tag = active.tagName;
326+
if (tag !== 'INPUT' && tag !== 'TEXTAREA') {
327+
return;
328+
}
329+
const tapped = ev.target;
330+
// if the selected target is the active element, do not blur
331+
if (tapped === active) {
332+
return;
333+
}
334+
if (tapped.classList.contains('input-cover')) {
335+
return;
336+
}
337+
focused = false;
338+
// TODO: find a better way, why 50ms?
339+
platform.timeout(() => {
340+
if (!focused) {
341+
active.blur();
342+
}
343+
}, 50);
344+
}
345+
}
346+
292347
}
293348

294349
function recursivePop(nav: any): Promise<any> {

src/components/checkbox/checkbox.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ export class Checkbox extends BaseInput<boolean> implements IonicTapInput, OnDes
118118
super(config, elementRef, renderer, 'checkbox', false, form, item, null);
119119
}
120120

121-
/**
122-
* @hidden
123-
*/
124-
initFocus() {
125-
this._elementRef.nativeElement.querySelector('button').focus();
126-
}
127-
128121
/**
129122
* @hidden
130123
*/
@@ -145,8 +138,8 @@ export class Checkbox extends BaseInput<boolean> implements IonicTapInput, OnDes
145138
/**
146139
* @hidden
147140
*/
148-
_inputCheckHasValue(val: boolean) {
149-
this._item && this._item.setElementClass('item-checkbox-checked', val);
141+
_inputUpdated() {
142+
this._item && this._item.setElementClass('item-checkbox-checked', this._value);
150143
}
151144

152145
}

src/components/datetime/datetime.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
448448
* @hidden
449449
*/
450450
_inputUpdated() {
451+
super._inputUpdated();
451452
this.updateText();
452453
}
453454

@@ -475,10 +476,6 @@ export class DateTime extends BaseInput<DateTimeData> implements AfterContentIni
475476

476477
@HostListener('click', ['$event'])
477478
_click(ev: UIEvent) {
478-
// do not continue if the click event came from a form submit
479-
if (ev.detail === 0) {
480-
return;
481-
}
482479
ev.preventDefault();
483480
ev.stopPropagation();
484481
this.open();

src/components/input/input.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $text-input-ios-highlight-color-invalid: $text-input-highlight-color-invalid !
5656
// iOS Default Input
5757
// --------------------------------------------------
5858

59-
.text-input-ios {
59+
.input-ios .text-input {
6060
@include margin($text-input-ios-margin-top, $text-input-ios-margin-end, $text-input-ios-margin-bottom, $text-input-ios-margin-start);
6161
@include padding(0);
6262

src/components/input/input.md.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ $text-input-md-highlight-color-invalid: $text-input-highlight-color-invalid
5656
// Material Design Default Input
5757
// --------------------------------------------------
5858

59-
.text-input-md {
59+
.input-md .text-input {
6060
@include margin($text-input-md-margin-top, $text-input-md-margin-end, $text-input-md-margin-bottom, $text-input-md-margin-start);
6161
@include padding(0);
6262

src/components/input/input.scss

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ input.text-input:-webkit-autofill {
9393

9494
width: 100%;
9595
height: 100%;
96+
97+
touch-action: manipulation;
9698
}
9799

98100
.input[disabled] .input-cover {
@@ -127,27 +129,6 @@ input.text-input:-webkit-autofill {
127129
}
128130

129131

130-
// Scroll Assist Input
131-
// --------------------------------------------------
132-
// This input is used to help the app handle
133-
// Next and Previous input tabbing
134-
135-
[next-input] {
136-
@include padding(0);
137-
138-
position: absolute;
139-
bottom: 20px;
140-
141-
width: 1px;
142-
height: 1px;
143-
144-
border: 0;
145-
background: transparent;
146-
147-
pointer-events: none;
148-
}
149-
150-
151132
// Clear Input Icon
152133
// --------------------------------------------------
153134

0 commit comments

Comments
 (0)