Skip to content

Commit

Permalink
fix(browser-repl): forward ref on the themed shell component (#2070)
Browse files Browse the repository at this point in the history
  • Loading branch information
gribnoysup authored Jul 10, 2024
1 parent d2eadb4 commit 689cc81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/browser-repl/src/components/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ export class _Shell extends Component<ShellProps, ShellState> {

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

export const Shell = function ShellWithDarkMode(
props: Omit<ShellProps, DefaultProps | 'darkMode'> &
export const Shell = React.forwardRef<
_Shell,
Omit<ShellProps, DefaultProps | 'darkMode'> &
Partial<Pick<ShellProps, DefaultProps>>
) {
>(function ShellWithDarkMode(props, ref) {
const darkMode = useDarkMode();
return <_Shell darkMode={darkMode} {...props}></_Shell>;
};
return <_Shell darkMode={darkMode} ref={ref} {...props}></_Shell>;
});
14 changes: 14 additions & 0 deletions packages/browser-repl/src/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Shell } from './index';
import { expect } from '../testing/chai';
import { mount } from '../testing/enzyme';

describe('Shell', function () {
it('should provide access to ref', function () {
const ref = React.createRef<any>();
mount(<Shell ref={ref} runtime={{} as any}></Shell>);
expect(ref.current).to.have.property('state');
expect(ref.current).to.have.property('props');
expect(ref.current).to.have.property('editor');
});
});

0 comments on commit 689cc81

Please sign in to comment.