@@ -162,12 +162,13 @@ export default class AngularColorPickerController {
162162 let _android_version = window . navigator . userAgent . match ( / A n d r o i d \s ( [ 0 - 9 \. ] * ) / i) ;
163163 this . android_version = _android_version && _android_version . length > 1 ? parseFloat ( _android_version [ 1 ] ) : NaN ;
164164
165- const mouseEventHandlers = {
166- down : this . onMouseDown . bind ( this ) ,
167- up : this . onMouseUp . bind ( this ) ,
168- move : this . onMouseMove . bind ( this )
165+ const eventHandlers = {
166+ mouseDown : this . onMouseDown . bind ( this ) ,
167+ mouseUp : this . onMouseUp . bind ( this ) ,
168+ mouseMove : this . onMouseMove . bind ( this ) ,
169+ keyUp : this . onKeyUp . bind ( this ) ,
169170 } ;
170-
171+
171172 // needed variables
172173 this . updateModel = true ;
173174
@@ -227,13 +228,18 @@ export default class AngularColorPickerController {
227228 //---------------------------
228229
229230 this . $scope . $on ( '$destroy' , ( ) => {
230- this . $document . off ( 'mousedown' , mouseEventHandlers . down ) ;
231- this . $document . off ( 'mouseup' , mouseEventHandlers . up ) ;
232- this . $document . off ( 'mousemove' , mouseEventHandlers . move ) ;
231+ // remove mouse events
232+ this . $document . off ( 'mousedown' , eventHandlers . mouseDown ) ;
233+ this . $document . off ( 'mouseup' , eventHandlers . mouseUp ) ;
234+ this . $document . off ( 'mousemove' , eventHandlers . mouseMove ) ;
235+
236+ // remove touch events
237+ this . $document . off ( 'touchstart' , eventHandlers . mouseDown ) ;
238+ this . $document . off ( 'touchend' , eventHandlers . mouseUp ) ;
239+ this . $document . off ( 'touchmove' , eventHandlers . mouseMove ) ;
233240
234- this . $document . off ( 'touchstart' , mouseEventHandlers . down ) ;
235- this . $document . off ( 'touchend' , mouseEventHandlers . up ) ;
236- this . $document . off ( 'touchmove' , mouseEventHandlers . move ) ;
241+ // remove key events
242+ this . $document . off ( 'keyup' , eventHandlers . keyUp ) ;
237243
238244 this . eventApiDispatch ( 'onDestroy' ) ;
239245 } ) ;
@@ -242,14 +248,17 @@ export default class AngularColorPickerController {
242248 this . initConfig ( ) ;
243249
244250 // setup mouse events
245- this . $document . on ( 'mousedown' , mouseEventHandlers . down ) ;
246- this . $document . on ( 'mouseup' , mouseEventHandlers . up ) ;
247- this . $document . on ( 'mousemove' , mouseEventHandlers . move ) ;
251+ this . $document . on ( 'mousedown' , eventHandlers . mouseDown ) ;
252+ this . $document . on ( 'mouseup' , eventHandlers . mouseUp ) ;
253+ this . $document . on ( 'mousemove' , eventHandlers . mouseMove ) ;
248254
249255 // setup touch events
250- this . $document . on ( 'touchstart' , mouseEventHandlers . down ) ;
251- this . $document . on ( 'touchend' , mouseEventHandlers . up ) ;
252- this . $document . on ( 'touchmove' , mouseEventHandlers . move ) ;
256+ this . $document . on ( 'touchstart' , eventHandlers . mouseDown ) ;
257+ this . $document . on ( 'touchend' , eventHandlers . mouseUp ) ;
258+ this . $document . on ( 'touchmove' , eventHandlers . mouseMove ) ;
259+
260+ // setup key events
261+ this . $document . on ( 'keyup' , eventHandlers . keyUp ) ;
253262
254263 // grid click
255264 this . find ( '.color-picker-grid' ) . on ( 'click' , this . onColorClick . bind ( this ) ) ;
@@ -328,6 +337,13 @@ export default class AngularColorPickerController {
328337 }
329338 }
330339
340+ onKeyUp ( event ) {
341+ // escape key
342+ if ( event . keyCode === 27 ) {
343+ this . api . close ( event ) ;
344+ }
345+ }
346+
331347 onColorClick ( event ) {
332348 if ( ! this . options . disabled && ! this . has_moused_moved ) {
333349 this . colorChange ( event ) ;
@@ -371,6 +387,7 @@ export default class AngularColorPickerController {
371387 }
372388
373389 this . eventApiDispatch ( 'onBlur' , [ event ] ) ;
390+ this . api . close ( event ) ;
374391 }
375392
376393 initConfig ( ) {
0 commit comments