mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix(input): do not hold input for composition on android
Workaround for chrome for android until #2129 is ready. Closes #5308, #5323
This commit is contained in:
parent
57d50582aa
commit
3dc18037e8
2 changed files with 40 additions and 20 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue