Skip to content

Commit db62acf

Browse files
committed
readio
1 parent 9e85799 commit db62acf

File tree

4 files changed

+89
-5
lines changed

4 files changed

+89
-5
lines changed

src/components/radio/radio.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
[name]="name"
1616
(change)="onInputChange($event)"
1717
(focus)="onInputFocus()"
18-
(blur)="onInputBlur()" />
18+
(blur)="onInputBlur()"
19+
[attr.aria-label]="ariaLabel"
20+
[attr.aria-labelledby]="ariaLabelledby"/>
1921

2022
<!-- The label content for radio control. -->
2123
<div class="md-radio-label-content">

src/components/radio/radio.spec.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('MdRadio', () => {
195195
expect(radioInstances[1].checked).toBe(true);
196196
});
197197

198-
it('should deselect all of the checkboxes when the group value is cleared', () => {
198+
it('should deselect all of the radioButtones when the group value is cleared', () => {
199199
radioInstances[0].checked = true;
200200

201201
expect(groupInstance.value).toBeTruthy();
@@ -206,6 +206,56 @@ describe('MdRadio', () => {
206206
});
207207
});
208208

209+
describe('with provided aria-label ', () => {
210+
let fixture: ComponentFixture<any>;
211+
let radioButtonDebugElement: DebugElement;
212+
let radioButtonNativeElement: HTMLElement;
213+
let inputElement: HTMLInputElement;
214+
215+
it('should use the provided aria-label', async(() => {
216+
builder.createAsync(RadioButtonWithAriaLabel).then(f => {
217+
fixture = f;
218+
radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton));
219+
radioButtonNativeElement = radioButtonDebugElement.nativeElement;
220+
inputElement = <HTMLInputElement>radioButtonNativeElement.querySelector('input');
221+
222+
fixture.detectChanges();
223+
expect(inputElement.getAttribute('aria-label')).toBe('superRadio');
224+
});
225+
}));
226+
});
227+
228+
describe('with provided aria-labelledby ', () => {
229+
let fixture: ComponentFixture<any>;
230+
let radioButtonDebugElement: DebugElement;
231+
let radioButtonNativeElement: HTMLElement;
232+
let inputElement: HTMLInputElement;
233+
234+
it('should use the provided aria-labelledby', async(() => {
235+
builder.createAsync(RadioButtonWithAriaLabelledby).then(f => {
236+
fixture = f;
237+
radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton));
238+
radioButtonNativeElement = radioButtonDebugElement.nativeElement;
239+
inputElement = <HTMLInputElement>radioButtonNativeElement.querySelector('input');
240+
241+
fixture.detectChanges();
242+
expect(inputElement.getAttribute('aria-labelledby')).toBe('superByRadio');
243+
});
244+
}));
245+
246+
it('should not assign aria-labelledby if none is provided', async(() => {
247+
builder.createAsync(SingleRadioButton).then(f => {
248+
fixture = f;
249+
radioButtonDebugElement = fixture.debugElement.query(By.directive(MdRadioButton));
250+
radioButtonNativeElement = radioButtonDebugElement.nativeElement;
251+
inputElement = <HTMLInputElement>radioButtonNativeElement.querySelector('input');
252+
253+
fixture.detectChanges();
254+
expect(inputElement.getAttribute('aria-labelledby')).toBe(null);
255+
});
256+
}));
257+
});
258+
209259
describe('group with ngModel', () => {
210260
let fixture: ComponentFixture<RadioGroupWithNgModel>;
211261
let groupDebugElement: DebugElement;
@@ -448,6 +498,27 @@ class RadioGroupWithNgModel {
448498
lastEvent: MdRadioChange;
449499
}
450500

501+
/** Simple test component with an aria-label set. */
502+
@Component({
503+
directives: [MdRadioButton],
504+
template: `<md-radio-button name="season" value="spring" aria-label="superRadio">Spring</md-radio-button>`
505+
})
506+
class RadioButtonWithAriaLabel { }
507+
508+
/** Simple test component with an aria-label set. */
509+
@Component({
510+
directives: [MdRadioButton],
511+
template: `<md-radio-button name="season" value="spring" aria-labelledby="superByRadio">Spring</md-radio-button>`
512+
})
513+
class RadioButtonWithAriaLabelledby {}
514+
515+
/** Simple test component with an aria-label set. */
516+
@Component({
517+
directives: [MdRadioButton],
518+
template: `<md-radio-button name="season" value="spring" >Spring</md-radio-button>`
519+
})
520+
class SingleRadioButton {}
521+
451522
// TODO(jelbourn): remove eveything below when Angular supports faking events.
452523

453524
/**

src/components/radio/radio.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
239239
}
240240
})
241241
export class MdRadioButton implements OnInit {
242+
/**
243+
* Attached to the aria-label attribute of the host element. In most cases, arial-labelledby will
244+
* take precedence so this may be omitted.
245+
*/
246+
@Input('aria-label') ariaLabel: string = '';
247+
248+
/**
249+
* Users can specify the `aria-labelledby` attribute which will be forwarded to the input element
250+
*/
251+
@Input('aria-labelledby') ariaLabelledby: string = null;
252+
242253
@HostBinding('class.md-radio-focused')
243254
private _isFocused: boolean;
244255

src/demo-app/radio/radio-demo.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1>Basic Example</h1>
22
<section class="demo-section">
3-
<md-radio-button name="group1">Option 1</md-radio-button>
4-
<md-radio-button name="group1">Option 2</md-radio-button>
5-
<md-radio-button name="group1" disabled="true">Option 3 (disabled)</md-radio-button>
3+
<md-radio-button name="group1" aria-label="option1">Option 1</md-radio-button>
4+
<md-radio-button name="group1" aria-label="option2">Option 2</md-radio-button>
5+
<md-radio-button name="group1" disabled="true" aria-labelledby="option3">Option 3 (disabled)</md-radio-button>
66
</section>
77
<h1>Dynamic Example</h1>
88
<section class="demo-section">

0 commit comments

Comments
 (0)