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

Commit

Permalink
feat(input): add drop event support (#16420)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFree authored and petebacondarwin committed Jan 28, 2018
1 parent 8d9984e commit a8830d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ng/directive/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1306,9 +1306,9 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
deferListener(event, this, this.value);
});

// if user modifies input value using context menu in IE, we need "paste" and "cut" events to catch it
// if user modifies input value using context menu in IE, we need "paste", "cut" and "drop" events to catch it
if ($sniffer.hasEvent('paste')) {
element.on('paste cut', deferListener);
element.on('paste cut drop', deferListener);
}
}

Expand Down
14 changes: 13 additions & 1 deletion test/ng/directive/inputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe('input', function() {
}
});

describe('"keydown", "paste" and "cut" events', function() {
describe('"keydown", "paste", "cut" and "drop" events', function() {
beforeEach(function() {
// Force browser to report a lack of an 'input' event
$sniffer.hasEvent = function(eventName) {
Expand All @@ -461,6 +461,18 @@ describe('input', function() {
expect($rootScope.name).toEqual('mark');
});

it('should update the model on "drop" event if the input value changes', function() {
var inputElm = helper.compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');

browserTrigger(inputElm, 'keydown');
$browser.defer.flush();
expect(inputElm).toBePristine();

inputElm.val('mark');
browserTrigger(inputElm, 'drop');
$browser.defer.flush();
expect($rootScope.name).toEqual('mark');
});

it('should update the model on "cut" event', function() {
var inputElm = helper.compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
Expand Down

0 comments on commit a8830d2

Please sign in to comment.