Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shared-events-no-container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"victory-shared-events": patch
---

Fix `VictorySharedEvents` crashing when rendered with neither `events` nor `container`: it now falls back to `groupComponent`, as it already did with events
45 changes: 45 additions & 0 deletions packages/victory-shared-events/src/victory-shared-events.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { render } from "@testing-library/react";
import React from "react";

import { VictorySharedEvents } from "./victory-shared-events";

describe("victory-shared-events", () => {
it("renders children in groupComponent without events or container", () => {
const { container } = render(
<svg>
<VictorySharedEvents>
<rect data-testid="child" />
</VictorySharedEvents>
</svg>,
);
const group = container.querySelector("svg > g");
expect(group).not.toBeNull();
expect(group?.querySelector("[data-testid='child']")).not.toBeNull();
});

it("renders children in a custom groupComponent without events or container", () => {
const { container } = render(
<svg>
<VictorySharedEvents groupComponent={<g data-testid="group" />}>
<rect data-testid="child" />
</VictorySharedEvents>
</svg>,
);
const group = container.querySelector("[data-testid='group']");
expect(group).not.toBeNull();
expect(group?.querySelector("[data-testid='child']")).not.toBeNull();
});

it("renders children in container without events", () => {
const { container } = render(
<svg>
<VictorySharedEvents container={<g data-testid="container" />}>
<rect data-testid="child" />
</VictorySharedEvents>
</svg>,
);
const group = container.querySelector("[data-testid='container']");
expect(group).not.toBeNull();
expect(group?.querySelector("[data-testid='child']")).not.toBeNull();
});
});
4 changes: 3 additions & 1 deletion packages/victory-shared-events/src/victory-shared-events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ export class VictorySharedEvents extends React.Component<VictorySharedEventsProp
if (events) {
return this.getContainer(this.props, this.baseProps, events);
}
return React.cloneElement(this.props.container as React.ReactElement<any>, {
const container = (this.props.container ||
this.props.groupComponent) as React.ReactElement<any>;
return React.cloneElement(container, {
children: this.props.children,
});
}
Expand Down
Loading