mirror of
https://github.com/material-components/material-web.git
synced 2024-09-11 21:57:41 +03:00
fix(radio): dispatches input event on select
PiperOrigin-RevId: 565522665
This commit is contained in:
parent
116b448639
commit
e444de3c02
@ -155,6 +155,8 @@ export class Radio extends LitElement {
|
||||
// Per spec, clicking on a radio input always selects it.
|
||||
this.checked = true;
|
||||
this.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
this.dispatchEvent(
|
||||
new InputEvent('input', {bubbles: true, composed: true}));
|
||||
}
|
||||
|
||||
private async handleKeydown(event: KeyboardEvent) {
|
||||
|
@ -139,6 +139,21 @@ describe('<md-radio>', () => {
|
||||
expect(changeHandler).toHaveBeenCalledTimes(1);
|
||||
expect(changeHandler).toHaveBeenCalledWith(jasmine.any(Event));
|
||||
});
|
||||
|
||||
it('Should trigger input event when a radio is selected', async () => {
|
||||
const {harnesses, root} = await setupTest(radioGroupPreSelected);
|
||||
const inputHandler = jasmine.createSpy('inputHandler');
|
||||
root.addEventListener('input', inputHandler);
|
||||
|
||||
const a3 = harnesses[2];
|
||||
await a3.clickWithMouse();
|
||||
|
||||
expect(a3.element.checked)
|
||||
.withContext('clicked radio checked')
|
||||
.toBeTrue();
|
||||
expect(inputHandler).toHaveBeenCalledTimes(1);
|
||||
expect(inputHandler).toHaveBeenCalledWith(jasmine.any(InputEvent));
|
||||
});
|
||||
});
|
||||
|
||||
describe('navigation', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user