Skip to content

Commit 689cc81

Browse files
authored
fix(browser-repl): forward ref on the themed shell component (#2070)
1 parent d2eadb4 commit 689cc81

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/browser-repl/src/components/shell.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,11 @@ export class _Shell extends Component<ShellProps, ShellState> {
462462

463463
type DefaultProps = keyof (typeof _Shell)['defaultProps'];
464464

465-
export const Shell = function ShellWithDarkMode(
466-
props: Omit<ShellProps, DefaultProps | 'darkMode'> &
465+
export const Shell = React.forwardRef<
466+
_Shell,
467+
Omit<ShellProps, DefaultProps | 'darkMode'> &
467468
Partial<Pick<ShellProps, DefaultProps>>
468-
) {
469+
>(function ShellWithDarkMode(props, ref) {
469470
const darkMode = useDarkMode();
470-
return <_Shell darkMode={darkMode} {...props}></_Shell>;
471-
};
471+
return <_Shell darkMode={darkMode} ref={ref} {...props}></_Shell>;
472+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import { Shell } from './index';
3+
import { expect } from '../testing/chai';
4+
import { mount } from '../testing/enzyme';
5+
6+
describe('Shell', function () {
7+
it('should provide access to ref', function () {
8+
const ref = React.createRef<any>();
9+
mount(<Shell ref={ref} runtime={{} as any}></Shell>);
10+
expect(ref.current).to.have.property('state');
11+
expect(ref.current).to.have.property('props');
12+
expect(ref.current).to.have.property('editor');
13+
});
14+
});

0 commit comments

Comments
 (0)