-
Notifications
You must be signed in to change notification settings - Fork 48.5k
Determine event target in Shadow DOM correctly #12163
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
Closed
marionebl
wants to merge
5
commits into
facebook:master
from
marionebl:fix-event-propagation-across-shadow-dom
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c85de86
Determine event target in Shadow DOM correctly
marionebl d02aa87
Reformat code
marionebl e2d5e68
Remove test with dubious use
marionebl 12cb00f
Harden type check to ensure full safety
marionebl 230bc69
Use single quotes for style consistency
marionebl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,67 @@ | ||
import FixtureSet from '../../FixtureSet'; | ||
import TestCase from '../../TestCase'; | ||
|
||
const SUPPORTS_SHADOW_DOM = 'attachShadow' in HTMLElement.prototype; | ||
|
||
const React = window.React; | ||
const ReactDOM = window.ReactDOM; | ||
|
||
class SelectFixture extends React.Component { | ||
render() { | ||
if (!SUPPORTS_SHADOW_DOM) { | ||
return ( | ||
<div>Browser does not support Shadow DOM, no tests to execute.</div> | ||
); | ||
} | ||
|
||
return ( | ||
<FixtureSet title="Shadow DOM" description=""> | ||
<TestCase title="Event listeners in shadow-dom" relatedIssues="4963"> | ||
<TestCase.Steps> | ||
<li>Click on the orange box</li> | ||
</TestCase.Steps> | ||
<TestCase.ExpectedResult> | ||
The box should turn green | ||
</TestCase.ExpectedResult> | ||
<Shadow> | ||
<Box /> | ||
</Shadow> | ||
</TestCase> | ||
</FixtureSet> | ||
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. we should probably also include a |
||
); | ||
} | ||
} | ||
|
||
class Shadow extends React.Component { | ||
componentDidMount() { | ||
this.ref.attachShadow({mode: 'open'}); | ||
const el = document.createElement('div'); | ||
this.ref.shadowRoot.appendChild(el); | ||
ReactDOM.render(this.props.children, el); | ||
} | ||
|
||
render() { | ||
return <div ref={ref => (this.ref = ref)} />; | ||
} | ||
} | ||
|
||
class Box extends React.Component { | ||
state = {active: false}; | ||
|
||
render() { | ||
const style = { | ||
height: 100, | ||
background: this.state.active ? 'green' : 'orange', | ||
color: 'white', | ||
marginBottom: 20, | ||
}; | ||
return ( | ||
<div | ||
onClick={() => this.setState({active: !this.state.active})} | ||
style={style} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default SelectFixture; |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this test case fail without this PR? My understanding is the event would still fire, but the
target
would be wrong, the TestCase doesn't assert anything about the target, only that the event was seen.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.
The test case fails without the other changes in this PR