Skip to content

Commit 1e5759a

Browse files
committed
fix(radio): radio buttons not being a tab stop and missing focus indication
* Fixes the radio buttons not being tabable. * Adds focus indication to the radio buttons. Referencing #421.
1 parent a0d85d8 commit 1e5759a

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/lib/radio/radio.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- TODO(jelbourn): render the radio on either side of the content -->
22
<!-- TODO(mtlin): Evaluate trade-offs of using native radio vs. cost of additional bindings. -->
3-
<label [attr.for]="inputId" class="md-radio-label">
3+
<label [attr.for]="inputId" class="md-radio-label" [class.md-ripple-focused]="_isFocused">
44
<!-- The actual 'radio' part of the control. -->
55
<div class="md-radio-container">
66
<div class="md-radio-outer-circle"></div>
@@ -17,6 +17,7 @@
1717
[checked]="checked"
1818
[disabled]="disabled"
1919
[name]="name"
20+
[tabIndex]="tabindex"
2021
[attr.aria-label]="ariaLabel"
2122
[attr.aria-labelledby]="ariaLabelledby"
2223
(change)="_onInputChange($event)"

src/lib/radio/radio.spec.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('MdRadio', () => {
152152
expect(spies[1]).toHaveBeenCalledTimes(1);
153153
});
154154

155-
it(`should not emit a change event from the radio group when change group value
155+
it(`should not emit a change event from the radio group when change group value
156156
programmatically`, () => {
157157
expect(groupInstance.value).toBeFalsy();
158158

@@ -235,7 +235,7 @@ describe('MdRadio', () => {
235235
}
236236
}));
237237

238-
it(`should update the group's selected radio to null when unchecking that radio
238+
it(`should update the group's selected radio to null when unchecking that radio
239239
programmatically`, () => {
240240
let changeSpy = jasmine.createSpy('radio-group change listener');
241241
groupInstance.change.subscribe(changeSpy);
@@ -485,6 +485,28 @@ describe('MdRadio', () => {
485485

486486
expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
487487
});
488+
489+
it('should make the native input element a tab stop', () => {
490+
expect(fruitRadioNativeInputs[0].tabIndex).toBe(0);
491+
});
492+
493+
it('should add a ripple when the native input element is focused', () => {
494+
let hostElement = seasonRadioInstances[0].getHostElement() as HTMLElement;
495+
let input = hostElement.querySelector('input') as HTMLInputElement;
496+
let label = hostElement.querySelector('label') as HTMLLabelElement;
497+
498+
expect(label.classList).not.toContain('md-ripple-focused');
499+
500+
dispatchEvent('focus', input);
501+
fixture.detectChanges();
502+
503+
expect(label.classList).toContain('md-ripple-focused');
504+
505+
dispatchEvent('blur', input);
506+
fixture.detectChanges();
507+
508+
expect(label.classList).not.toContain('md-ripple-focused');
509+
});
488510
});
489511
});
490512

@@ -514,11 +536,11 @@ class RadiosInsideRadioGroup {
514536
<md-radio-button name="season" value="spring">Spring</md-radio-button>
515537
<md-radio-button name="season" value="summer">Summer</md-radio-button>
516538
<md-radio-button name="season" value="autum">Autumn</md-radio-button>
517-
539+
518540
<md-radio-button name="weather" value="warm">Spring</md-radio-button>
519541
<md-radio-button name="weather" value="hot">Summer</md-radio-button>
520542
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
521-
543+
522544
<span id="xyz">Baby Banana</span>
523545
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
524546
</md-radio-button>

src/lib/radio/radio.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ export class MdRadioButton implements OnInit {
239239
@HostBinding('class.md-radio-focused')
240240
_isFocused: boolean;
241241

242+
/** Tabindex for the input element. */
243+
@Input() tabindex: number = 0;
244+
242245
/** Whether this radio is checked. */
243246
private _checked: boolean = false;
244247

0 commit comments

Comments
 (0)