From db62acfa8f654f4c8585bfd7f1fcb0dc5f04bb10 Mon Sep 17 00:00:00 2001 From: SendilKumar N Date: Thu, 2 Jun 2016 16:34:58 +0800 Subject: [PATCH] readio --- src/components/radio/radio.html | 4 +- src/components/radio/radio.spec.ts | 73 +++++++++++++++++++++++++++++- src/components/radio/radio.ts | 11 +++++ src/demo-app/radio/radio-demo.html | 6 +-- 4 files changed, 89 insertions(+), 5 deletions(-) diff --git a/src/components/radio/radio.html b/src/components/radio/radio.html index e094b07f4842..2269c506a3c5 100644 --- a/src/components/radio/radio.html +++ b/src/components/radio/radio.html @@ -15,7 +15,9 @@ [name]="name" (change)="onInputChange($event)" (focus)="onInputFocus()" - (blur)="onInputBlur()" /> + (blur)="onInputBlur()" + [attr.aria-label]="ariaLabel" + [attr.aria-labelledby]="ariaLabelledby"/>
diff --git a/src/components/radio/radio.spec.ts b/src/components/radio/radio.spec.ts index 6f5a8c1a6de4..b3c51094b9df 100644 --- a/src/components/radio/radio.spec.ts +++ b/src/components/radio/radio.spec.ts @@ -195,7 +195,7 @@ describe('MdRadio', () => { expect(radioInstances[1].checked).toBe(true); }); - it('should deselect all of the checkboxes when the group value is cleared', () => { + it('should deselect all of the radioButtones when the group value is cleared', () => { radioInstances[0].checked = true; expect(groupInstance.value).toBeTruthy(); @@ -206,6 +206,56 @@ describe('MdRadio', () => { }); }); + describe('with provided aria-label ', () => { + let fixture: ComponentFixture; + let radioButtonDebugElement: DebugElement; + let radioButtonNativeElement: HTMLElement; + let inputElement: HTMLInputElement; + + it('should use the provided aria-label', async(() => { + builder.createAsync(RadioButtonWithAriaLabel).then(f => { + fixture = f; + radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton)); + radioButtonNativeElement = radioButtonDebugElement.nativeElement; + inputElement = radioButtonNativeElement.querySelector('input'); + + fixture.detectChanges(); + expect(inputElement.getAttribute('aria-label')).toBe('superRadio'); + }); + })); + }); + + describe('with provided aria-labelledby ', () => { + let fixture: ComponentFixture; + let radioButtonDebugElement: DebugElement; + let radioButtonNativeElement: HTMLElement; + let inputElement: HTMLInputElement; + + it('should use the provided aria-labelledby', async(() => { + builder.createAsync(RadioButtonWithAriaLabelledby).then(f => { + fixture = f; + radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton)); + radioButtonNativeElement = radioButtonDebugElement.nativeElement; + inputElement = radioButtonNativeElement.querySelector('input'); + + fixture.detectChanges(); + expect(inputElement.getAttribute('aria-labelledby')).toBe('superByRadio'); + }); + })); + + it('should not assign aria-labelledby if none is provided', async(() => { + builder.createAsync(SingleRadioButton).then(f => { + fixture = f; + radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton)); + radioButtonNativeElement = radioButtonDebugElement.nativeElement; + inputElement = radioButtonNativeElement.querySelector('input'); + + fixture.detectChanges(); + expect(inputElement.getAttribute('aria-labelledby')).toBe(null); + }); + })); + }); + describe('group with ngModel', () => { let fixture: ComponentFixture; let groupDebugElement: DebugElement; @@ -448,6 +498,27 @@ class RadioGroupWithNgModel { lastEvent: MdRadioChange; } +/** Simple test component with an aria-label set. */ +@Component({ + directives: [MdRadioButton], + template: `Spring` +}) +class RadioButtonWithAriaLabel { } + +/** Simple test component with an aria-label set. */ +@Component({ + directives: [MdRadioButton], + template: `Spring` +}) +class RadioButtonWithAriaLabelledby {} + +/** Simple test component with an aria-label set. */ +@Component({ + directives: [MdRadioButton], + template: `Spring` +}) +class SingleRadioButton {} + // TODO(jelbourn): remove eveything below when Angular supports faking events. /** diff --git a/src/components/radio/radio.ts b/src/components/radio/radio.ts index f4028ad8db40..c1ed4ffc7c57 100644 --- a/src/components/radio/radio.ts +++ b/src/components/radio/radio.ts @@ -239,6 +239,17 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor { } }) export class MdRadioButton implements OnInit { + /** + * Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will + * take precedence so this may be omitted. + */ + @Input('aria-label') ariaLabel: string = ''; + + /** + * Users can specify the `aria-labelledby` attribute which will be forwarded to the input element + */ + @Input('aria-labelledby') ariaLabelledby: string = null; + @HostBinding('class.md-radio-focused') private _isFocused: boolean; diff --git a/src/demo-app/radio/radio-demo.html b/src/demo-app/radio/radio-demo.html index 802d0070a149..a4a64dff2ac2 100644 --- a/src/demo-app/radio/radio-demo.html +++ b/src/demo-app/radio/radio-demo.html @@ -1,8 +1,8 @@

Basic Example

- Option 1 - Option 2 - Option 3 (disabled) + Option 1 + Option 2 + Option 3 (disabled)

Dynamic Example