Skip to content

Commit

Permalink
fix(dialog): fire a change event when using arrow keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-g committed Jul 3, 2023
1 parent b2d2321 commit 65d31a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions radio/lib/single-selection-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ export class SingleSelectionController implements ReactiveController {
nextSibling.checked = true;
nextSibling.removeAttribute('tabindex');
nextSibling.focus();
// Fire a change event since the change is triggered by a user action.
// This matches native <input type="radio"> behavior.
nextSibling.dispatchEvent(new Event('change', {bubbles: true}));

break;
}
};
Expand Down
14 changes: 14 additions & 0 deletions radio/radio_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ describe('<md-radio>', () => {
expect(a2.element.checked).withContext('prev radio checked').toBeFalse();
});

it('Using arrow right should fire a change event', async () => {
const {harnesses, root} = await setupTest(radioGroupPreSelected);
const changeHandler = jasmine.createSpy('changeHandler');
root.addEventListener('change', changeHandler);
const [, a2] = harnesses;
expect(a2.element.checked)
.withContext('default checked radio')
.toBeTrue();

await simulateKeyDown(a2.element, 'ArrowRight');

expect(changeHandler).toHaveBeenCalledTimes(1);
});

it('Using arrow right on the last radio should select the first radio in that group',
async () => {
const {harnesses} = await setupTest(radioGroupPreSelected);
Expand Down

0 comments on commit 65d31a6

Please sign in to comment.