Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[recipes] Handle option field that doesn't exist in config #1337

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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/fast-kings-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vanilla-extract/recipes': minor
---

Handle option field that doesn't exist in config
2 changes: 1 addition & 1 deletion packages/recipes/src/createRuntimeFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const createRuntimeFn = <Variants extends VariantGroups>(

const selectionClassName =
// @ts-expect-error
config.variantClassNames[variantName][selection];
config.variantClassNames?.[variantName]?.[selection];

if (selectionClassName) {
className += ' ' + selectionClassName;
Expand Down
7 changes: 7 additions & 0 deletions tests/recipes/recipes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ describe('recipes', () => {
);
});

it('should not fall on arbitrary fields', () => {
// @ts-expect-error Field should be not defined in this test
expect(basic({ notHere: 'arbitrary-prop' })).toMatchInlineSnapshot(
`"recipes_basic__niwegb0 recipes_basic_spaceWithDefault_small__niwegb1"`,
);
});

it('should return requested variants', () => {
expect(
basic({
Expand Down