Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 6e685c3

Browse files
topherfangioThomasBurleson
authored andcommitted
fix(input): Fix transition when switching tabs in Safari.
In Safari, if you select an input, switch tabs, then switch back, the CSS animation to float the label does not fire properly causing the label to sit on top on any text that you copy/paste into the field. Fix by delaying the `setFocus()` until the next tick. Fixes #4203. Closes #7207
1 parent a838761 commit 6e685c3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/components/input/input.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,16 @@ function inputTextareaDirective($mdUtil, $window, $mdAria) {
320320
if (!isReadonly) {
321321
element
322322
.on('focus', function(ev) {
323-
containerCtrl.setFocused(true);
323+
$mdUtil.nextTick(function() {
324+
containerCtrl.setFocused(true);
325+
});
324326
})
325327
.on('blur', function(ev) {
326-
containerCtrl.setFocused(false);
327-
inputCheckValue();
328+
$mdUtil.nextTick(function() {
329+
containerCtrl.setFocused(false);
330+
inputCheckValue();
331+
});
328332
});
329-
330333
}
331334

332335
//ngModelCtrl.$setTouched();

src/components/input/input.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,18 @@ describe('md-input-container directive', function() {
134134
expect(el).not.toHaveClass('md-input-focused');
135135

136136
el.find('input').triggerHandler('focus');
137+
138+
// Expect a slight delay (via $mdUtil.nextTick()) which fixes a tabbing issue in Safari, see
139+
// https://github.com/angular/material/issues/4203 for more info.
140+
expect(el).not.toHaveClass('md-input-focused');
141+
$timeout.flush();
137142
expect(el).toHaveClass('md-input-focused');
138143

139144
el.find('input').triggerHandler('blur');
145+
146+
// Again, expect the change to not be immediate
147+
expect(el).toHaveClass('md-input-focused');
148+
$timeout.flush();
140149
expect(el).not.toHaveClass('md-input-focused');
141150
});
142151

0 commit comments

Comments
 (0)