1- import React , { useState , useEffect , useRef , useMemo } from 'react' ;
1+ import React , {
2+ useState ,
3+ useEffect ,
4+ useRef ,
5+ useMemo ,
6+ useCallback ,
7+ } from 'react' ;
28import Scrollable from './Scrollable' ;
39import PreviewHint from './PreviewHint' ;
410import AddHtml from './AddHtml' ;
@@ -8,7 +14,14 @@ function selectByCssPath(rootNode, cssPath) {
814 return rootNode ?. querySelector ( cssPath . toString ( ) . replace ( / ^ b o d y > / , '' ) ) ;
915}
1016
11- function Preview ( { markup, accessibleRoles, elements, dispatch, variant } ) {
17+ function Preview ( {
18+ markup,
19+ accessibleRoles,
20+ elements,
21+ dispatch,
22+ variant,
23+ forwardedRef,
24+ } ) {
1225 // Okay, listen up. `highlighted` can be a number of things, as I wanted to
1326 // keep a single variable to represent the state. This to reduce bug count
1427 // by creating out-of-sync states.
@@ -33,7 +46,13 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) {
3346 element : highlighted ,
3447 } ) ;
3548
36- // TestingLibraryDom?.getSuggestedQuery(highlighted, 'get').toString() : null
49+ const refSetter = useCallback ( ( node ) => {
50+ if ( typeof forwardedRef === 'function' ) {
51+ forwardedRef ( node || null ) ;
52+ }
53+
54+ htmlRoot . current = node ;
55+ } , [ ] ) ;
3756
3857 useEffect ( ( ) => {
3958 const container = document . createElement ( 'div' ) ;
@@ -154,7 +173,7 @@ function Preview({ markup, accessibleRoles, elements, dispatch, variant }) {
154173 className = "preview"
155174 onClick = { handleClick }
156175 onMouseMove = { handleMove }
157- ref = { htmlRoot }
176+ ref = { refSetter }
158177 dangerouslySetInnerHTML = { {
159178 __html : actualMarkup ,
160179 } }
0 commit comments