-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: onFocus/onBlur/onBeforeInput have a matching event type (#19561)
* test: Add current behavior for event types of onFocus/onBlur * fix: onFocus/onBlur have a matching event type * fix useFocus * fix: don't compare native event types with react event types * Add FocusIn/FocusOutEventInterface * A simpler alternative fix * Add regression tests * Always pass React event type and fix beforeinput Co-authored-by: Dan Abramov <dan.abramov@me.com>
- Loading branch information
Showing
13 changed files
with
241 additions
and
41 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/react-dom/src/__tests__/ReactDOMEventPropagation-test.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/react-dom/src/events/__tests__/SyntheticFocusEvent-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
describe('SyntheticFocusEvent', () => { | ||
let React; | ||
let ReactDOM; | ||
let container; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
React = require('react'); | ||
ReactDOM = require('react-dom'); | ||
|
||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(container); | ||
container = null; | ||
}); | ||
|
||
test('onFocus events have the focus type', () => { | ||
const log = []; | ||
ReactDOM.render( | ||
<button | ||
onFocus={event => log.push(`onFocus: ${event.type}`)} | ||
onFocusCapture={event => log.push(`onFocusCapture: ${event.type}`)} | ||
/>, | ||
container, | ||
); | ||
const button = container.querySelector('button'); | ||
|
||
button.dispatchEvent( | ||
new FocusEvent('focusin', { | ||
bubbles: true, | ||
cancelable: false, | ||
}), | ||
); | ||
|
||
expect(log).toEqual(['onFocusCapture: focus', 'onFocus: focus']); | ||
}); | ||
|
||
test('onBlur events have the blur type', () => { | ||
const log = []; | ||
ReactDOM.render( | ||
<button | ||
onBlur={event => log.push(`onBlur: ${event.type}`)} | ||
onBlurCapture={event => log.push(`onBlurCapture: ${event.type}`)} | ||
/>, | ||
container, | ||
); | ||
const button = container.querySelector('button'); | ||
|
||
button.dispatchEvent( | ||
new FocusEvent('focusout', { | ||
bubbles: true, | ||
cancelable: false, | ||
}), | ||
); | ||
|
||
expect(log).toEqual(['onBlurCapture: blur', 'onBlur: blur']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.