Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Ensure style and links are included for inheritCSS (#48)
Browse files Browse the repository at this point in the history
* Ensure style and links are included for inheritCSS

* bump version to 1.3.3

Co-authored-by: SL-SWoods <[email protected]>
  • Loading branch information
oriondean and swoods-scottlogic authored Jan 29, 2020
1 parent a3a07bd commit df9136e
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions demo/src/pages/childWindow/ChildWindow.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ label {
.checkboxes {
margin-bottom: 20px;
}

.external_style code {
color: navy;
}
2 changes: 1 addition & 1 deletion demo/src/pages/childWindow/ChildWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const INITIAL_TEXT_AREA_VALUE: string = `<div class="App_containerApp__F0W0w">
</div>`;
const CHILD_BODY_AS_HOOK_OPTION = (
<div className="App_containerApp__F0W0w">
<p>
<p className="ChildWindow_external_style__2s3g_">
This jsx was passed in as a part of <code>CHILD_WINDOW_HOOK_OPTIONS</code>
. See "Code Example" Section for more information.
</p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openfin-react-hooks",
"version": "1.3.2",
"version": "1.3.3",
"description": "A collection of React Hooks built on top of the Openfin API",
"main": "dist/index.js",
"scripts": {
Expand Down
7 changes: 5 additions & 2 deletions src/useChildWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ export default ({

const inheritCss = useCallback(() => {
if (parentDocument && htmlDocument) {
const parentStyles = parentDocument.getElementsByTagName("style");
injectNodes(parentStyles, htmlDocument);
const externalStyles = parentDocument.styleSheets;
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < externalStyles.length; i ++ ) {
injectNode(externalStyles[i].ownerNode, htmlDocument);
}
}
}, [parentDocument, injectNodes, htmlDocument]);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/helpers/inject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const injectNode = (
node: HTMLStyleElement | HTMLScriptElement,
node: HTMLStyleElement | HTMLScriptElement | Node,
document: HTMLDocument,
) => {
if (document) {
Expand Down

0 comments on commit df9136e

Please sign in to comment.