|
12 | 12 |
|
13 | 13 | import {addWindowFocusTracking} from '../src';
|
14 | 14 | import {Cell, Column, Row, TableBody, TableHeader, TableView} from '@react-spectrum/table';
|
| 15 | +import Frame from 'react-frame-component'; |
15 | 16 | import {Key} from '@react-types/shared';
|
16 | 17 | import {mergeProps} from '@react-aria/utils';
|
17 | 18 | import React, {useEffect, useRef, useState} from 'react';
|
18 |
| -import ReactDOM from 'react-dom'; |
19 | 19 | import {SearchField} from '@react-spectrum/searchfield';
|
20 | 20 | import {useButton} from '@react-aria/button';
|
21 | 21 | import {useFocusRing} from '@react-aria/focus';
|
@@ -100,50 +100,34 @@ function SearchExample() {
|
100 | 100 | );
|
101 | 101 | }
|
102 | 102 |
|
103 |
| -function Button() { |
104 |
| - const buttonRef = useRef<HTMLButtonElement | null>(null); |
| 103 | +function MyButton(props) { |
| 104 | + const buttonRef = props.btnRef; |
105 | 105 |
|
106 |
| - const {buttonProps} = useButton({}, buttonRef); |
107 | 106 | const {focusProps, isFocusVisible, isFocused} = useFocusRing();
|
| 107 | + let {buttonProps} = useButton(props, buttonRef); |
108 | 108 |
|
109 | 109 | return (
|
110 |
| - <button ref={buttonRef} {...mergeProps(buttonProps, focusProps)}> |
| 110 | + <button ref={buttonRef} {...mergeProps(focusProps, buttonProps)}> |
111 | 111 | Focus Visible: {isFocusVisible ? 'true' : 'false'} <br />
|
112 | 112 | Focused: {isFocused ? 'true' : 'false'}
|
113 | 113 | </button>
|
114 | 114 | );
|
115 | 115 | }
|
116 | 116 |
|
117 |
| -const IframeWrapper = ({children}) => { |
118 |
| - const iframeRef = useRef<HTMLIFrameElement | null>(null); |
119 |
| - |
| 117 | +const IFrameExample = (props) => { |
| 118 | + let btnRef = useRef(null); |
120 | 119 | useEffect(() => {
|
121 |
| - if (iframeRef.current) { |
122 |
| - const main = document.createElement('main'); |
123 |
| - const iframeDocument = iframeRef.current.contentDocument; |
124 |
| - |
125 |
| - if (iframeDocument) { |
126 |
| - iframeDocument.body.innerHTML = ''; |
127 |
| - iframeDocument.body.appendChild(main); |
128 |
| - ReactDOM.render(children, main); |
129 |
| - |
130 |
| - return addWindowFocusTracking(iframeDocument.body); |
131 |
| - } |
132 |
| - } |
133 |
| - }, [children]); |
| 120 | + return addWindowFocusTracking(btnRef.current); |
| 121 | + }, []); |
134 | 122 |
|
135 |
| - return <iframe title="test" ref={iframeRef} />; |
136 |
| -}; |
137 |
| - |
138 |
| -function IFrameExample() { |
139 | 123 | return (
|
140 | 124 | <>
|
141 |
| - <Button /> |
142 |
| - <IframeWrapper> |
143 |
| - <Button /> |
144 |
| - <Button /> |
145 |
| - <Button /> |
146 |
| - </IframeWrapper> |
| 125 | + <MyButton /> |
| 126 | + <Frame {...props}> |
| 127 | + <MyButton btnRef={btnRef} /> |
| 128 | + <MyButton /> |
| 129 | + <MyButton /> |
| 130 | + </Frame> |
147 | 131 | </>
|
148 | 132 | );
|
149 |
| -} |
| 133 | +}; |
0 commit comments