Skip to content

Commit

Permalink
Improve typing of Show wrap prop to have children, add a test that a …
Browse files Browse the repository at this point in the history
…custom component with props could be used
  • Loading branch information
jmeistrich committed Jan 26, 2025
1 parent d13bffc commit 3fb7613
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/react/Show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface PropsIfReady<T> {
interface PropsBase<T> {
else?: ReactNode | (() => ReactNode);
$value?: Observable<T>;
wrap?: FC;
wrap?: FC<{ children: ReactNode }>;
children: ReactNode | ((value?: T) => ReactNode);
}

Expand Down
30 changes: 30 additions & 0 deletions tests/react.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,36 @@ describe('Show', () => {

expect(numRenders).toEqual(2);
});
test('Show wrap with wrapProps', async () => {
const obs = observable({
ok: false,
});
let testValue;
const Wrap = (props: { test: string; children?: any }) => {
testValue = props.test;
return props.children;
};
function Test() {
return (
<Show if={obs.ok} wrap={(props: { children: any }) => <Wrap test="tester" {...props} />}>
<span>hi</span>
</Show>
);
}
const { container } = render(createElement(Test));

let items = container.querySelectorAll('span');
expect(items.length).toEqual(0);

act(() => {
obs.ok.set(true);
});

items = container.querySelectorAll('span');
expect(items.length).toEqual(1);
expect(items[0].textContent).toEqual('hi');
expect(testValue).toEqual('tester');
});
});

describe('Switch', () => {
Expand Down

0 comments on commit 3fb7613

Please sign in to comment.