Skip to content

Commit

Permalink
fix component props from attrs not respecting provided transient props
Browse files Browse the repository at this point in the history
  • Loading branch information
kivvvvv committed Aug 12, 2024
1 parent 1b4e2bf commit 3b9823a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,20 @@ describe("twc", () => {
expect(svg).toBeDefined();
expect(svg.tagName).toBe("SVG");
});

test("component props from attrs should respect provided transient props", () => {
type ButtonProps = TwcComponentProps<"button"> & {
variant: "primary" | "secondary";
};
const Button = twc.button
.transientProps(["variant"])
.attrs<ButtonProps>(({ type = "button", variant }) => {
expect(variant).toBe("primary");
return { type };
})`text-xl`;
render(<Button data-testid="button" variant="primary" />);

const renderedButton = screen.getByTestId("button");
expect(renderedButton.getAttribute("variant")).toBeNull();
});
});
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const createTwc = <TCompose extends AbstractCompose = typeof clsx>(

if (attrs === undefined) {
template.attrs = (attrs: Attributes) => {
return createTemplate(attrs);
return createTemplate(attrs, shouldForwardProp);
};
}

Expand Down

0 comments on commit 3b9823a

Please sign in to comment.