mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-06 13:11:46 +00:00
Add types for react-shadow-dom-retarget-events (#35200)
* Add types for react-shadow-dom-retarget-events * Use esModuleInterop for react-shadow-dom-retarget-events
This commit is contained in:
committed by
Sheetal Nandi
parent
ca6a7fe49a
commit
b3a144d609
@@ -0,0 +1,17 @@
|
||||
// Type definitions for react-shadow-dom-retarget-events 1.0
|
||||
// Project: https://github.com/weltn24/react-shadow-dom-retarget-events#readme
|
||||
// Definitions by: Remco Haszing <https://github.com/remcohaszing>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
export = retargetEvents;
|
||||
|
||||
/**
|
||||
* Fixes events for react components rendered in a `shadow dom`.
|
||||
*
|
||||
* When you render a react component inside `shadow dom` events will not be dispatched to react. I.e. when a user clicks in your react component nothing happens. This happens (or does not happen)
|
||||
* with any events.
|
||||
*
|
||||
* A bug is filed at [#10422](https://github.com/facebook/react/issues/10422).
|
||||
*/
|
||||
declare function retargetEvents(shadowRoot: ShadowRoot): void;
|
||||
@@ -0,0 +1,22 @@
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import retargetEvents from 'react-shadow-dom-retarget-events';
|
||||
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
return <div onClick={() => alert('I have been clicked')}>Click me</div>;
|
||||
}
|
||||
}
|
||||
|
||||
class MyCustomElement extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
const mountPoint = document.createElement('span');
|
||||
const shadowRoot = this.attachShadow({ mode: 'open' });
|
||||
shadowRoot.appendChild(mountPoint);
|
||||
ReactDOM.render(<App/>, mountPoint);
|
||||
retargetEvents(shadowRoot);
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define(name, MyCustomElement);
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"strictFunctionTypes": true,
|
||||
"jsx": "react",
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-shadow-dom-retarget-events-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user