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 212e513 commit 5dc0766
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 @@ -1302,9 +1302,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 @@ -440,7 +440,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 @@ -462,6 +462,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 5dc0766

Please sign in to comment.