mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 12:05:46 +08:00
committed by
Caitlin Potter
parent
c6b57f1ec6
commit
5481e2cfcd
@@ -26,7 +26,7 @@
|
|||||||
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
|
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
|
||||||
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
|
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
|
||||||
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
|
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
|
||||||
* | {@link ng.directive:ngClick ngClick} | tabindex |
|
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event |
|
||||||
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
|
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
|
||||||
* | {@link module:ngMessages ngMessages} | aria-live |
|
* | {@link module:ngMessages ngMessages} | aria-live |
|
||||||
*
|
*
|
||||||
@@ -82,7 +82,8 @@ function $AriaProvider() {
|
|||||||
ariaInvalid: true,
|
ariaInvalid: true,
|
||||||
ariaMultiline: true,
|
ariaMultiline: true,
|
||||||
ariaValue: true,
|
ariaValue: true,
|
||||||
tabindex: true
|
tabindex: true,
|
||||||
|
bindKeypress: true
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,6 +100,7 @@ function $AriaProvider() {
|
|||||||
* - **ariaMultiline** – `{boolean}` – Enables/disables aria-multiline tags
|
* - **ariaMultiline** – `{boolean}` – Enables/disables aria-multiline tags
|
||||||
* - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and aria-valuenow tags
|
* - **ariaValue** – `{boolean}` – Enables/disables aria-valuemin, aria-valuemax and aria-valuenow tags
|
||||||
* - **tabindex** – `{boolean}` – Enables/disables tabindex tags
|
* - **tabindex** – `{boolean}` – Enables/disables tabindex tags
|
||||||
|
* - **bindKeypress** – `{boolean}` – Enables/disables keypress event binding on ng-click
|
||||||
*
|
*
|
||||||
* @description
|
* @description
|
||||||
* Enables/disables various ARIA attributes
|
* Enables/disables various ARIA attributes
|
||||||
@@ -183,13 +185,6 @@ function $AriaProvider() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var ngAriaTabindex = ['$aria', function($aria) {
|
|
||||||
return function(scope, elem, attr) {
|
|
||||||
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
|
||||||
elem.attr('tabindex', 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}];
|
|
||||||
|
|
||||||
ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
||||||
return $aria.$$watchExpr('ngShow', 'aria-hidden', true);
|
return $aria.$$watchExpr('ngShow', 'aria-hidden', true);
|
||||||
@@ -309,5 +304,28 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.directive('ngClick', ngAriaTabindex)
|
.directive('ngClick',['$aria', function($aria) {
|
||||||
.directive('ngDblclick', ngAriaTabindex);
|
return {
|
||||||
|
restrict: 'A',
|
||||||
|
link: function(scope, elem, attr) {
|
||||||
|
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
||||||
|
elem.attr('tabindex', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($aria.config('bindKeypress') && !elem.attr('ng-keypress')) {
|
||||||
|
elem.on('keypress', function(event) {
|
||||||
|
if (event.keyCode === 32 || event.keyCode === 13) {
|
||||||
|
scope.$eval(attr.ngClick);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}])
|
||||||
|
.directive('ngDblclick', ['$aria', function($aria) {
|
||||||
|
return function(scope, elem, attr) {
|
||||||
|
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
|
||||||
|
elem.attr('tabindex', 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}]);
|
||||||
|
|||||||
@@ -481,6 +481,54 @@ describe('$aria', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('accessible actions', function() {
|
||||||
|
beforeEach(injectScopeAndCompiler);
|
||||||
|
|
||||||
|
var clickFn;
|
||||||
|
|
||||||
|
it('should a trigger click from the keyboard', function() {
|
||||||
|
scope.someAction = function() {};
|
||||||
|
compileInput('<div ng-click="someAction()" tabindex="0"></div>');
|
||||||
|
clickFn = spyOn(scope, 'someAction');
|
||||||
|
|
||||||
|
element.triggerHandler({type: 'keypress', keyCode: 32});
|
||||||
|
|
||||||
|
expect(clickFn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not override existing ng-keypress', function() {
|
||||||
|
scope.someOtherAction = function() {};
|
||||||
|
var keypressFn = spyOn(scope, 'someOtherAction');
|
||||||
|
|
||||||
|
scope.someAction = function() {};
|
||||||
|
clickFn = spyOn(scope, 'someAction');
|
||||||
|
compileInput('<div ng-click="someAction()" ng-keypress="someOtherAction()" tabindex="0"></div>');
|
||||||
|
|
||||||
|
element.triggerHandler({type: 'keypress', keyCode: 32});
|
||||||
|
|
||||||
|
expect(clickFn).not.toHaveBeenCalled();
|
||||||
|
expect(keypressFn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('actions when bindKeypress set to false', function() {
|
||||||
|
beforeEach(configAriaProvider({
|
||||||
|
bindKeypress: false
|
||||||
|
}));
|
||||||
|
beforeEach(injectScopeAndCompiler);
|
||||||
|
|
||||||
|
it('should not a trigger click from the keyboard', function() {
|
||||||
|
scope.someAction = function() {};
|
||||||
|
var clickFn = spyOn(scope, 'someAction');
|
||||||
|
|
||||||
|
element = $compile('<div ng-click="someAction()" tabindex="0">></div>')(scope);
|
||||||
|
|
||||||
|
element.triggerHandler({type: 'keypress', keyCode: 32});
|
||||||
|
|
||||||
|
expect(clickFn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('tabindex when disabled', function() {
|
describe('tabindex when disabled', function() {
|
||||||
beforeEach(configAriaProvider({
|
beforeEach(configAriaProvider({
|
||||||
tabindex: false
|
tabindex: false
|
||||||
|
|||||||
Reference in New Issue
Block a user