diff --git a/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js b/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js index 03eafccd..724f5677 100644 --- a/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js +++ b/packages/react-native-web/src/exports/AppRegistry/__tests__/index-test.js @@ -39,6 +39,14 @@ describe('AppRegistry', () => { expect(styleElement).toMatchSnapshot(); }); + test('"getStyleElement" adds props to `; - document.head.insertAdjacentHTML('afterbegin', style); - styleElement = document.getElementById(id); - } - }; - /** * Computes whether the given element should automatically trigger the * `focus-ring`. @@ -83,20 +70,22 @@ const modality = () => { }; /** - * Add the focus ring to the focused element + * Add the focus ring style */ const addFocusRing = () => { - if (styleElement) { - styleElement.disabled = true; + if (styleElement && ruleExists) { + styleElement.sheet.deleteRule(0); + ruleExists = false; } }; /** - * Remove the focus ring + * Remove the focus ring style */ const removeFocusRing = () => { - if (styleElement) { - styleElement.disabled = false; + if (styleElement && !ruleExists) { + styleElement.sheet.insertRule(rule, 0); + ruleExists = true; } }; @@ -136,7 +125,7 @@ const modality = () => { }; if (document.body && document.body.addEventListener) { - initialize(); + removeFocusRing(); document.body.addEventListener('keydown', handleKeyDown, true); document.body.addEventListener('focus', handleFocus, true); document.body.addEventListener('blur', handleBlur, true); diff --git a/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js b/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js index 3abff5ef..bf36a3b2 100644 --- a/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js +++ b/website/storybook/2-apis/AppRegistry/AppRegistryScreen.js @@ -31,10 +31,18 @@ const AppRegistryScreen = () => ( /> + Use this for server-side rendering to HTML. Returns an object containing the given + application's element and a function to get styles once the element is rendered. + Additional props can be passed to the getStyleElement function, e.g., your + CSP policy may require a nonce to be set on style + elements. + + } label="web" name="static getApplication" - typeInfo="(appKey: string, appParameters: ?object) => { element: ReactElement; getStyleElement: () => ReactElement }" + typeInfo="(appKey: string, appParameters: ?object) => { element: ReactElement; getStyleElement: (props) => ReactElement }" />