Skip to content

Conversation

@micnic
Copy link

@micnic micnic commented Oct 30, 2025

Description

This PR adds the requiredVariants option for mandatory variants, that is an array of strings representing a part of defined variants, they are checked at runtime and will throw if the user did not provide them.

Usage example:

const buttonVariants = tv({
  base: 'cursor-pointer',
  variants: {
    intent: {
      primary: 'bg-blue-700',
      secondary: 'bg-gray-500'
    }
  },
  requiredVariants: ['intent']
});

buttonVariants({ intent: 'primary' }); // TS will expect `intent` to be provided

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@jrgarciadev
Copy link
Member

@wingkwong please check

@jrgarciadev
Copy link
Member

@tianenpang @wingkwong please check

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. please resolve conflicts.
  2. if a default is provided, then the variant must be there. required variant for this case seems counterintuitive.

}): TVReturnType<V, S, B, EV, ES, E>;
/**
* Required variants that must be provided at runtime and are required in the type system.
* @see https://www.tailwind-variants.org/docs/variants#required-variants
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please supplement in docs. Currently this section doesn't exist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a PR in the docs repo: heroui-inc/tailwind-variants-docs#48

@micnic
Copy link
Author

micnic commented Nov 24, 2025

2. if a default is provided, then the variant must be there. required variant for this case seems counterintuitive.

What would be the expected behavior when both defaultVariants and requiredVariants contain the same variant? Should I filter out the defaultVariants from the requiredVariants check in runtime and types declaration? @wingkwong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants