chore(list): simplify next sibling end user navigation

nextSibling.click() takes care of:
- setting checked to true
- focusing nextSibling
- fire a change event
This commit is contained in:
christophe-g 2023-07-05 22:27:12 +02:00
parent 65d31a68c1
commit 3436d023a0
2 changed files with 4 additions and 9 deletions

View File

@ -215,14 +215,9 @@ export class SingleSelectionController implements ReactiveController {
}
}
// The next sibling should be checked and focused.
nextSibling.checked = true;
// The next sibling should be checked, focused and dispatch a change event
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}));
nextSibling.click();
break;
}
};

View File

@ -138,7 +138,7 @@ describe('<md-radio>', () => {
expect(a2.element.checked).withContext('prev radio checked').toBeFalse();
});
it('Using arrow right should fire a change event', async () => {
it('dispatched a change event on user navigation', async () => {
const {harnesses, root} = await setupTest(radioGroupPreSelected);
const changeHandler = jasmine.createSpy('changeHandler');
root.addEventListener('change', changeHandler);
@ -146,7 +146,7 @@ describe('<md-radio>', () => {
expect(a2.element.checked)
.withContext('default checked radio')
.toBeTrue();
await simulateKeyDown(a2.element, 'ArrowRight');
expect(changeHandler).toHaveBeenCalledTimes(1);