Skip to content

Commit fcb3a26

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 fcb3a26

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-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,7 @@
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+
<!-- TODO(crisbeto): only show focus indication if focus came from a keyboard event -->
4+
<label [attr.for]="inputId" class="md-radio-label" [class.md-ripple-focused]="_isFocused">
45
<!-- The actual 'radio' part of the control. -->
56
<div class="md-radio-container">
67
<div class="md-radio-outer-circle"></div>

src/lib/radio/radio.spec.ts

Lines changed: 22 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,24 @@ describe('MdRadio', () => {
485485

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

@@ -514,11 +532,11 @@ class RadiosInsideRadioGroup {
514532
<md-radio-button name="season" value="spring">Spring</md-radio-button>
515533
<md-radio-button name="season" value="summer">Summer</md-radio-button>
516534
<md-radio-button name="season" value="autum">Autumn</md-radio-button>
517-
535+
518536
<md-radio-button name="weather" value="warm">Spring</md-radio-button>
519537
<md-radio-button name="weather" value="hot">Summer</md-radio-button>
520538
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
521-
539+
522540
<span id="xyz">Baby Banana</span>
523541
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
524542
</md-radio-button>

0 commit comments

Comments
 (0)