mirror of
https://github.com/material-components/material-web.git
synced 2024-09-11 21:57:41 +03:00
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:
parent
65d31a68c1
commit
3436d023a0
@ -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;
|
||||
}
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user