Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(input): do not hold input for composition on android
Browse files Browse the repository at this point in the history
Workaround for chrome for android until #2129 is ready.

Closes #5308, #5323
  • Loading branch information
clkao authored and tbosch committed Dec 18, 2013
1 parent 57d5058 commit 3dc1803
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
16 changes: 9 additions & 7 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,17 @@ function textInputType(scope, element, attr, ctrl, $sniffer, $browser) {
// In composition mode, users are still inputing intermediate text buffer,
// hold the listener until composition is done.
// More about composition events: https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent
var composing = false;
if (!$sniffer.android) {
var composing = false;

element.on('compositionstart', function() {
composing = true;
});
element.on('compositionstart', function(data) {
composing = true;
});

element.on('compositionend', function() {
composing = false;
});
element.on('compositionend', function() {
composing = false;
});
}

var listener = function() {
if (composing) return;
Expand Down
44 changes: 31 additions & 13 deletions test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,37 @@ describe('input', function() {
expect(scope.name).toEqual('adam');
});

it('should not update the model between "compositionstart" and "compositionend"', function() {
compileInput('<input type="text" ng-model="name" name="alias"" />');
changeInputValueTo('a');
expect(scope.name).toEqual('a');
if (!(msie < 9)) {
browserTrigger(inputElm, 'compositionstart');
changeInputValueTo('adam');
expect(scope.name).toEqual('a');
browserTrigger(inputElm, 'compositionend');
}
changeInputValueTo('adam');
expect(scope.name).toEqual('adam');
});
if (!(msie < 9)) {
describe('compositionevents', function() {
it('should not update the model between "compositionstart" and "compositionend" on non android', inject(function($sniffer) {
$sniffer.android = false;

compileInput('<input type="text" ng-model="name" name="alias"" />');
changeInputValueTo('a');
expect(scope.name).toEqual('a');
browserTrigger(inputElm, 'compositionstart');
changeInputValueTo('adam');
expect(scope.name).toEqual('a');
browserTrigger(inputElm, 'compositionend');
changeInputValueTo('adam');
expect(scope.name).toEqual('adam');
}));

it('should update the model between "compositionstart" and "compositionend" on android', inject(function($sniffer) {
$sniffer.android = true;

compileInput('<input type="text" ng-model="name" name="alias"" />');
changeInputValueTo('a');
expect(scope.name).toEqual('a');
browserTrigger(inputElm, 'compositionstart');
changeInputValueTo('adam');
expect(scope.name).toEqual('adam');
browserTrigger(inputElm, 'compositionend');
changeInputValueTo('adam2');
expect(scope.name).toEqual('adam2');
}));
});
}

describe('"change" event', function() {
function assertBrowserSupportsChangeEvent(inputEventSupported) {
Expand Down

0 comments on commit 3dc1803

Please sign in to comment.