Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Added support for up/down arrow keys on timepicker #2316

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ angular.module('ui.bootstrap.timepicker', [])
showMeridian: true,
meridians: null,
readonlyInput: false,
mousewheel: true
mousewheel: true,
arrowKeys: true
})

.controller('TimepickerController', ['$scope', '$attrs', '$parse', '$log', '$locale', 'timepickerConfig', function($scope, $attrs, $parse, $log, $locale, timepickerConfig) {
Expand All @@ -25,6 +26,11 @@ angular.module('ui.bootstrap.timepicker', [])
if ( mousewheel ) {
this.setupMousewheelEvents( hoursInputEl, minutesInputEl );
}

var arrowKeys = angular.isDefined($attrs.arrowKeys) ? $scope.$parent.$eval($attrs.arrowKeys) : timepickerConfig.arrowKeys;
if ( arrowKeys ) {
this.setupArrowKeyEvents( hoursInputEl, minutesInputEl );
}

$scope.readonlyInput = angular.isDefined($attrs.readonlyInput) ? $scope.$parent.$eval($attrs.readonlyInput) : timepickerConfig.readonlyInput;
this.setupInputEvents( hoursInputEl, minutesInputEl );
Expand Down Expand Up @@ -113,6 +119,25 @@ angular.module('ui.bootstrap.timepicker', [])
});

};

// Respond on up/down arrow keys
this.setupArrowKeyEvents = function( hoursInputEl, minutesInputEl ) {
hoursInputEl.bind('keydown', function(e) {
if ( e.which === 38 ) {
$scope.$apply($scope.incrementHours());
} else if( e.which === 40 ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spacing

$scope.$apply($scope.decrementHours());
}
});

minutesInputEl.bind('keydown', function(e) {
if ( e.which == 38 ) {
$scope.$apply($scope.incrementMinutes());
}else if( e.which == 40 ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

$scope.$apply($scope.decrementMinutes());
}
});
};

this.setupInputEvents = function( hoursInputEl, minutesInputEl ) {
if ( $scope.readonlyInput ) {
Expand Down