Skip to content

Commit b48d22d

Browse files
kivvvvvgregberge
authored andcommitted
fix: component props from attrs not respecting provided transient props
1 parent 1b4e2bf commit b48d22d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/index.test.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,20 @@ describe("twc", () => {
279279
expect(svg).toBeDefined();
280280
expect(svg.tagName).toBe("SVG");
281281
});
282+
283+
test("component props from attrs should respect provided transient props", () => {
284+
type ButtonProps = TwcComponentProps<"button"> & {
285+
variant: "primary" | "secondary";
286+
};
287+
const Button = twc.button
288+
.transientProps(["variant"])
289+
.attrs<ButtonProps>(({ type = "button", variant }) => {
290+
expect(variant).toBe("primary");
291+
return { type };
292+
})`text-xl`;
293+
render(<Button data-testid="button" variant="primary" />);
294+
295+
const renderedButton = screen.getByTestId("button");
296+
expect(renderedButton.getAttribute("variant")).toBeNull();
297+
});
282298
});

src/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const createTwc = <TCompose extends AbstractCompose = typeof clsx>(
171171

172172
if (attrs === undefined) {
173173
template.attrs = (attrs: Attributes) => {
174-
return createTemplate(attrs);
174+
return createTemplate(attrs, shouldForwardProp);
175175
};
176176
}
177177

0 commit comments

Comments
 (0)