Skip to content

Commit

Permalink
fix(radio): radio buttons not being a tab stop and missing focus indi…
Browse files Browse the repository at this point in the history
…cation

* Fixes the radio buttons not being tabable.
* Adds focus indication to the radio buttons.

Referencing angular#421.
  • Loading branch information
crisbeto committed Nov 8, 2016
1 parent a0d85d8 commit fcb3a26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/lib/radio/radio.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- TODO(jelbourn): render the radio on either side of the content -->
<!-- TODO(mtlin): Evaluate trade-offs of using native radio vs. cost of additional bindings. -->
<label [attr.for]="inputId" class="md-radio-label">
<!-- TODO(crisbeto): only show focus indication if focus came from a keyboard event -->
<label [attr.for]="inputId" class="md-radio-label" [class.md-ripple-focused]="_isFocused">
<!-- The actual 'radio' part of the control. -->
<div class="md-radio-container">
<div class="md-radio-outer-circle"></div>
Expand Down
26 changes: 22 additions & 4 deletions src/lib/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('MdRadio', () => {
expect(spies[1]).toHaveBeenCalledTimes(1);
});

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

Expand Down Expand Up @@ -235,7 +235,7 @@ describe('MdRadio', () => {
}
}));

it(`should update the group's selected radio to null when unchecking that radio
it(`should update the group's selected radio to null when unchecking that radio
programmatically`, () => {
let changeSpy = jasmine.createSpy('radio-group change listener');
groupInstance.change.subscribe(changeSpy);
Expand Down Expand Up @@ -485,6 +485,24 @@ describe('MdRadio', () => {

expect(fruitRadioNativeInputs[0].getAttribute('aria-labelledby')).toBe('uvw');
});

it('should add a ripple when the native input element is focused', () => {
let hostElement = seasonRadioInstances[0].getHostElement() as HTMLElement;
let input = hostElement.querySelector('input') as HTMLInputElement;
let label = hostElement.querySelector('label') as HTMLLabelElement;

expect(label.classList).not.toContain('md-ripple-focused');

dispatchEvent('focus', input);
fixture.detectChanges();

expect(label.classList).toContain('md-ripple-focused');

dispatchEvent('blur', input);
fixture.detectChanges();

expect(label.classList).not.toContain('md-ripple-focused');
});
});
});

Expand Down Expand Up @@ -514,11 +532,11 @@ class RadiosInsideRadioGroup {
<md-radio-button name="season" value="spring">Spring</md-radio-button>
<md-radio-button name="season" value="summer">Summer</md-radio-button>
<md-radio-button name="season" value="autum">Autumn</md-radio-button>
<md-radio-button name="weather" value="warm">Spring</md-radio-button>
<md-radio-button name="weather" value="hot">Summer</md-radio-button>
<md-radio-button name="weather" value="cool">Autumn</md-radio-button>
<span id="xyz">Baby Banana</span>
<md-radio-button name="fruit" value="banana" aria-label="Banana" aria-labelledby="xyz">
</md-radio-button>
Expand Down

0 comments on commit fcb3a26

Please sign in to comment.