Overview
Data selectors let you conditionally apply styles based on a component’s props using Tailwind-style variants. This mirrors the familiardata-[state=open]:... pattern from Tailwind v4 and allows React Native components to react to their own prop values.
Basic Usage
Use thedata-[prop=value] variant with your classes. The name inside the brackets maps to a data-<prop> prop on the same component.
- Inside brackets, use the name without the
data-prefix (e.g.,statetargets thedata-stateprop) - The utility applies only when the prop equals the given value
Boolean Props
For boolean props, compare totrue or false:
String Props
You can match arbitrary string values:Multiple Variants
Chain multiple data selectors to target different prop states:How It Works
- During build, Uniwind recognizes attribute selectors generated by variants like
data-[prop=value]:...and records them as data constraints for the corresponding class - At runtime, when resolving a component’s
className, Uniwind compares the component’s props against those constraints and only applies the matching styles - Styles that depend on data selectors are evaluated against props and are not cached across prop changes
Supported Syntax
- Equality checks:
data-[prop=value]:utility - Boolean checks:
data-[prop=true]anddata-[prop=false] - Multiple different data selectors can be used on the same className string
Tailwind 4.3.3 and newer emit flattened variant selectors instead of nested ones. Data selectors compiled by these Tailwind versions need Uniwind 1.12.0+ or Uniwind Pro 1.7.0+. On older Uniwind versions, the variant is ignored and the style applies unconditionally.
Best Practices
- Prefer semantic prop names (e.g.,
state,status,variant,disabled) to keep selectors readable - Keep variant logic close to the component whose props drive the state
- Use data selectors for prop-driven state; use interactive variants for interaction states when available
Examples
Tabs
Toggle
Related
Supported Class Names
Learn which utilities and variants are supported
Platform Selectors
Combine data selectors with platform variants