Skip to content

Commit

Permalink
Merge pull request #48 from kivvvvv/fix/component-props-from-attrs-sh…
Browse files Browse the repository at this point in the history
…ould-respect-transient-props

fix component props from attrs not respecting provided transient props
  • Loading branch information
gregberge authored Aug 18, 2024
2 parents 1b4e2bf + 2d190bc commit 9a3c5b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/composite-actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ description: "Sets up Node.js and runs install"
runs:
using: composite
steps:
- uses: pnpm/action-setup@v2.2.4
- uses: pnpm/action-setup@v4
with:
version: 8
version: 9

- name: Setup Node.js
uses: actions/setup-node@v3
Expand Down
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 9a3c5b0

Please sign in to comment.