feat: support binding to aria-* attributes

Closes #643
This commit is contained in:
Pawel Kozlowski
2015-02-13 16:32:49 +01:00
parent 6d45153b67
commit 1846ce8c68
5 changed files with 96 additions and 1 deletions

View File

@ -71,6 +71,24 @@ export function main() {
});
});
it('should consume binding to aria-* attributes', (done) => {
tplResolver.setTemplate(MyComp, new Template({inline: '<div [aria-label]="ctxProp"></div>'}));
compiler.compile(MyComp).then((pv) => {
createView(pv);
ctx.ctxProp = 'Initial aria label';
cd.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-label')).toEqual('Initial aria label');
ctx.ctxProp = 'Changed aria label';
cd.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-label')).toEqual('Changed aria label');
done();
});
});
it('should consume directive watch expression change.', (done) => {
var tpl =
'<div>' +

View File

@ -195,6 +195,52 @@ export function main() {
expect(view.nodes[0].hidden).toEqual(false);
});
it('should bind to aria-* attributes when exp evaluates to strings', () => {
var propertyBindings = MapWrapper.createFromStringMap({
'aria-label': 'prop1'
});
var pipeline = createPipeline({propertyBindings: propertyBindings});
var results = pipeline.process(el('<div viewroot prop-binding></div>'));
var pv = results[0].inheritedProtoView;
expect(pv.elementBinders[0].hasElementPropertyBindings).toBe(true);
instantiateView(pv);
evalContext.prop1 = 'some label';
changeDetector.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-label')).toEqual('some label');
evalContext.prop1 = 'some other label';
changeDetector.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-label')).toEqual('some other label');
evalContext.prop1 = null;
changeDetector.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-label')).toBeNull();
});
it('should bind to aria-* attributes when exp evaluates to booleans', () => {
var propertyBindings = MapWrapper.createFromStringMap({
'aria-busy': 'prop1'
});
var pipeline = createPipeline({propertyBindings: propertyBindings});
var results = pipeline.process(el('<div viewroot prop-binding></div>'));
var pv = results[0].inheritedProtoView;
expect(pv.elementBinders[0].hasElementPropertyBindings).toBe(true);
instantiateView(pv);
evalContext.prop1 = true;
changeDetector.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-busy')).toEqual('true');
evalContext.prop1 = false;
changeDetector.detectChanges();
expect(DOM.getAttribute(view.nodes[0], 'aria-busy')).toEqual('false');
});
it('should bind class with a dot', () => {
var propertyBindings = MapWrapper.createFromStringMap({
'class.bar': 'prop1',