mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(Page.select): synthesized events should bubble
This patch fixes `Page.select` to synthesize bubbling events.
This commit is contained in:
parent
44cdf85b77
commit
3ecd98d634
@ -732,9 +732,8 @@ class Page extends EventEmitter {
|
||||
} else {
|
||||
element.value = values.shift();
|
||||
}
|
||||
|
||||
element.dispatchEvent(new Event('change'));
|
||||
element.dispatchEvent(new Event('input'));
|
||||
element.dispatchEvent(new Event('input', { 'bubbles': true }));
|
||||
element.dispatchEvent(new Event('change', { 'bubbles': true }));
|
||||
}, values);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
window.result = {
|
||||
onInput: null,
|
||||
onChange: null,
|
||||
onBubblingChange: null,
|
||||
onBubblingInput: null,
|
||||
};
|
||||
|
||||
let select = document.querySelector('select');
|
||||
@ -50,6 +52,18 @@
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.body.addEventListener('input', () => {
|
||||
result.onBubblingInput = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.body.addEventListener('change', () => {
|
||||
result.onBubblingChange = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -2244,6 +2244,13 @@ describe('Page', function() {
|
||||
expect(await page.evaluate(() => result.onChange)).toEqual(['blue', 'green', 'red']);
|
||||
}));
|
||||
|
||||
it('should respect event bubbling', SX(async function() {
|
||||
await page.goto(PREFIX + '/input/select.html');
|
||||
await page.select('select', 'blue');
|
||||
expect(await page.evaluate(() => result.onBubblingInput)).toEqual(['blue']);
|
||||
expect(await page.evaluate(() => result.onBubblingChange)).toEqual(['blue']);
|
||||
}));
|
||||
|
||||
it('should work with no options', SX(async function() {
|
||||
await page.goto(PREFIX + '/input/select.html');
|
||||
await page.evaluate(() => makeEmpty());
|
||||
|
Loading…
Reference in New Issue
Block a user