-
-
Notifications
You must be signed in to change notification settings - Fork 79.2k
Handle delegated events in bubbling phase wherever possible #40574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
48f6fb8
443a8d8
3973239
36182fe
2dc80af
eae6f81
2261ae7
484f344
a084886
732493e
2c5cf8e
4fa651f
d3b28dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the change to this test could be made on master and still pass. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1358,7 +1358,7 @@ describe('Dropdown', () => { | |
btnDropdown.addEventListener('shown.bs.dropdown', () => { | ||
expect(btnDropdown).toHaveClass('show') | ||
|
||
const keyup = createEvent('keyup') | ||
const keyup = createEvent('keyup', { bubbles: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and all other |
||
|
||
keyup.key = 'Tab' | ||
document.dispatchEvent(keyup) | ||
|
@@ -1453,7 +1453,7 @@ describe('Dropdown', () => { | |
expect(triggerDropdownFirst).toHaveClass('show') | ||
expect(fixtureEl.querySelectorAll('.dropdown-menu.show')).toHaveSize(1) | ||
|
||
const keyup = createEvent('keyup') | ||
const keyup = createEvent('keyup', { bubbles: true }) | ||
keyup.key = 'Tab' | ||
|
||
document.dispatchEvent(keyup) | ||
|
@@ -1468,7 +1468,7 @@ describe('Dropdown', () => { | |
expect(triggerDropdownLast).toHaveClass('show') | ||
expect(fixtureEl.querySelectorAll('.dropdown-menu.show')).toHaveSize(1) | ||
|
||
const keyup = createEvent('keyup') | ||
const keyup = createEvent('keyup', { bubbles: true }) | ||
keyup.key = 'Tab' | ||
|
||
document.dispatchEvent(keyup) | ||
|
@@ -1567,7 +1567,7 @@ describe('Dropdown', () => { | |
}) | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
|
||
keydown.key = 'Escape' | ||
triggerDropdown.dispatchEvent(keydown) | ||
|
@@ -1634,7 +1634,7 @@ describe('Dropdown', () => { | |
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
input.focus() | ||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
|
||
keydown.key = 'ArrowUp' | ||
input.dispatchEvent(keydown) | ||
|
@@ -1668,7 +1668,7 @@ describe('Dropdown', () => { | |
const triggerDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]') | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
keydown.key = 'ArrowDown' | ||
|
||
triggerDropdown.dispatchEvent(keydown) | ||
|
@@ -1705,7 +1705,7 @@ describe('Dropdown', () => { | |
const triggerDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]') | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
keydown.key = 'ArrowDown' | ||
|
||
triggerDropdown.dispatchEvent(keydown) | ||
|
@@ -1738,7 +1738,7 @@ describe('Dropdown', () => { | |
const item2 = fixtureEl.querySelector('#item2') | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
const keydownArrowDown = createEvent('keydown') | ||
const keydownArrowDown = createEvent('keydown', { bubbles: true }) | ||
keydownArrowDown.key = 'ArrowDown' | ||
|
||
triggerDropdown.dispatchEvent(keydownArrowDown) | ||
|
@@ -1747,7 +1747,7 @@ describe('Dropdown', () => { | |
document.activeElement.dispatchEvent(keydownArrowDown) | ||
expect(document.activeElement).toEqual(item2, 'item2 is focused') | ||
|
||
const keydownArrowUp = createEvent('keydown') | ||
const keydownArrowUp = createEvent('keydown', { bubbles: true }) | ||
keydownArrowUp.key = 'ArrowUp' | ||
|
||
document.activeElement.dispatchEvent(keydownArrowUp) | ||
|
@@ -1782,7 +1782,7 @@ describe('Dropdown', () => { | |
}) | ||
}) | ||
|
||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
keydown.key = 'ArrowUp' | ||
triggerDropdown.dispatchEvent(keydown) | ||
}) | ||
|
@@ -1810,7 +1810,7 @@ describe('Dropdown', () => { | |
}) | ||
}) | ||
|
||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
keydown.key = 'ArrowDown' | ||
triggerDropdown.dispatchEvent(keydown) | ||
}) | ||
|
@@ -1837,7 +1837,7 @@ describe('Dropdown', () => { | |
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
expect(triggerDropdown).toHaveClass('show') | ||
input.dispatchEvent(createEvent('click')) | ||
input.dispatchEvent(createEvent('click', { bubbles: true })) | ||
}) | ||
|
||
triggerDropdown.click() | ||
|
@@ -1865,7 +1865,7 @@ describe('Dropdown', () => { | |
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
expect(triggerDropdown).toHaveClass('show') | ||
textarea.dispatchEvent(createEvent('click')) | ||
textarea.dispatchEvent(createEvent('click', { bubbles: true })) | ||
}) | ||
|
||
triggerDropdown.click() | ||
|
@@ -1892,9 +1892,7 @@ describe('Dropdown', () => { | |
}) | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
input.dispatchEvent(createEvent('click', { | ||
bubbles: true | ||
})) | ||
input.dispatchEvent(createEvent('click', { bubbles: true })) | ||
}) | ||
|
||
triggerDropdown.click() | ||
|
@@ -1919,14 +1917,14 @@ describe('Dropdown', () => { | |
const textarea = fixtureEl.querySelector('textarea') | ||
|
||
const test = (eventKey, elementToDispatch) => { | ||
const event = createEvent('keydown') | ||
const event = createEvent('keydown', { bubbles: true }) | ||
event.key = eventKey | ||
elementToDispatch.focus() | ||
elementToDispatch.dispatchEvent(event) | ||
expect(document.activeElement).toEqual(elementToDispatch, `${elementToDispatch.tagName} still focused`) | ||
} | ||
|
||
const keydownEscape = createEvent('keydown') | ||
const keydownEscape = createEvent('keydown', { bubbles: true }) | ||
keydownEscape.key = 'Escape' | ||
|
||
triggerDropdown.addEventListener('shown.bs.dropdown', () => { | ||
|
@@ -1982,7 +1980,7 @@ describe('Dropdown', () => { | |
// Key escape | ||
button.focus() | ||
// Key escape | ||
const keydownEscape = createEvent('keydown') | ||
const keydownEscape = createEvent('keydown', { bubbles: true }) | ||
keydownEscape.key = 'Escape' | ||
button.dispatchEvent(keydownEscape) | ||
|
||
|
@@ -2348,10 +2346,10 @@ describe('Dropdown', () => { | |
const triggerDropdown = fixtureEl.querySelector('[data-bs-toggle="dropdown"]') | ||
const dropdown = fixtureEl.querySelector('.dropdown') | ||
|
||
const keydown = createEvent('keydown') | ||
const keydown = createEvent('keydown', { bubbles: true }) | ||
keydown.key = 'ArrowDown' | ||
|
||
const keyup = createEvent('keyup') | ||
const keyup = createEvent('keyup', { bubbles: true }) | ||
keyup.key = 'ArrowUp' | ||
|
||
const handleArrowDown = () => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main change from this PR: whether or not the listener is for the capture phase is now explicit instead of being inferred based on whether this is a delegated handler or not.
I'm very open to changing this API. Suggestions welcome, especially if they mean we can avoid the
eslint-disable-next-line max-params
later in this file.