Skip to content

Commit 41fc436

Browse files
committed
Better focus delay for modals
1 parent bc297ed commit 41fc436

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

dist/css/ionic.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@charset "UTF-8";
12
/*!
23
* Copyright 2014 Drifty Co.
34
* http://drifty.com/

dist/css/ionic.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/ionic-angular.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/ionic.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,19 +4951,25 @@ ionic.views.Scroll = ionic.views.View.inherit({
49514951
initialize: function(opts) {
49524952
opts = ionic.extend({
49534953
focusFirstInput: false,
4954-
unfocusOnHide: true
4954+
unfocusOnHide: true,
4955+
focusFirstDelay: 600
49554956
}, opts);
49564957

49574958
ionic.extend(this, opts);
49584959

49594960
this.el = opts.el;
49604961
},
49614962
show: function() {
4963+
var self = this;
4964+
49624965
this.el.classList.add('active');
49634966

49644967
if(this.focusFirstInput) {
4965-
var input = this.el.querySelector('input, textarea');
4966-
input && input.focus && input.focus();
4968+
// Let any animations run first
4969+
window.setTimeout(function() {
4970+
var input = self.el.querySelector('input, textarea');
4971+
input && input.focus && input.focus();
4972+
}, this.focusFirstDelay);
49674973
}
49684974
},
49694975
hide: function() {
@@ -4972,9 +4978,12 @@ ionic.views.Scroll = ionic.views.View.inherit({
49724978
// Unfocus all elements
49734979
if(this.unfocusOnHide) {
49744980
var inputs = this.el.querySelectorAll('input, textarea');
4975-
for(var i = 0; i < inputs.length; i++) {
4976-
inputs[i].blur && inputs[i].blur();
4977-
}
4981+
// Let any animations run first
4982+
window.setTimeout(function() {
4983+
for(var i = 0; i < inputs.length; i++) {
4984+
inputs[i].blur && inputs[i].blur();
4985+
}
4986+
});
49784987
}
49794988
}
49804989
});

dist/js/ionic.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/ext/angular/test/modal.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ <h1 class="title">New Contact</h1>
8181
$ionicModal.fromTemplateUrl('modal.html', function(modal) {
8282
$scope.modal = modal;
8383
}, {
84-
animation: 'slide-in-up'
84+
animation: 'slide-in-up',
85+
focusFirstInput: true
8586
});
8687

8788
})

js/views/modalView.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55
initialize: function(opts) {
66
opts = ionic.extend({
77
focusFirstInput: false,
8-
unfocusOnHide: true
8+
unfocusOnHide: true,
9+
focusFirstDelay: 600
910
}, opts);
1011

1112
ionic.extend(this, opts);
1213

1314
this.el = opts.el;
1415
},
1516
show: function() {
17+
var self = this;
18+
1619
this.el.classList.add('active');
1720

1821
if(this.focusFirstInput) {
19-
var input = this.el.querySelector('input, textarea');
20-
input && input.focus && input.focus();
22+
// Let any animations run first
23+
window.setTimeout(function() {
24+
var input = self.el.querySelector('input, textarea');
25+
input && input.focus && input.focus();
26+
}, this.focusFirstDelay);
2127
}
2228
},
2329
hide: function() {
@@ -26,9 +32,12 @@
2632
// Unfocus all elements
2733
if(this.unfocusOnHide) {
2834
var inputs = this.el.querySelectorAll('input, textarea');
29-
for(var i = 0; i < inputs.length; i++) {
30-
inputs[i].blur && inputs[i].blur();
31-
}
35+
// Let any animations run first
36+
window.setTimeout(function() {
37+
for(var i = 0; i < inputs.length; i++) {
38+
inputs[i].blur && inputs[i].blur();
39+
}
40+
});
3241
}
3342
}
3443
});

0 commit comments

Comments
 (0)