Skip to content

Commit 3ebcc66

Browse files
authored
Fix FF FocusRing story with iframe (#6001)
* Fix FF FocusRing story with iframe
1 parent e54e3c5 commit 3ebcc66

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"react": "^18.0.0",
161161
"react-axe": "^3.0.2",
162162
"react-dom": "^18.0.0",
163+
"react-frame-component": "^5.0.0",
163164
"react-test-renderer": "^16.9.0",
164165
"recast": "^0.20",
165166
"recursive-readdir": "^2.2.2",

packages/@react-aria/interactions/stories/useFocusRing.stories.tsx

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
import {addWindowFocusTracking} from '../src';
1414
import {Cell, Column, Row, TableBody, TableHeader, TableView} from '@react-spectrum/table';
15+
import Frame from 'react-frame-component';
1516
import {Key} from '@react-types/shared';
1617
import {mergeProps} from '@react-aria/utils';
1718
import React, {useEffect, useRef, useState} from 'react';
18-
import ReactDOM from 'react-dom';
1919
import {SearchField} from '@react-spectrum/searchfield';
2020
import {useButton} from '@react-aria/button';
2121
import {useFocusRing} from '@react-aria/focus';
@@ -100,50 +100,34 @@ function SearchExample() {
100100
);
101101
}
102102

103-
function Button() {
104-
const buttonRef = useRef<HTMLButtonElement | null>(null);
103+
function MyButton(props) {
104+
const buttonRef = props.btnRef;
105105

106-
const {buttonProps} = useButton({}, buttonRef);
107106
const {focusProps, isFocusVisible, isFocused} = useFocusRing();
107+
let {buttonProps} = useButton(props, buttonRef);
108108

109109
return (
110-
<button ref={buttonRef} {...mergeProps(buttonProps, focusProps)}>
110+
<button ref={buttonRef} {...mergeProps(focusProps, buttonProps)}>
111111
Focus Visible: {isFocusVisible ? 'true' : 'false'} <br />
112112
Focused: {isFocused ? 'true' : 'false'}
113113
</button>
114114
);
115115
}
116116

117-
const IframeWrapper = ({children}) => {
118-
const iframeRef = useRef<HTMLIFrameElement | null>(null);
119-
117+
const IFrameExample = (props) => {
118+
let btnRef = useRef(null);
120119
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+
}, []);
134122

135-
return <iframe title="test" ref={iframeRef} />;
136-
};
137-
138-
function IFrameExample() {
139123
return (
140124
<>
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>
147131
</>
148132
);
149-
}
133+
};

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21088,6 +21088,11 @@ react-error-overlay@6.0.9:
2108821088
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a"
2108921089
integrity sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew==
2109021090

21091+
react-frame-component@^5.0.0:
21092+
version "5.2.6"
21093+
resolved "https://registry.yarnpkg.com/react-frame-component/-/react-frame-component-5.2.6.tgz#0d9991d251ff1f7177479d8f370deea06b824b79"
21094+
integrity sha512-CwkEM5VSt6nFwZ1Op8hi3JB5rPseZlmnp5CGiismVTauE6S4Jsc4TNMlT0O7Cts4WgIC3ZBAQ2p1Mm9XgLbj+w==
21095+
2109121096
react-inspector@^5.1.0:
2109221097
version "5.1.1"
2109321098
resolved "https://registry.yarnpkg.com/react-inspector/-/react-inspector-5.1.1.tgz#58476c78fde05d5055646ed8ec02030af42953c8"

0 commit comments

Comments
 (0)