2626 * | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
2727 * | {@link ng.directive:ngShow ngShow} | aria-hidden |
2828 * | {@link ng.directive:ngHide ngHide} | aria-hidden |
29- * | {@link ng.directive:ngClick ngClick} | tabindex |
29+ * | {@link ng.directive:ngClick ngClick} | tabindex, keypress event |
3030 * | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
3131 * | {@link module:ngMessages ngMessages} | aria-live |
3232 *
@@ -82,7 +82,8 @@ function $AriaProvider() {
8282 ariaInvalid : true ,
8383 ariaMultiline : true ,
8484 ariaValue : true ,
85- tabindex : true
85+ tabindex : true ,
86+ bindKeypress : true
8687 } ;
8788
8889 /**
@@ -99,6 +100,7 @@ function $AriaProvider() {
99100 * - **ariaMultiline** – `{boolean}` – Enables/disables aria-multiline tags
100101 * - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and aria-valuenow tags
101102 * - **tabindex** – `{boolean}` – Enables/disables tabindex tags
103+ * - **bindKeypress** – `{boolean}` – Enables/disables keypress event binding on ng-click
102104 *
103105 * @description
104106 * Enables/disables various ARIA attributes
@@ -183,13 +185,6 @@ function $AriaProvider() {
183185 } ;
184186}
185187
186- var ngAriaTabindex = [ '$aria' , function ( $aria ) {
187- return function ( scope , elem , attr ) {
188- if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
189- elem . attr ( 'tabindex' , 0 ) ;
190- }
191- } ;
192- } ] ;
193188
194189ngAriaModule . directive ( 'ngShow' , [ '$aria' , function ( $aria ) {
195190 return $aria . $$watchExpr ( 'ngShow' , 'aria-hidden' , true ) ;
@@ -309,5 +304,28 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
309304 }
310305 } ;
311306} )
312- . directive ( 'ngClick' , ngAriaTabindex )
313- . directive ( 'ngDblclick' , ngAriaTabindex ) ;
307+ . directive ( 'ngClick' , [ '$aria' , function ( $aria ) {
308+ return {
309+ restrict : 'A' ,
310+ link : function ( scope , elem , attr ) {
311+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
312+ elem . attr ( 'tabindex' , 0 ) ;
313+ }
314+
315+ if ( $aria . config ( 'bindKeypress' ) && ! elem . attr ( 'ng-keypress' ) ) {
316+ elem . on ( 'keypress' , function ( event ) {
317+ if ( event . keyCode === 32 || event . keyCode === 13 ) {
318+ scope . $eval ( attr . ngClick ) ;
319+ }
320+ } ) ;
321+ }
322+ }
323+ } ;
324+ } ] )
325+ . directive ( 'ngDblclick' , [ '$aria' , function ( $aria ) {
326+ return function ( scope , elem , attr ) {
327+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
328+ elem . attr ( 'tabindex' , 0 ) ;
329+ }
330+ } ;
331+ } ] ) ;
0 commit comments