<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rivai Nasution on Medium]]></title>
        <description><![CDATA[Stories by Rivai Nasution on Medium]]></description>
        <link>https://medium.com/@rivainasution?source=rss-d27cc2537172------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cY9yv4XuJfg7F58P5HcEyA.jpeg</url>
            <title>Stories by Rivai Nasution on Medium</title>
            <link>https://medium.com/@rivainasution?source=rss-d27cc2537172------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:52:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rivainasution/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 36] Native Select: When the Browser Is Enough]]></title>
            <link>https://medium.com/@rivainasution/shadcn-ui-react-series-part-36-native-select-when-the-browser-is-enough-edeac144757b?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/edeac144757b</guid>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Tue, 24 Feb 2026 02:01:01 GMT</pubDate>
            <atom:updated>2026-02-24T02:01:01.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li>Part 32: Field</li><li>Part 33: Input Group</li><li>Part 34: Text Area</li><li>Part 35: Select</li><li>Part 36: Native Select</li><li>Part 37: Combobox</li><li>Part 38: Date Picker</li><li>Part 39: Calendar</li><li>Part 40: Slider</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/native-select">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/native-select">here</a></p><h3>Why Native Select still exists</h3><p>After building a fully composable Select (Part 35),<br>you might think:</p><p>“Why would I ever go back to native?”</p><p>Because sometimes…</p><p>you don’t need a portal<br>you don’t need grouped animations<br>you don’t need scroll buttons<br>you don’t need custom positioning</p><p>You just need a dropdown.</p><p>Fast.<br>Stable.<br>Mobile-friendly.</p><p>Native select is not outdated.<br>It’s just limited.</p><p>And when your use case is simple,<br>limitations become advantages.</p><h3>What Native Select actually gives you</h3><p>Native Select gives you:</p><ul><li>zero portal overhead</li><li>perfect mobile UX (especially iOS)</li><li>OS-level accessibility</li><li>minimal JS</li><li>predictable performance</li></ul><p>It sacrifices full styling control.<br>But gains reliability.</p><p>This component wraps the browser primitive — <br>and aligns it visually with the design system.</p><h3>1. Create components/ui/native-select.tsx</h3><p>Same idea as Input or Textarea.<br>Style the primitive. Don’t fight it.</p><p><strong>File location</strong><br>components/ui/native-select.tsx</p><pre>import * as React from &quot;react&quot;;<br><br>import { cn } from &quot;@/lib/utils&quot;;<br>import { ChevronDownIcon } from &quot;lucide-react&quot;;<br><br>type NativeSelectProps = Omit&lt;React.ComponentProps&lt;&quot;select&quot;&gt;, &quot;size&quot;&gt; &amp; {<br> size?: &quot;sm&quot; | &quot;default&quot;;<br>};<br><br>function NativeSelect({<br> className,<br> size = &quot;default&quot;,<br> ...props<br>}: NativeSelectProps) {<br> return (<br>  &lt;div<br>   className={cn(<br>    &quot;group/native-select relative w-fit has-[select:disabled]:opacity-50&quot;,<br>    className,<br>   )}<br>   data-slot=&quot;native-select-wrapper&quot;<br>   data-size={size}<br>  &gt;<br>   &lt;select<br>    data-slot=&quot;native-select&quot;<br>    data-size={size}<br>    className=&quot;border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 h-8 w-full min-w-0 appearance-none rounded-lg border bg-transparent py-1 pr-8 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-[size=sm]:py-0.5 outline-none disabled:pointer-events-none disabled:cursor-not-allowed&quot;<br>    {...props}<br>   /&gt;<br>   &lt;ChevronDownIcon<br>    className=&quot;text-muted-foreground top-1/2 right-2.5 size-4 -translate-y-1/2 pointer-events-none absolute select-none&quot;<br>    aria-hidden=&quot;true&quot;<br>    data-slot=&quot;native-select-icon&quot;<br>   /&gt;<br>  &lt;/div&gt;<br> );<br>}<br><br>function NativeSelectOption({ ...props }: React.ComponentProps&lt;&quot;option&quot;&gt;) {<br> return &lt;option data-slot=&quot;native-select-option&quot; {...props} /&gt;;<br>}<br><br>function NativeSelectOptGroup({<br> className,<br> ...props<br>}: React.ComponentProps&lt;&quot;optgroup&quot;&gt;) {<br> return (<br>  &lt;optgroup<br>   data-slot=&quot;native-select-optgroup&quot;<br>   className={cn(className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br><br>export { NativeSelect, NativeSelectOptGroup, NativeSelectOption };</pre><p>We don’t remove native behavior.<br>We only:</p><ul><li>hide default arrow (appearance-none)</li><li>add our own icon</li><li>normalize height and focus ring</li><li>preserve accessibility</li></ul><p>It’s enhancement — not replacement.</p><h3>2. Basic usage</h3><p>Smallest working pattern:</p><pre>&lt;NativeSelect defaultValue=&quot;&quot;&gt;<br>  &lt;NativeSelectOption value=&quot;&quot; disabled&gt;<br>    Select framework<br>  &lt;/NativeSelectOption&gt;<br>  &lt;NativeSelectOption value=&quot;react&quot;&gt;React&lt;/NativeSelectOption&gt;<br>  &lt;NativeSelectOption value=&quot;vue&quot;&gt;Vue&lt;/NativeSelectOption&gt;<br>  &lt;NativeSelectOption value=&quot;svelte&quot;&gt;Svelte&lt;/NativeSelectOption&gt;<br>&lt;/NativeSelect&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*LxUl0Pt9TowDuN1CMTZfwg.gif" /></figure><p>Rule:</p><p>Always include a disabled placeholder option<br>if selection is required.</p><h3>3. Controlled Native Select</h3><p>Just like Input.</p><pre>const [value, setValue] = React.useState(&quot;&quot;);<br><br>&lt;NativeSelect<br>  value={value}<br>  onChange={(e) =&gt; setValue(e.target.value)}<br>&gt;<br>  &lt;NativeSelectOption value=&quot;admin&quot;&gt;Admin&lt;/NativeSelectOption&gt;<br>  &lt;NativeSelectOption value=&quot;editor&quot;&gt;Editor&lt;/NativeSelectOption&gt;<br>  &lt;NativeSelectOption value=&quot;user&quot;&gt;User&lt;/NativeSelectOption&gt;<br>&lt;/NativeSelect&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*bEnHwCblOGjIyOw4Frg-9g.gif" /></figure><p>Same mental model.</p><p>It’s still a form field.<br>Treat it like one.</p><h3>4. With Option Groups</h3><p>Native &lt;optgroup&gt; still works — and is lightweight.</p><pre>&lt;NativeSelect defaultValue=&quot;&quot;&gt;<br>  &lt;NativeSelectOptGroup label=&quot;Asia&quot;&gt;<br>    &lt;NativeSelectOption value=&quot;jakarta&quot;&gt;Jakarta&lt;/NativeSelectOption&gt;<br>    &lt;NativeSelectOption value=&quot;tokyo&quot;&gt;Tokyo&lt;/NativeSelectOption&gt;<br>  &lt;/NativeSelectOptGroup&gt;<br>    &lt;NativeSelectOptGroup label=&quot;Europe&quot;&gt;<br>    &lt;NativeSelectOption value=&quot;berlin&quot;&gt;Berlin&lt;/NativeSelectOption&gt;<br>    &lt;NativeSelectOption value=&quot;paris&quot;&gt;Paris&lt;/NativeSelectOption&gt;<br>  &lt;/NativeSelectOptGroup&gt;<br>&lt;/NativeSelect&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*XH1izN1HwnqdhKaDXwsECA.gif" /></figure><p>No custom separator needed.<br>Browser handles structure.</p><h3>5. Inside a Field (real-world pattern)</h3><pre>&lt;Field&gt;<br>  &lt;FieldLabel&gt;Role&lt;/FieldLabel&gt;<br>  &lt;NativeSelect className=&quot;w-full&quot; defaultValue=&quot;&quot;&gt;<br>    &lt;NativeSelectOption value=&quot;&quot; disabled&gt;<br>      Select role<br>    &lt;/NativeSelectOption&gt;<br>    &lt;NativeSelectOption value=&quot;admin&quot;&gt;Admin&lt;/NativeSelectOption&gt;<br>    &lt;NativeSelectOption value=&quot;editor&quot;&gt;Editor&lt;/NativeSelectOption&gt;<br>    &lt;NativeSelectOption value=&quot;user&quot;&gt;User&lt;/NativeSelectOption&gt;<br>  &lt;/NativeSelect&gt;<br>  &lt;FieldDescription&gt;<br>    Determines access level.<br>  &lt;/FieldDescription&gt;<br>&lt;/Field&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*RzQeXZRZPNQSxPRQMnPSvw.gif" /></figure><p>Notice:</p><ul><li>w-full is still necessary</li><li>height matches other inputs</li><li>focus ring stays consistent</li></ul><p>It blends into the system.</p><h3>Native Select vs Select (Part 35)</h3><p>Here’s the practical difference:</p><p>Use <strong>Select (Radix)</strong> when:</p><ul><li>you need custom positioning</li><li>you need advanced styling</li><li>dropdown must behave consistently across browsers</li><li>design system precision matters</li></ul><p>Use <strong>Native Select</strong> when:</p><ul><li>form is simple</li><li>performance matters</li><li>mobile UX is priority</li><li>OS-level dropdown behavior is preferred</li></ul><p>Don’t choose based on trend.<br>Choose based on constraints.</p><h3>Common mistakes</h3><h3>1. Forgetting appearance-none</h3><p>Without it:</p><p>You’ll see double arrows.</p><p>Browser arrow + custom icon.</p><p>Always remove native arrow<br>before adding your own.</p><h3>2. Expecting full styling control</h3><p>You can style the trigger.</p><p>You cannot fully style:</p><ul><li>dropdown panel</li><li>option hover states</li><li>internal scroll behavior</li></ul><p>That’s the trade-off.</p><p>If you need total control — use Select (Part 35).</p><h3>3. Mixing Native Select and Radix Select randomly</h3><p>They look similar.</p><p>But behavior differs.</p><p>If you mix both in the same form<br>without intent,<br>users will feel the inconsistency.</p><p>Be deliberate.</p><h3>When to use Native Select</h3><p>Use it when:</p><ul><li>simplicity wins</li><li>performance is critical</li><li>mobile matters more than animation</li><li>your design system tolerates native dropdown UI</li></ul><p>Skip it when:</p><ul><li>dropdown design must be identical across platforms</li><li>custom interaction is required</li><li>accessibility customization is necessary</li></ul><h3>What changed after this</h3><p>I stopped overengineering simple forms.<br>I stopped replacing primitives unnecessarily.<br>I stopped assuming “custom” is always better.</p><p>Sometimes the browser is enough.</p><p>And Native Select reminds you of that.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FDvWJHSOxTff84SQsD9%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY3RjYWZrMHV2Y2l1ajB3dnJvcnV1cTB5eWZ4NnZhOWx2YTk1MTMxbiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FDvWJHSOxTff84SQsD9%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExOXd1NzZmbWdlNWRmdnQxNGc4dXlsNjk1dWJsd2J5eW45cWZoYzcyeSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FDvWJHSOxTff84SQsD9%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/4685d862916505a3bf1feaac574a2c3d/href">https://medium.com/media/4685d862916505a3bf1feaac574a2c3d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edeac144757b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 35] Select: Controlled Dropdown Without Native Limits]]></title>
            <link>https://medium.com/@rivainasution/shadcn-ui-react-series-part-35-select-controlled-dropdown-without-native-limits-8ef8ec342788?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ef8ec342788</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Mon, 23 Feb 2026 02:01:00 GMT</pubDate>
            <atom:updated>2026-02-23T02:01:00.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li>Part 32: Field</li><li>Part 33: Input Group</li><li>Part 34: Text Area</li><li>Part 35: Select</li><li>Part 36: Native Select</li><li>Part 37: Combobox</li><li>Part 38: Date Picker</li><li>Part 39: Calendar</li><li>Part 40: Slider</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/select">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/select">here</a></p><h3>Why Select exists</h3><p>At first, I used &lt;select&gt;.</p><p>It worked.</p><p>Until I needed:</p><p>custom styling<br>consistent height with Input<br>dark mode support<br>keyboard navigation guarantees<br>grouped options<br>scrollable dropdowns</p><p>Native select is powerful.</p><p>But it’s not composable.</p><p>Different browsers render it differently.<br>Styling is limited.<br>Positioning the dropdown is not predictable.</p><p>It looks fine.<br>Until your UI grows.</p><p>That’s when Select becomes infrastructure — not just a dropdown.</p><h3>What Select actually gives you</h3><p>This Select (built on Radix) gives you:</p><ul><li>consistent trigger styling</li><li>controlled open state</li><li>keyboard &amp; screen reader support</li><li>portal-based positioning</li><li>scrollable content with buttons</li><li>full composability</li></ul><p>It behaves like a real component.<br>Not a browser primitive.</p><h3>1. Create components/ui/select.tsx</h3><p>Same pattern as other action components.<br>Composable pieces. No over-opinionated logic.</p><p><strong>File location</strong><br>components/ui/select.tsx</p><pre>import * as React from &quot;react&quot;;<br>import { Select as SelectPrimitive } from &quot;radix-ui&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from &quot;lucide-react&quot;;<br>function Select({<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Root&gt;) {<br> return &lt;SelectPrimitive.Root data-slot=&quot;select&quot; {...props} /&gt;;<br>}<br>function SelectGroup({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Group&gt;) {<br> return (<br>  &lt;SelectPrimitive.Group<br>   data-slot=&quot;select-group&quot;<br>   className={cn(&quot;scroll-my-1 p-1&quot;, className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function SelectValue({<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Value&gt;) {<br> return &lt;SelectPrimitive.Value data-slot=&quot;select-value&quot; {...props} /&gt;;<br>}<br>function SelectTrigger({<br> className,<br> size = &quot;default&quot;,<br> children,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Trigger&gt; &amp; {<br> size?: &quot;sm&quot; | &quot;default&quot;;<br>}) {<br> return (<br>  &lt;SelectPrimitive.Trigger<br>   data-slot=&quot;select-trigger&quot;<br>   data-size={size}<br>   className={cn(<br>    &quot;border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-lg border bg-transparent py-2 pr-2 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:gap-1.5 [&amp;_svg:not([class*=&#39;size-&#39;])]:size-4 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&amp;_svg]:pointer-events-none [&amp;_svg]:shrink-0&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   {children}<br>   &lt;SelectPrimitive.Icon asChild&gt;<br>    &lt;ChevronDownIcon className=&quot;text-muted-foreground size-4 pointer-events-none&quot; /&gt;<br>   &lt;/SelectPrimitive.Icon&gt;<br>  &lt;/SelectPrimitive.Trigger&gt;<br> );<br>}<br>function SelectContent({<br> className,<br> children,<br> position = &quot;item-aligned&quot;,<br> align = &quot;center&quot;,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Content&gt;) {<br> return (<br>  &lt;SelectPrimitive.Portal&gt;<br>   &lt;SelectPrimitive.Content<br>    data-slot=&quot;select-content&quot;<br>    data-align-trigger={position === &quot;item-aligned&quot;}<br>    className={cn(<br>     &quot;bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 min-w-36 rounded-lg shadow-md ring-1 duration-100 relative z-50 max-h-(--radix-select-content-available-height) origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto data-[align-trigger=true]:animate-none&quot;,<br>     position === &quot;popper&quot; &amp;&amp;<br>      &quot;data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1&quot;,<br>     className,<br>    )}<br>    position={position}<br>    align={align}<br>    {...props}<br>   &gt;<br>    &lt;SelectScrollUpButton /&gt;<br>    &lt;SelectPrimitive.Viewport<br>     data-position={position}<br>     className={cn(<br>      &quot;data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)&quot;,<br>      position === &quot;popper&quot; &amp;&amp; &quot;&quot;,<br>     )}<br>    &gt;<br>     {children}<br>    &lt;/SelectPrimitive.Viewport&gt;<br>    &lt;SelectScrollDownButton /&gt;<br>   &lt;/SelectPrimitive.Content&gt;<br>  &lt;/SelectPrimitive.Portal&gt;<br> );<br>}<br>function SelectLabel({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Label&gt;) {<br> return (<br>  &lt;SelectPrimitive.Label<br>   data-slot=&quot;select-label&quot;<br>   className={cn(&quot;text-muted-foreground px-1.5 py-1 text-xs&quot;, className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function SelectItem({<br> className,<br> children,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Item&gt;) {<br> return (<br>  &lt;SelectPrimitive.Item<br>   data-slot=&quot;select-item&quot;<br>   className={cn(<br>    &quot;focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm [&amp;_svg:not([class*=&#39;size-&#39;])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&amp;_svg]:pointer-events-none [&amp;_svg]:shrink-0&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;span className=&quot;pointer-events-none absolute right-2 flex size-4 items-center justify-center&quot;&gt;<br>    &lt;SelectPrimitive.ItemIndicator&gt;<br>     &lt;CheckIcon className=&quot;pointer-events-none&quot; /&gt;<br>    &lt;/SelectPrimitive.ItemIndicator&gt;<br>   &lt;/span&gt;<br>   &lt;SelectPrimitive.ItemText&gt;{children}&lt;/SelectPrimitive.ItemText&gt;<br>  &lt;/SelectPrimitive.Item&gt;<br> );<br>}<br>function SelectSeparator({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.Separator&gt;) {<br> return (<br>  &lt;SelectPrimitive.Separator<br>   data-slot=&quot;select-separator&quot;<br>   className={cn(&quot;bg-border -mx-1 my-1 h-px pointer-events-none&quot;, className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function SelectScrollUpButton({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.ScrollUpButton&gt;) {<br> return (<br>  &lt;SelectPrimitive.ScrollUpButton<br>   data-slot=&quot;select-scroll-up-button&quot;<br>   className={cn(<br>    &quot;bg-popover z-10 flex cursor-default items-center justify-center py-1 [&amp;_svg:not([class*=&#39;size-&#39;])]:size-4&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;ChevronUpIcon /&gt;<br>  &lt;/SelectPrimitive.ScrollUpButton&gt;<br> );<br>}<br>function SelectScrollDownButton({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof SelectPrimitive.ScrollDownButton&gt;) {<br> return (<br>  &lt;SelectPrimitive.ScrollDownButton<br>   data-slot=&quot;select-scroll-down-button&quot;<br>   className={cn(<br>    &quot;bg-popover z-10 flex cursor-default items-center justify-center py-1 [&amp;_svg:not([class*=&#39;size-&#39;])]:size-4&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;ChevronDownIcon /&gt;<br>  &lt;/SelectPrimitive.ScrollDownButton&gt;<br> );<br>}<br>export {<br> Select,<br> SelectContent,<br> SelectGroup,<br> SelectItem,<br> SelectLabel,<br> SelectScrollDownButton,<br> SelectScrollUpButton,<br> SelectSeparator,<br> SelectTrigger,<br> SelectValue,<br>};</pre><p>Important idea:</p><p>This file doesn’t “simplify” Select.</p><p>It exposes all building blocks:</p><ul><li>Select</li><li>SelectTrigger</li><li>SelectContent</li><li>SelectItem</li><li>SelectLabel</li><li>SelectSeparator</li><li>Scroll buttons</li></ul><p>You compose what you need.</p><h3>2. Basic usage</h3><p>The smallest working pattern:</p><pre>&lt;Select&gt;<br>  &lt;SelectTrigger className=&quot;w-48&quot;&gt;<br>    &lt;SelectValue placeholder=&quot;Select a framework&quot; /&gt;<br>  &lt;/SelectTrigger&gt;<br>  &lt;SelectContent&gt;<br>    &lt;SelectItem value=&quot;react&quot;&gt;React&lt;/SelectItem&gt;<br>    &lt;SelectItem value=&quot;vue&quot;&gt;Vue&lt;/SelectItem&gt;<br>    &lt;SelectItem value=&quot;svelte&quot;&gt;Svelte&lt;/SelectItem&gt;<br>  &lt;/SelectContent&gt;<br>&lt;/Select&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*0nVJxObz1pk8wv8U2RAfvw.gif" /></figure><p>Rules:</p><ul><li>SelectValue lives inside SelectTrigger</li><li>SelectContent lives at root level</li><li>Each SelectItem must have a unique value</li></ul><h3>3. Controlled Select (real-world pattern)</h3><p>In real forms, always control the value.</p><pre>const [value, setValue] = React.useState(&quot;&quot;)<br><br>&lt;Select value={value} onValueChange={setValue}&gt;<br>  &lt;SelectTrigger className=&quot;w-48&quot;&gt;<br>    &lt;SelectValue placeholder=&quot;Choose role&quot; /&gt;<br>  &lt;/SelectTrigger&gt;<br>  &lt;SelectContent&gt;<br>    &lt;SelectItem value=&quot;admin&quot;&gt;Admin&lt;/SelectItem&gt;<br>    &lt;SelectItem value=&quot;editor&quot;&gt;Editor&lt;/SelectItem&gt;<br>    &lt;SelectItem value=&quot;user&quot;&gt;User&lt;/SelectItem&gt;<br>  &lt;/SelectContent&gt;<br>&lt;/Select&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*guG0jXaJruBbh6-vhrF4WQ.gif" /></figure><p>Why controlled?</p><p>Because you:</p><ul><li>validate</li><li>submit</li><li>sync with form libraries</li><li>conditionally render based on selection</li></ul><p>Uncontrolled Selects don’t scale.</p><h3>4. Grouped options</h3><p>When dropdowns grow, grouping matters.</p><pre>&lt;Select&gt;<br>  &lt;SelectTrigger className=&quot;w-56&quot;&gt;<br>    &lt;SelectValue placeholder=&quot;Select timezone&quot; /&gt;<br>  &lt;/SelectTrigger&gt;<br>  &lt;SelectContent&gt;<br>    &lt;SelectGroup&gt;<br>      &lt;SelectLabel&gt;Asia&lt;/SelectLabel&gt;<br>      &lt;SelectItem value=&quot;jakarta&quot;&gt;Jakarta&lt;/SelectItem&gt;<br>      &lt;SelectItem value=&quot;tokyo&quot;&gt;Tokyo&lt;/SelectItem&gt;<br>    &lt;/SelectGroup&gt;<br>    &lt;SelectSeparator /&gt;<br>    &lt;SelectGroup&gt;<br>      &lt;SelectLabel&gt;Europe&lt;/SelectLabel&gt;<br>      &lt;SelectItem value=&quot;berlin&quot;&gt;Berlin&lt;/SelectItem&gt;<br>      &lt;SelectItem value=&quot;paris&quot;&gt;Paris&lt;/SelectItem&gt;<br>    &lt;/SelectGroup&gt;<br>  &lt;/SelectContent&gt;<br>&lt;/Select&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*KZ3HZrXR1LjwPiH-x1o5AQ.gif" /></figure><p>Now it feels structured.<br>Not like a long random list.</p><h3>5. Select inside a Field (form-safe pattern)</h3><p>The pattern you’ll reuse constantly:</p><pre>&lt;Field&gt;<br>  &lt;FieldLabel&gt;Role&lt;/FieldLabel&gt;<br>  &lt;Select&gt;<br>    &lt;SelectTrigger className=&quot;w-full&quot;&gt;<br>      &lt;SelectValue placeholder=&quot;Select role&quot; /&gt;<br>    &lt;/SelectTrigger&gt;<br>    &lt;SelectContent&gt;<br>      &lt;SelectItem value=&quot;admin&quot;&gt;Admin&lt;/SelectItem&gt;<br>      &lt;SelectItem value=&quot;editor&quot;&gt;Editor&lt;/SelectItem&gt;<br>      &lt;SelectItem value=&quot;user&quot;&gt;User&lt;/SelectItem&gt;<br>    &lt;/SelectContent&gt;<br>  &lt;/Select&gt;<br>  &lt;FieldDescription&gt;<br>    This determines system permissions.<br>  &lt;/FieldDescription&gt;<br>&lt;/Field&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*SNC_FFTZcLu-_bVBo729vA.gif" /></figure><p>Notice:</p><ul><li>Trigger uses w-full</li><li>Height matches Input</li><li>Validation styling stays consistent</li></ul><p>Select becomes just another form surface.</p><p>Not a special case.</p><h3>Common mistakes (and why it feels broken)</h3><h3>1. Forgetting width on Trigger</h3><p>By default:</p><pre>w-fit</pre><p>So it shrinks to content.</p><p>If you want full-width form behavior:</p><pre>className=&quot;w-full&quot;</pre><p>Be explicit.</p><h3>2. Mixing native &lt;select&gt; and this Select</h3><p>They look similar.</p><p>They behave differently.</p><p>Mixing both inside the same UI causes:</p><ul><li>inconsistent height</li><li>different focus styles</li><li>visual misalignment</li></ul><p>Pick one system.</p><p>Stick to it.</p><h3>3. Forgetting value control</h3><p>Without value + onValueChange:</p><p>You lose predictability.</p><p>Forms become harder to debug.</p><p>Treat Select like Input.<br>Always control it in serious applications.</p><h3>When to use Select</h3><p>Use this Select when:</p><ul><li>styling consistency matters</li><li>accessibility matters</li><li>you need grouping</li><li>you need controlled open/close behavior</li><li>design system consistency is required</li></ul><p>Skip it when:</p><ul><li>performance must be extremely minimal</li><li>native mobile UI is preferred</li><li>browser default behavior is acceptable</li></ul><p>That’s where Part 36 (Native Select) comes in.</p><h3>What changed after this</h3><p>I stopped fighting browser styling.<br>I stopped patching dropdown positioning bugs.<br>I stopped worrying about keyboard support.</p><p>Select became predictable.</p><p>And dropdowns stopped being a browser problem.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxHMIDAy1qkzNS%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY3RjYWZrMHV2Y2l1ajB3dnJvcnV1cTB5eWZ4NnZhOWx2YTk1MTMxbiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FxHMIDAy1qkzNS%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExajFrOXd5aTcycTNjM24zZndrdW5uazZla2J1OGN4Nzk3OHcwNDR2aCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxHMIDAy1qkzNS%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="322" frameborder="0" scrolling="no"><a href="https://medium.com/media/308f57429c5ead15746cf3987faeb632/href">https://medium.com/media/308f57429c5ead15746cf3987faeb632/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef8ec342788" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 34] Text Area: When Input Is No Longer Enough]]></title>
            <link>https://medium.com/@rivainasution/shadcn-ui-react-series-part-34-text-area-when-input-is-no-longer-enough-18afe317eeea?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/18afe317eeea</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Sun, 22 Feb 2026 02:01:00 GMT</pubDate>
            <atom:updated>2026-02-22T02:01:00.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li>Part 32: Field</li><li>Part 33: Input Group</li><li>Part 34: Text Area</li><li>Part 35: Select</li><li>Part 36: Native Select</li><li>Part 37: Combobox</li><li>Part 38: Date Picker</li><li>Part 39: Calendar</li><li>Part 40: Slider</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/textarea">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/textarea">here</a></p><h3>Why Text Area exists</h3><p>At first, I used &lt;input /&gt; for everything.</p><p>Names.<br>Emails.<br>Short messages.</p><p>Then real forms started appearing:</p><p>support tickets<br>product descriptions<br>admin notes<br>user feedback</p><p>Suddenly one line wasn’t enough.</p><p>And resizing behavior became messy.<br>Some browsers allowed drag-resize.<br>Some didn’t.<br>Height jumped unexpectedly.<br>Validation styling broke alignment.</p><p>Nothing catastrophic.<br>But nothing consistent either.</p><p>That’s when Text Area stopped being “just a bigger input”<br>and became a controlled form surface.</p><h3>What Text Area actually gives you</h3><p>Textarea is not about multi-line typing.</p><p>It gives you:</p><ul><li>predictable vertical growth</li><li>consistent focus styling</li><li>proper error state visuals</li><li>layout-safe composition inside forms</li><li>accessibility alignment with other fields</li></ul><p>It behaves like Input.<br>But respects long-form content.</p><h3>1. Create components/ui/textarea.tsx</h3><p>Same philosophy as other shadcn/ui action components.<br>Minimal. Reusable. No extra opinions.</p><p><strong>File location</strong><br>components/ui/textarea.tsx</p><pre>import * as React from &quot;react&quot;<br>import { cn } from &quot;@/lib/utils&quot;<br>function Textarea({ className, ...props }: React.ComponentProps&lt;&quot;textarea&quot;&gt;) {<br>  return (<br>    &lt;textarea<br>      data-slot=&quot;textarea&quot;<br>      className={cn(<br>        &quot;border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-3 aria-invalid:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50&quot;,<br>        className<br>      )}<br>      {...props}<br>    /&gt;<br>  )<br>}<br>export { Textarea }</pre><p>Notice:</p><ul><li>min-h-16 ensures usable default height</li><li>w-full keeps layout stable</li><li>aria-invalid integrates with form validation</li><li>no manual resize override</li></ul><p>Keep it simple.</p><h3>2. Basic usage</h3><p>The simplest case.</p><pre>&lt;Textarea placeholder=&quot;Write your message...&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*krlUF9WSsNBJ9pxPi78iOQ.png" /></figure><p>Rule:</p><p>Textareas should almost always live inside a Field wrapper<br>if you’re building real forms.</p><h3>3. Controlled Text Area (React state)</h3><p>For real applications, it’s almost always controlled.</p><pre>const [value, setValue] = React.useState(&quot;&quot;)<br><br>&lt;Textarea<br>  value={value}<br>  onChange={(e) =&gt; setValue(e.target.value)}<br>  placeholder=&quot;Describe the issue...&quot;<br>/&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*dpjVFg1guYF2H8SQ1zjhxg.gif" /></figure><p>Why controlled?</p><p>Because:</p><ul><li>you validate</li><li>you submit</li><li>you autosave</li><li>you count characters</li></ul><p>Uncontrolled textareas don’t scale well in complex forms.</p><h3>4. Text Area inside a Field (real form pattern)</h3><p>This is the pattern you’ll reuse constantly.</p><pre>&lt;Field&gt;<br>  &lt;FieldLabel&gt;Description&lt;/FieldLabel&gt;<br>  &lt;Textarea placeholder=&quot;Explain what happened...&quot; /&gt;<br>  &lt;FieldDescription&gt;<br>    Provide as much detail as possible.<br>  &lt;/FieldDescription&gt;<br>&lt;/Field&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*HN_JrtEsx8F_qOAjou5bOw.png" /></figure><p>Notice:</p><ul><li>spacing stays consistent</li><li>error styling aligns automatically</li><li>description doesn’t shift layout</li></ul><p>Textarea becomes just another field surface.</p><p>Not a special case.</p><h3>5. Fixed height vs flexible height</h3><p>By default, this component has:</p><pre>min-h-16</pre><p>If you need a larger writing surface:</p><pre>&lt;Textarea className=&quot;min-h-32&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*P9YeRstAZ8XdPPSUz8bXiQ.png" /></figure><p>If you need scroll inside:</p><pre>&lt;Textarea className=&quot;h-40 resize-none&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*XfsGS0-GK-97D4fPdkUUuw.gif" /></figure><p>Be intentional.</p><p>Growing fields change layout.<br>Fixed fields contain layout.</p><p>Choose based on UX, not habit.</p><h3>Common mistakes (and why it feels wrong)</h3><h3>1. Letting users resize freely</h3><p>Default browser behavior allows resizing.</p><p>That can:</p><ul><li>break grid alignment</li><li>overlap adjacent components</li><li>cause visual inconsistency</li></ul><p>If layout matters:</p><pre>className=&quot;resize-none&quot;</pre><h3>2. Forgetting minimum height</h3><p>Without min-h-*, the textarea collapses visually.</p><p>It feels broken.<br>Even when technically functional.</p><p>Always define a baseline height.</p><h3>3. Treating it differently from Input</h3><p>If Input has:</p><ul><li>consistent focus ring</li><li>error border</li><li>disabled styling</li></ul><p>Textarea must match it.</p><p>Inconsistent fields destroy visual trust.</p><h3>When to use Text Area</h3><p>Use Text Area when:</p><ul><li>content can exceed one line</li><li>explanation or description is required</li><li>user feedback is expected</li><li>admins manage long-form content</li></ul><p>Skip it when:</p><ul><li>single-line input is enough</li><li>space is constrained</li><li>inline editing is required</li></ul><h3>What changed after this</h3><p>I stopped stretching Inputs to fake multi-line fields.<br>I stopped fighting browser resize behavior.<br>I stopped patching validation styles.</p><p>Textarea became predictable.</p><p>And long-form input stopped being a layout problem.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FVhWVAa7rUtT3xKX6Cd%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY3RjYWZrMHV2Y2l1ajB3dnJvcnV1cTB5eWZ4NnZhOWx2YTk1MTMxbiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FVhWVAa7rUtT3xKX6Cd%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExamFlcjl2OGgzc2RvcHVvemwyaWV3ZmM3bHowNWFyNGc0aGNxcG1iOCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FVhWVAa7rUtT3xKX6Cd%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/abd90e4267207be8175b530f0a4a4502/href">https://medium.com/media/abd90e4267207be8175b530f0a4a4502/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18afe317eeea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 33] Input Group: Creating a Clean & Responsive Input Group]]></title>
            <link>https://medium.com/@rivainasution/shadcn-ui-react-series-part-33-input-group-creating-a-clean-responsive-input-group-399ee66c8e9c?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/399ee66c8e9c</guid>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[radix-ui-react]]></category>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Sat, 21 Feb 2026 02:01:02 GMT</pubDate>
            <atom:updated>2026-02-21T02:01:02.258Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li>Part 32: Field</li><li>Part 33: Input Group</li><li>Part 34: Text Area</li><li>Part 35: Select</li><li>Part 36: Native Select</li><li>Part 37: Combobox</li><li>Part 38: Date Picker</li><li>Part 39: Calendar</li><li>Part 40: Slider</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/input-group">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/input-group">here</a></p><h3>Why Input Group?</h3><p>InputGroup is used when:</p><ul><li>You need prefix/suffix</li><li>You want embedded buttons inside input</li><li>You need icon + input in one visual unit</li><li>You want advanced control composition (spinner, dropdown, kbd hint, etc.)</li></ul><p>Instead of manually hacking relative + absolute every time,<br>InputGroup gives you structural discipline.</p><p>It handles:</p><ul><li>Focus ring</li><li>Invalid state</li><li>Disabled state</li><li>Border merging</li><li>Alignment logic</li></ul><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ input-group.tsx<br>      └─ textarea.tsx</pre><h3>textarea.tsx</h3><pre>import * as React from &quot;react&quot;;<br><br>import { cn } from &quot;@/lib/utils&quot;;<br><br>function Textarea({ className, ...props }: React.ComponentProps&lt;&quot;textarea&quot;&gt;) {<br> return (<br>  &lt;textarea<br>   data-slot=&quot;textarea&quot;<br>   className={cn(<br>    &quot;border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-transparent px-2.5 py-2 text-base transition-colors focus-visible:ring-3 aria-invalid:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br><br>export { Textarea };</pre><h3>input-group.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import { cva, type VariantProps } from &quot;class-variance-authority&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { Button } from &quot;@/components/ui/button&quot;;<br>import { Input } from &quot;@/components/ui/input&quot;;<br>import { Textarea } from &quot;./textarea&quot;;<br><br>function InputGroup({ className, ...props }: React.ComponentProps&lt;&quot;div&quot;&gt;) {<br> return (<br>  &lt;div<br>   data-slot=&quot;input-group&quot;<br>   role=&quot;group&quot;<br>   className={cn(<br>    &quot;border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-disabled:bg-input/50 dark:has-disabled:bg-input/80 h-8 rounded-lg border transition-colors in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-3 has-[&gt;[data-align=block-end]]:h-auto has-[&gt;[data-align=block-end]]:flex-col has-[&gt;[data-align=block-start]]:h-auto has-[&gt;[data-align=block-start]]:flex-col has-[&gt;[data-align=block-end]]:[&amp;&gt;input]:pt-3 has-[&gt;[data-align=block-start]]:[&amp;&gt;input]:pb-3 has-[&gt;[data-align=inline-end]]:[&amp;&gt;input]:pr-1.5 has-[&gt;[data-align=inline-start]]:[&amp;&gt;input]:pl-1.5 group/input-group relative flex w-full min-w-0 items-center outline-none has-[&gt;textarea]:h-auto&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>const inputGroupAddonVariants = cva(<br> &quot;text-muted-foreground h-auto gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&amp;&gt;kbd]:rounded-[calc(var(--radius)-5px)] [&amp;&gt;svg:not([class*=&#39;size-&#39;])]:size-4 flex cursor-text items-center justify-center select-none&quot;,<br> {<br>  variants: {<br>   align: {<br>    &quot;inline-start&quot;:<br>     &quot;pl-2 has-[&gt;button]:ml-[-0.3rem] has-[&gt;kbd]:ml-[-0.15rem] order-first&quot;,<br>    &quot;inline-end&quot;:<br>     &quot;pr-2 has-[&gt;button]:mr-[-0.3rem] has-[&gt;kbd]:mr-[-0.15rem] order-last&quot;,<br>    &quot;block-start&quot;:<br>     &quot;px-2.5 pt-2 group-has-[&gt;input]/input-group:pt-2 [.border-b]:pb-2 order-first w-full justify-start&quot;,<br>    &quot;block-end&quot;:<br>     &quot;px-2.5 pb-2 group-has-[&gt;input]/input-group:pb-2 [.border-t]:pt-2 order-last w-full justify-start&quot;,<br>   },<br>  },<br>  defaultVariants: {<br>   align: &quot;inline-start&quot;,<br>  },<br> },<br>);<br>function InputGroupAddon({<br> className,<br> align = &quot;inline-start&quot;,<br> ...props<br>}: React.ComponentProps&lt;&quot;div&quot;&gt; &amp; VariantProps&lt;typeof inputGroupAddonVariants&gt;) {<br> return (<br>  &lt;div<br>   role=&quot;group&quot;<br>   data-slot=&quot;input-group-addon&quot;<br>   data-align={align}<br>   className={cn(inputGroupAddonVariants({ align }), className)}<br>   onClick={(e) =&gt; {<br>    if ((e.target as HTMLElement).closest(&quot;button&quot;)) {<br>     return;<br>    }<br>    e.currentTarget.parentElement?.querySelector(&quot;input&quot;)?.focus();<br>   }}<br>   {...props}<br>  /&gt;<br> );<br>}<br>const inputGroupButtonVariants = cva(<br> &quot;gap-2 text-sm shadow-none flex items-center&quot;,<br> {<br>  variants: {<br>   size: {<br>    xs: &quot;h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&amp;&gt;svg:not([class*=&#39;size-&#39;])]:size-3.5&quot;,<br>    sm: &quot;&quot;,<br>    &quot;icon-xs&quot;:<br>     &quot;size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[&gt;svg]:p-0&quot;,<br>    &quot;icon-sm&quot;: &quot;size-8 p-0 has-[&gt;svg]:p-0&quot;,<br>   },<br>  },<br>  defaultVariants: {<br>   size: &quot;xs&quot;,<br>  },<br> },<br>);<br>function InputGroupButton({<br> className,<br> type = &quot;button&quot;,<br> variant = &quot;ghost&quot;,<br> size = &quot;xs&quot;,<br> ...props<br>}: Omit&lt;React.ComponentProps&lt;typeof Button&gt;, &quot;size&quot;&gt; &amp;<br> VariantProps&lt;typeof inputGroupButtonVariants&gt;) {<br> return (<br>  &lt;Button<br>   type={type}<br>   data-size={size}<br>   variant={variant}<br>   className={cn(inputGroupButtonVariants({ size }), className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function InputGroupText({ className, ...props }: React.ComponentProps&lt;&quot;span&quot;&gt;) {<br> return (<br>  &lt;span<br>   className={cn(<br>    &quot;text-muted-foreground gap-2 text-sm [&amp;_svg:not([class*=&#39;size-&#39;])]:size-4 flex items-center [&amp;_svg]:pointer-events-none&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function InputGroupInput({<br> className,<br> ...props<br>}: React.ComponentProps&lt;&quot;input&quot;&gt;) {<br> return (<br>  &lt;Input<br>   data-slot=&quot;input-group-control&quot;<br>   className={cn(<br>    &quot;rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function InputGroupTextarea({<br> className,<br> ...props<br>}: React.ComponentProps&lt;&quot;textarea&quot;&gt;) {<br> return (<br>  &lt;Textarea<br>   data-slot=&quot;input-group-control&quot;<br>   className={cn(<br>    &quot;rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent flex-1 resize-none&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>export {<br> InputGroup,<br> InputGroupAddon,<br> InputGroupButton,<br> InputGroupText,<br> InputGroupInput,<br> InputGroupTextarea,<br>};</pre><h3>Basic Structure</h3><pre>       &lt;InputGroup&gt;<br>        &lt;InputGroupAddon&gt;<br>         &lt;InputGroupText&gt;@&lt;/InputGroupText&gt;<br>        &lt;/InputGroupAddon&gt;<br>        &lt;InputGroupInput placeholder=&quot;username&quot; /&gt;<br>       &lt;/InputGroup&gt;</pre><p>That’s it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*AgV9wM8jsg7gmaTS-ntN2Q.png" /></figure><p>No manual borders.<br>No extra flex hacks.</p><h3>Alignment Variants</h3><p>InputGroupAddon supports:</p><ul><li>inline-start</li><li>inline-end</li><li>block-start</li><li>block-end</li></ul><p>These control placement relative to the input.</p><h3>inline-start (Default)</h3><p>Left side (most common).</p><pre>       &lt;InputGroup&gt;<br>        &lt;InputGroupAddon align=&quot;inline-start&quot;&gt;<br>         &lt;InputGroupText&gt;https://&lt;/InputGroupText&gt;<br>        &lt;/InputGroupAddon&gt;<br>        &lt;InputGroupInput placeholder=&quot;your-site.com&quot; /&gt;<br>       &lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*pGjUJSmNegUICv_amsC_vg.png" /></figure><p>Used for:</p><ul><li>URL prefix</li><li>Currency symbol</li><li>Icons</li></ul><h3>inline-end</h3><p>Right side.</p><pre>import { FaSearch } from &quot;react-icons/fa&quot;;       <br><br>       &lt;InputGroup&gt;<br>        &lt;InputGroupInput placeholder=&quot;Search...&quot; /&gt;<br>        &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>         &lt;InputGroupButton size=&quot;icon-xs&quot;&gt;&lt;FaSearch /&gt;&lt;/InputGroupButton&gt;<br>        &lt;/InputGroupAddon&gt;<br>       &lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*z90WwBFstSXTm5V-aXfWGA.png" /></figure><p>Perfect for:</p><ul><li>Search button</li><li>Clear button</li><li>Dropdown trigger</li></ul><h3>block-start</h3><p>Top section (stacked above input).</p><pre>       &lt;InputGroup&gt;<br>        &lt;InputGroupAddon align=&quot;block-start&quot;&gt;<br>         &lt;InputGroupText&gt;Project Name&lt;/InputGroupText&gt;<br>        &lt;/InputGroupAddon&gt;<br>        &lt;InputGroupInput placeholder=&quot;My SaaS App&quot; /&gt;<br>       &lt;/InputGroup&gt;  </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*wsn8u1MlbnxPYx2LTx1CjQ.png" /></figure><p>Useful when:</p><ul><li>You need contextual label inside same bordered group</li><li>You want compact vertical grouping</li></ul><h3>block-end</h3><p>Below the input.</p><pre>       &lt;InputGroup&gt;<br>        &lt;InputGroupInput placeholder=&quot;Enter amount&quot; /&gt;<br>        &lt;InputGroupAddon align=&quot;block-end&quot;&gt;<br>         &lt;InputGroupText&gt;USD&lt;/InputGroupText&gt;<br>        &lt;/InputGroupAddon&gt;<br>       &lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*_5drWSk2pRmtJU3eWGZ0fQ.png" /></figure><p>Great for:</p><ul><li>Units</li><li>Hints</li><li>Secondary actions</li></ul><h3>Examples</h3><p>Now let’s explore real-world compositions.</p><h3>Icon Example</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupAddon&gt;<br>    &lt;InputGroupText&gt;<br>      &lt;Mail className=&quot;size-4&quot; /&gt;<br>    &lt;/InputGroupText&gt;<br>  &lt;/InputGroupAddon&gt;<br>  &lt;InputGroupInput type=&quot;email&quot; placeholder=&quot;you@example.com&quot; /&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*ZN77gyKou4F_sDF6p0qCsA.png" /></figure><p>Clean. Minimal. Predictable.</p><h3>Text Prefix</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupAddon&gt;<br>    &lt;InputGroupText&gt;$&lt;/InputGroupText&gt;<br>  &lt;/InputGroupAddon&gt;<br>  &lt;InputGroupInput type=&quot;number&quot; placeholder=&quot;0.00&quot; /&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*ILK9HigYzuqIalux-toLKg.png" /></figure><p>Currency input done properly.</p><h3>Button Inside Input</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput placeholder=&quot;Search...&quot; /&gt;<br>  &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>    &lt;InputGroupButton&gt;<br>     Search<br>    &lt;/InputGroupButton&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*QC1s8ZdMFjXQB92uIqm6-w.png" /></figure><p>The button is visually merged with the input.</p><p>No border duplication.</p><h3>Icon Button Variant</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput placeholder=&quot;Search...&quot; /&gt;<br>  &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>    &lt;InputGroupButton size=&quot;icon-xs&quot;&gt;<br>      &lt;Search className=&quot;size-4&quot; /&gt;<br>    &lt;/InputGroupButton&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*wLDHTVcA4H-V44FdFkkQjA.png" /></figure><p>Compact and modern.</p><h3>Kbd Example</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput placeholder=&quot;Search...&quot; /&gt;<br>  &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>    &lt;kbd className=&quot;px-2 py-1 text-xs border rounded&quot;&gt;<br>      ⌘K<br>    &lt;/kbd&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*8qeBfXVLt5NX3HgIYmjqgg.png" /></figure><p>Useful for command palette triggers.</p><h3>Dropdown Trigger</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput placeholder=&quot;Select country&quot; /&gt;<br>  &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>    &lt;InputGroupButton size=&quot;icon-xs&quot;&gt;<br>      &lt;ChevronDown className=&quot;w-4&quot; /&gt;<br>    &lt;/InputGroupButton&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*z42yPIvgLOqB_UF5InWB5Q.png" /></figure><p>Later you can connect it to a Popover or Select.</p><h3>Spinner / Loading State</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput placeholder=&quot;Loading...&quot; disabled /&gt;<br>  &lt;InputGroupAddon align=&quot;inline-end&quot;&gt;<br>    &lt;InputGroupText&gt;<br>      &lt;Spinner className=&quot;size-4 animate-spin&quot; /&gt;<br>    &lt;/InputGroupText&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*1IlvgDbOiMGByFdEu52Gxw.gif" /></figure><p>No layout jump.<br>No border shift.</p><h3>Textarea Support</h3><p>InputGroupTextarea supports multiline inputs.</p><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupTextarea placeholder=&quot;Write your feedback...&quot; /&gt;<br>  &lt;InputGroupAddon align=&quot;block-end&quot;&gt;<br>    &lt;InputGroupText&gt;<br>      0 / 500<br>    &lt;/InputGroupText&gt;<br>  &lt;/InputGroupAddon&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*_gcEyt65t5FbP20x4aH3gQ.png" /></figure><p>It automatically switches height behavior.</p><h3>Invalid State</h3><pre>&lt;InputGroup&gt;<br>  &lt;InputGroupInput aria-invalid placeholder=&quot;Invalid input&quot; /&gt;<br>&lt;/InputGroup&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*Iwj_DbSnmQy2TbBPKOoMiQ.png" /></figure><p>The entire group:</p><ul><li>Turns destructive border</li><li>Applies ring</li><li>Preserves accessibility</li></ul><p>No extra CSS needed.</p><h3>Design Principles Behind InputGroup</h3><ol><li>Group owns border.</li><li>Child inputs are borderless.</li><li>Addons are structural, not decorative.</li><li>Focus state propagates upward.</li><li>aria-invalid affects entire container.</li></ol><p>This is how you build scalable form systems.</p><p>Not random flex containers.</p><h3>When to Use InputGroup</h3><p>Use it when:</p><ul><li>Input has prefix/suffix</li><li>Input has action button</li><li>Input needs inline metadata</li><li>You want atomic form composition</li></ul><p>Do NOT use it for basic standalone inputs.</p><p>Keep it intentional</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F7FgDPLLKh1v4d2XLkl%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExN2FmY212Z3RqMGYxdmwwYXo3ZDh3OTBjcGtpNDdkZ2ZsNDlpZG92aiZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2F7FgDPLLKh1v4d2XLkl%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY284aDVyMmV5ODNkcjdvcXBkdGt4amIzMGxmd3Q5NTNheGRvMDdybSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F7FgDPLLKh1v4d2XLkl%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="248" frameborder="0" scrolling="no"><a href="https://medium.com/media/57554a309ab0c78ee1ec178eb19f8b51/href">https://medium.com/media/57554a309ab0c78ee1ec178eb19f8b51/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=399ee66c8e9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 32] Field: Structuring Form Intent]]></title>
            <link>https://medium.com/@rivainasution/shadcn-ui-react-series-part-32-field-structuring-form-intent-cdd7917feac6?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdd7917feac6</guid>
            <category><![CDATA[radix-ui]]></category>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Fri, 20 Feb 2026 02:01:01 GMT</pubDate>
            <atom:updated>2026-02-20T02:01:01.434Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li>Part 32: Field</li><li>Part 33: Input Group</li><li>Part 34: Text Area</li><li>Part 35: Select</li><li>Part 36: Native Select</li><li>Part 37: Combobox</li><li>Part 38: Date Picker</li><li>Part 39: Calendar</li><li>Part 40: Slider</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/field">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/field">here</a></p><p>Field is not an input.</p><p>It is structure.</p><p>It organizes:</p><p>Label<br>Control<br>Description<br>Error message</p><p>Into a predictable, accessible unit.</p><p>Without Field, forms become inconsistent.<br>Spacing breaks.<br>Error messages float.<br>Alignment collapses.</p><p>Field is about <strong>form architecture</strong>.</p><p>In this part, we’ll break down how Field works, why it exists, and how it standardizes complex forms.</p><h3>Why Field Exists</h3><p>Forms are repetitive.</p><p>Every input needs:</p><p>A label<br>Optional helper text<br>Validation feedback<br>Consistent spacing</p><p>If each component handles this individually,<br>you get inconsistency.</p><p>Field centralizes that logic.</p><p>It separates:</p><p>Structure → Field<br>Interaction → Input / Checkbox / Radio / etc</p><p>That separation matters.</p><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ field.tsx</pre><h3>Core Concept</h3><p>Field is composed of smaller pieces:</p><ul><li>Field</li><li>FieldLabel</li><li>FieldContent</li><li>FieldDescription</li><li>FieldError</li><li>FieldGroup</li><li>FieldSet</li><li>FieldLegend</li><li>FieldSeparator</li><li>FieldTitle</li></ul><p>It’s modular by design.</p><p>You don’t use all of them every time.</p><p>You use what the form requires.</p><h3>field.tsx</h3><pre>import { useMemo } from &quot;react&quot;;<br>import { cva, type VariantProps } from &quot;class-variance-authority&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { Label } from &quot;@/components/ui/label&quot;;<br>import { Separator } from &quot;@/components/ui/separator&quot;;<br><br>function FieldSet({ className, ...props }: React.ComponentProps&lt;&quot;fieldset&quot;&gt;) {<br> return (<br>  &lt;fieldset<br>   data-slot=&quot;field-set&quot;<br>   className={cn(<br>    &quot;gap-4 has-[&gt;[data-slot=checkbox-group]]:gap-3 has-[&gt;[data-slot=radio-group]]:gap-3 flex flex-col&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldLegend({<br> className,<br> variant = &quot;legend&quot;,<br> ...props<br>}: React.ComponentProps&lt;&quot;legend&quot;&gt; &amp; { variant?: &quot;legend&quot; | &quot;label&quot; }) {<br> return (<br>  &lt;legend<br>   data-slot=&quot;field-legend&quot;<br>   data-variant={variant}<br>   className={cn(<br>    &quot;mb-1.5 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldGroup({ className, ...props }: React.ComponentProps&lt;&quot;div&quot;&gt;) {<br> return (<br>  &lt;div<br>   data-slot=&quot;field-group&quot;<br>   className={cn(<br>    &quot;gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4 group/field-group @container/field-group flex w-full flex-col&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>const fieldVariants = cva(<br> &quot;data-[invalid=true]:text-destructive gap-2 group/field flex w-full&quot;,<br> {<br>  variants: {<br>   orientation: {<br>    vertical: &quot;flex-col *:w-full [&amp;&gt;.sr-only]:w-auto&quot;,<br>    horizontal:<br>     &quot;flex-row items-center *:data-[slot=field-label]:flex-auto has-[&gt;[data-slot=field-content]]:items-start has-[&gt;[data-slot=field-content]]:[&amp;&gt;[role=checkbox],[role=radio]]:mt-px&quot;,<br>    responsive:<br>     &quot;flex-col *:w-full [&amp;&gt;.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:*:data-[slot=field-label]:flex-auto @md/field-group:has-[&gt;[data-slot=field-content]]:items-start @md/field-group:has-[&gt;[data-slot=field-content]]:[&amp;&gt;[role=checkbox],[role=radio]]:mt-px&quot;,<br>   },<br>  },<br>  defaultVariants: {<br>   orientation: &quot;vertical&quot;,<br>  },<br> },<br>);<br>function Field({<br> className,<br> orientation = &quot;vertical&quot;,<br> ...props<br>}: React.ComponentProps&lt;&quot;div&quot;&gt; &amp; VariantProps&lt;typeof fieldVariants&gt;) {<br> return (<br>  &lt;div<br>   role=&quot;group&quot;<br>   data-slot=&quot;field&quot;<br>   data-orientation={orientation}<br>   className={cn(fieldVariants({ orientation }), className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldContent({ className, ...props }: React.ComponentProps&lt;&quot;div&quot;&gt;) {<br> return (<br>  &lt;div<br>   data-slot=&quot;field-content&quot;<br>   className={cn(<br>    &quot;gap-0.5 group/field-content flex flex-1 flex-col leading-snug&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldLabel({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof Label&gt;) {<br> return (<br>  &lt;Label<br>   data-slot=&quot;field-label&quot;<br>   className={cn(<br>    &quot;has-data-checked:bg-primary/5 has-data-checked:border-primary/30 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10 gap-2 group-data-[disabled=true]/field:opacity-50 has-[&gt;[data-slot=field]]:rounded-lg has-[&gt;[data-slot=field]]:border *:data-[slot=field]:p-2.5 group/field-label peer/field-label flex w-fit leading-snug&quot;,<br>    &quot;has-[&gt;[data-slot=field]]:w-full has-[&gt;[data-slot=field]]:flex-col&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldTitle({ className, ...props }: React.ComponentProps&lt;&quot;div&quot;&gt;) {<br> return (<br>  &lt;div<br>   data-slot=&quot;field-label&quot;<br>   className={cn(<br>    &quot;gap-2 text-sm font-medium group-data-[disabled=true]/field:opacity-50 flex w-fit items-center leading-snug&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldDescription({ className, ...props }: React.ComponentProps&lt;&quot;p&quot;&gt;) {<br> return (<br>  &lt;p<br>   data-slot=&quot;field-description&quot;<br>   className={cn(<br>    &quot;text-muted-foreground text-left text-sm [[data-variant=legend]+&amp;]:-mt-1.5 leading-normal font-normal group-has-data-horizontal/field:text-balance&quot;,<br>    &quot;last:mt-0 nth-last-2:-mt-1&quot;,<br>    &quot;[&amp;&gt;a:hover]:text-primary [&amp;&gt;a]:underline [&amp;&gt;a]:underline-offset-4&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function FieldSeparator({<br> children,<br> className,<br> ...props<br>}: React.ComponentProps&lt;&quot;div&quot;&gt; &amp; {<br> children?: React.ReactNode;<br>}) {<br> return (<br>  &lt;div<br>   data-slot=&quot;field-separator&quot;<br>   data-content={!!children}<br>   className={cn(<br>    &quot;-my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2 relative&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;Separator className=&quot;absolute inset-0 top-1/2&quot; /&gt;<br>   {children &amp;&amp; (<br>    &lt;span<br>     className=&quot;text-muted-foreground px-2 bg-background relative mx-auto block w-fit&quot;<br>     data-slot=&quot;field-separator-content&quot;<br>    &gt;<br>     {children}<br>    &lt;/span&gt;<br>   )}<br>  &lt;/div&gt;<br> );<br>}<br>function FieldError({<br> className,<br> children,<br> errors,<br> ...props<br>}: React.ComponentProps&lt;&quot;div&quot;&gt; &amp; {<br> errors?: Array&lt;{ message?: string } | undefined&gt;;<br>}) {<br> const content = useMemo(() =&gt; {<br>  if (children) {<br>   return children;<br>  }<br>  if (!errors?.length) {<br>   return null;<br>  }<br>  const uniqueErrors = [<br>   ...new Map(errors.map((error) =&gt; [error?.message, error])).values(),<br>  ];<br>  if (uniqueErrors?.length == 1) {<br>   return uniqueErrors[0]?.message;<br>  }<br>  return (<br>   &lt;ul className=&quot;ml-4 flex list-disc flex-col gap-1&quot;&gt;<br>    {uniqueErrors.map(<br>     (error, index) =&gt;<br>      error?.message &amp;&amp; &lt;li key={index}&gt;{error.message}&lt;/li&gt;,<br>    )}<br>   &lt;/ul&gt;<br>  );<br> }, [children, errors]);<br> if (!content) {<br>  return null;<br> }<br> return (<br>  &lt;div<br>   role=&quot;alert&quot;<br>   data-slot=&quot;field-error&quot;<br>   className={cn(&quot;text-destructive text-sm font-normal&quot;, className)}<br>   {...props}<br>  &gt;<br>   {content}<br>  &lt;/div&gt;<br> );<br>}<br>export {<br> Field,<br> FieldLabel,<br> FieldDescription,<br> FieldError,<br> FieldGroup,<br> FieldLegend,<br> FieldSeparator,<br> FieldSet,<br> FieldContent,<br> FieldTitle,<br>};</pre><h3>Basic Vertical Field</h3><p>Default Field adalah vertical.<br> Tidak perlu set orientation kalau mau stacked layout.</p><pre>&lt;FieldSet className=&quot;w-full max-w-xs&quot;&gt;<br>  &lt;FieldGroup&gt;<br>    &lt;Field&gt;<br>      &lt;FieldLabel htmlFor=&quot;email&quot;&gt;Email&lt;/FieldLabel&gt;<br>      &lt;Input id=&quot;email&quot; type=&quot;email&quot; placeholder=&quot;you@example.com&quot; /&gt;<br>      &lt;FieldDescription&gt;<br>        We&#39;ll never share your email with anyone else.<br>      &lt;/FieldDescription&gt;<br>      &lt;FieldError&gt;Enter a valid email address.&lt;/FieldError&gt;<br>    &lt;/Field&gt;<br>  &lt;/FieldGroup&gt;<br>&lt;/FieldSet&gt;</pre><p>This gives you:</p><ul><li>Natural stacked layout</li><li>Consistent spacing from FieldGroup</li><li>Correct error placement</li><li>No layout overrides</li></ul><p>Field controls structure. You don’t fight it.</p><h3>Orientation Variants</h3><p>Field supports:</p><ul><li>vertical (default)</li><li>horizontal</li><li>responsive</li></ul><p>Do not add layout classes like flex flex-col manually.<br>That breaks the variant system.</p><h3>Vertical (Default)</h3><p>Stacked layout.<br>Best for mobile and most forms.</p><pre>&lt;Field&gt;<br>  &lt;FieldLabel htmlFor=&quot;username&quot;&gt;Username&lt;/FieldLabel&gt;<br>  &lt;Input id=&quot;username&quot; placeholder=&quot;Max Leiter&quot; /&gt;<br>  &lt;FieldDescription&gt;<br>    Choose a unique username for your account.<br>  &lt;/FieldDescription&gt;<br>&lt;/Field&gt;</pre><h3>Horizontal</h3><p>Label and control aligned side by side.</p><p>Used in:</p><ul><li>Settings pages</li><li>Compact admin forms</li><li>Toggle rows</li></ul><p>Example (like your Checkbox / Radio usage):</p><pre>&lt;Field orientation=&quot;horizontal&quot;&gt;<br>  &lt;Checkbox id=&quot;notifications&quot; /&gt;<br>  &lt;FieldLabel htmlFor=&quot;notifications&quot; className=&quot;font-normal&quot;&gt;<br>    Enable notifications<br>  &lt;/FieldLabel&gt;<br>&lt;/Field&gt;</pre><p>Or with content grouping:</p><pre>&lt;Field orientation=&quot;horizontal&quot;&gt;<br>  &lt;Checkbox id=&quot;sync&quot; /&gt;<br>  &lt;FieldContent&gt;<br>    &lt;FieldLabel htmlFor=&quot;sync&quot;&gt;<br>      Sync Desktop &amp; Documents folders<br>    &lt;/FieldLabel&gt;<br>    &lt;FieldDescription&gt;<br>      Your folders will be synced across devices.<br>    &lt;/FieldDescription&gt;<br>  &lt;/FieldContent&gt;<br>&lt;/Field&gt;</pre><p>No custom grid classes needed.<br>Orientation handles structure.</p><h3>Responsive</h3><p>Vertical on small screens.<br>Horizontal on medium+ screens.</p><p>Used in your Profile example:</p><pre>&lt;Field orientation=&quot;responsive&quot;&gt;<br>  &lt;FieldContent&gt;<br>    &lt;FieldLabel htmlFor=&quot;name&quot;&gt;Name&lt;/FieldLabel&gt;<br>    &lt;FieldDescription&gt;<br>      Provide your full name for identification.<br>    &lt;/FieldDescription&gt;<br>  &lt;/FieldContent&gt;<br>  &lt;Input id=&quot;name&quot; placeholder=&quot;Evil Rabbit&quot; required /&gt;<br>&lt;/Field&gt;</pre><p>This avoids duplicating CSS for mobile/desktop layouts.</p><h3>FieldSet and Legend</h3><p>Use semantic grouping when fields are related.</p><p>Example from your Address section:</p><pre>&lt;FieldSet className=&quot;w-full max-w-sm&quot;&gt;<br>  &lt;FieldLegend&gt;Address Information&lt;/FieldLegend&gt;<br>  &lt;FieldDescription&gt;<br>    We need your address to deliver your order.<br>  &lt;/FieldDescription&gt;<br>  &lt;FieldGroup&gt;<br>    &lt;Field&gt;<br>      &lt;FieldLabel htmlFor=&quot;street&quot;&gt;Street Address&lt;/FieldLabel&gt;<br>      &lt;Input id=&quot;street&quot; placeholder=&quot;123 Main St&quot; /&gt;<br>    &lt;/Field&gt;<br>    &lt;div className=&quot;grid grid-cols-2 gap-4&quot;&gt;<br>      &lt;Field&gt;<br>        &lt;FieldLabel htmlFor=&quot;city&quot;&gt;City&lt;/FieldLabel&gt;<br>        &lt;Input id=&quot;city&quot; placeholder=&quot;New York&quot; /&gt;<br>      &lt;/Field&gt;<br>      &lt;Field&gt;<br>        &lt;FieldLabel htmlFor=&quot;zip&quot;&gt;Postal Code&lt;/FieldLabel&gt;<br>        &lt;Input id=&quot;zip&quot; placeholder=&quot;90502&quot; /&gt;<br>      &lt;/Field&gt;<br>    &lt;/div&gt;<br>  &lt;/FieldGroup&gt;<br>&lt;/FieldSet&gt;</pre><p>FieldSet defines semantic scope.<br>FieldLegend names the group.<br>Accessibility is preserved.</p><h3>FieldGroup</h3><p>Used to stack multiple fields with normalized spacing.</p><p>Do NOT override layout like this:</p><pre>&lt;Field orientation=&quot;horizontal&quot; className=&quot;flex flex-col gap-1&quot;&gt;</pre><p>That breaks the system.</p><p>Correct usage:</p><pre>&lt;FieldGroup&gt;<br>  &lt;Field&gt;<br>    &lt;FieldLabel htmlFor=&quot;username&quot;&gt;Username&lt;/FieldLabel&gt;<br>    &lt;Input id=&quot;username&quot; placeholder=&quot;Max Leiter&quot; /&gt;<br>  &lt;/Field&gt;<br>``&lt;Field&gt;<br>    &lt;FieldLabel htmlFor=&quot;password&quot;&gt;Password&lt;/FieldLabel&gt;<br>    &lt;Input id=&quot;password&quot; type=&quot;password&quot; placeholder=&quot;••••••••&quot; /&gt;<br>    &lt;FieldDescription&gt;<br>      Must be at least 8 characters long.<br>    &lt;/FieldDescription&gt;<br>  &lt;/Field&gt;<br>&lt;/FieldGroup&gt;</pre><p>FieldGroup already controls vertical rhythm.<br> No margin hacks needed.</p><h3>FieldDescription</h3><p>Used for contextual guidance.</p><pre>&lt;FieldDescription&gt;<br>  Password must be at least 8 characters long.<br>&lt;/FieldDescription&gt;</pre><p>Good helper text reduces validation errors.</p><p>Keep it short and precise.</p><h3>FieldError</h3><p>Handles validation messaging.</p><p>Example from your validation section:</p><pre>&lt;Field data-invalid&gt;<br>  &lt;FieldLabel htmlFor=&quot;email&quot;&gt;Email&lt;/FieldLabel&gt;<br>  &lt;Input id=&quot;email&quot; type=&quot;email&quot; aria-invalid /&gt;<br>  &lt;FieldError&gt;Enter a valid email address.&lt;/FieldError&gt;<br>&lt;/Field&gt;</pre><p>It should:</p><ul><li>Be predictable</li><li>Appear in consistent position</li><li>Not shift layout dramatically</li><li>Use aria-invalid correctly</li></ul><p>Error handling must feel stable.</p><h3>FieldSeparator</h3><p>Used to divide logical blocks inside one grouped section.</p><p>Example (from your checkbox section):</p><pre>&lt;FieldSeparator /&gt;</pre><p>Optional text version:</p><pre>&lt;FieldSeparator&gt;OR&lt;/FieldSeparator&gt;</pre><p>Use sparingly. Too many separators create visual noise.</p><h3>FieldTitle</h3><p>Used when you need semantic emphasis but not a direct &lt;label&gt;.</p><p>Example from your Choice Card:</p><pre>&lt;Field orientation=&quot;horizontal&quot;&gt;<br>  &lt;FieldContent&gt;<br>    &lt;FieldTitle&gt;Kubernetes&lt;/FieldTitle&gt;<br>    &lt;FieldDescription&gt;<br>      Run GPU workloads on a K8s cluster.<br>    &lt;/FieldDescription&gt;<br>  &lt;/FieldContent&gt;<br>  &lt;RadioGroupItem value=&quot;kubernetes&quot; id=&quot;kubernetes-r2h&quot; /&gt;<br>&lt;/Field&gt;</pre><p>Use FieldTitle when the control is already associated via wrapping label.</p><h3>Form</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kB1UPYQk5p0kW4sgrDOWuA.png" /></figure><pre>&lt;FieldSet className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldGroup&gt;<br>         &lt;Field&gt;<br>          &lt;FieldLabel htmlFor=&quot;username&quot;&gt;Username&lt;/FieldLabel&gt;<br>          &lt;Input id=&quot;username&quot; type=&quot;text&quot; placeholder=&quot;Max Leiter&quot; /&gt;<br>          &lt;FieldDescription&gt;<br>           Choose a unique username for your account.<br>          &lt;/FieldDescription&gt;<br>         &lt;/Field&gt;<br>         &lt;Field&gt;<br>          &lt;FieldLabel htmlFor=&quot;password&quot;&gt;Password&lt;/FieldLabel&gt;<br>          &lt;FieldDescription&gt;<br>           Must be at least 8 characters long.<br>          &lt;/FieldDescription&gt;<br>          &lt;Input<br>           id=&quot;password&quot;<br>           type=&quot;password&quot;<br>           placeholder=&quot;••••••••&quot;<br>          /&gt;<br>         &lt;/Field&gt;<br>        &lt;/FieldGroup&gt;<br>       &lt;/FieldSet&gt;</pre><h3>Textarea</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1jvLgWvQw31YdKW4Sby9Iw.png" /></figure><pre>&lt;FieldSet className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldGroup&gt;<br>         &lt;Field&gt;<br>          &lt;FieldLabel htmlFor=&quot;feedback&quot;&gt;Feedback&lt;/FieldLabel&gt;<br>          &lt;textarea<br>           id=&quot;feedback&quot;<br>           placeholder=&quot;Your feedback helps us improve...&quot;<br>           rows={4}<br>          /&gt;<br>          &lt;FieldDescription&gt;<br>           Share your thoughts about our service.<br>          &lt;/FieldDescription&gt;<br>         &lt;/Field&gt;<br>        &lt;/FieldGroup&gt;<br>       &lt;/FieldSet&gt;</pre><h3>Select</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ccSJo-R1fhV58GQhh-An3w.gif" /></figure><pre>&lt;Field className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldLabel&gt;Department&lt;/FieldLabel&gt;<br>        &lt;Select&gt;<br>         &lt;SelectTrigger&gt;<br>          &lt;SelectValue placeholder=&quot;Choose department&quot; /&gt;<br>         &lt;/SelectTrigger&gt;<br>         &lt;SelectContent&gt;<br>          &lt;SelectGroup&gt;<br>           &lt;SelectItem value=&quot;engineering&quot;&gt;Engineering&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;design&quot;&gt;Design&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;marketing&quot;&gt;Marketing&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;sales&quot;&gt;Sales&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;support&quot;&gt;Customer Support&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;hr&quot;&gt;Human Resources&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;finance&quot;&gt;Finance&lt;/SelectItem&gt;<br>           &lt;SelectItem value=&quot;operations&quot;&gt;Operations&lt;/SelectItem&gt;<br>          &lt;/SelectGroup&gt;<br>         &lt;/SelectContent&gt;<br>        &lt;/Select&gt;<br>        &lt;FieldDescription&gt;<br>         Select your department or area of work.<br>        &lt;/FieldDescription&gt;<br>       &lt;/Field&gt;</pre><h3>Slider</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-cqw8R6IVlCaTKHVKn0Lag.gif" /></figure><pre>const [value, setValue] = React.useState([200, 800]);<br><br>&lt;Field className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldTitle&gt;Price Range&lt;/FieldTitle&gt;<br>        &lt;FieldDescription&gt;<br>         Set your budget range ($<br>         &lt;span className=&quot;font-medium tabular-nums&quot;&gt;<br>          {value[0]}<br>         &lt;/span&gt; -{&quot; &quot;}<br>         &lt;span className=&quot;font-medium tabular-nums&quot;&gt;{value[1]}&lt;/span&gt;).<br>        &lt;/FieldDescription&gt;<br>        &lt;Slider<br>         value={value}<br>         onValueChange={(value) =&gt; setValue(value as [number, number])}<br>         max={1000}<br>         min={0}<br>         step={10}<br>         className=&quot;mt-2 w-full&quot;<br>         aria-label=&quot;Price Range&quot;<br>        /&gt;<br>       &lt;/Field&gt;</pre><h3>Fieldset</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4MaDe-VtQ13GewL7BNhLQ.png" /></figure><pre>&lt;FieldSet className=&quot;w-full max-w-sm&quot;&gt;<br>        &lt;FieldLegend&gt;Address Information&lt;/FieldLegend&gt;<br>        &lt;FieldDescription&gt;<br>         We need your address to deliver your order.<br>        &lt;/FieldDescription&gt;<br>        &lt;FieldGroup&gt;<br>         &lt;Field&gt;<br>          &lt;FieldLabel htmlFor=&quot;street&quot;&gt;Street Address&lt;/FieldLabel&gt;<br>          &lt;Input id=&quot;street&quot; type=&quot;text&quot; placeholder=&quot;123 Main St&quot; /&gt;<br>         &lt;/Field&gt;<br>         &lt;div className=&quot;grid grid-cols-2 gap-4&quot;&gt;<br>          &lt;Field&gt;<br>           &lt;FieldLabel htmlFor=&quot;city&quot;&gt;City&lt;/FieldLabel&gt;<br>           &lt;Input id=&quot;city&quot; type=&quot;text&quot; placeholder=&quot;New York&quot; /&gt;<br>          &lt;/Field&gt;<br>          &lt;Field&gt;<br>           &lt;FieldLabel htmlFor=&quot;zip&quot;&gt;Postal Code&lt;/FieldLabel&gt;<br>           &lt;Input id=&quot;zip&quot; type=&quot;text&quot; placeholder=&quot;90502&quot; /&gt;<br>          &lt;/Field&gt;<br>         &lt;/div&gt;<br>        &lt;/FieldGroup&gt;<br>       &lt;/FieldSet&gt;</pre><h3>Checkbox</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp6ZPc2af7z08Btjf6alhA.png" /></figure><pre>&lt;FieldGroup className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldSet&gt;<br>         &lt;FieldLegend variant=&quot;label&quot;&gt;<br>          Show these items on the desktop<br>         &lt;/FieldLegend&gt;<br>         &lt;FieldDescription&gt;<br>          Select the items you want to show on the desktop.<br>         &lt;/FieldDescription&gt;<br>         &lt;FieldGroup className=&quot;gap-3&quot;&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;finder-pref-9k2-hard-disks-ljj&quot; /&gt;<br>           &lt;FieldLabel<br>            htmlFor=&quot;finder-pref-9k2-hard-disks-ljj&quot;<br>            className=&quot;font-normal&quot;<br>            defaultChecked<br>           &gt;<br>            Hard disks<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;finder-pref-9k2-external-disks-1yg&quot; /&gt;<br>           &lt;FieldLabel<br>            htmlFor=&quot;finder-pref-9k2-external-disks-1yg&quot;<br>            className=&quot;font-normal&quot;<br>           &gt;<br>            External disks<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;finder-pref-9k2-cds-dvds-fzt&quot; /&gt;<br>           &lt;FieldLabel<br>            htmlFor=&quot;finder-pref-9k2-cds-dvds-fzt&quot;<br>            className=&quot;font-normal&quot;<br>           &gt;<br>            CDs, DVDs, and iPods<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;finder-pref-9k2-connected-servers-6l2&quot; /&gt;<br>           &lt;FieldLabel<br>            htmlFor=&quot;finder-pref-9k2-connected-servers-6l2&quot;<br>            className=&quot;font-normal&quot;<br>           &gt;<br>            Connected servers<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>         &lt;/FieldGroup&gt;<br>        &lt;/FieldSet&gt;<br>        &lt;FieldSeparator /&gt;<br>        &lt;Field orientation=&quot;horizontal&quot;&gt;<br>         &lt;Checkbox<br>          id=&quot;finder-pref-9k2-sync-folders-nep&quot;<br>          defaultChecked<br>         /&gt;<br>         &lt;FieldContent&gt;<br>          &lt;FieldLabel htmlFor=&quot;finder-pref-9k2-sync-folders-nep&quot;&gt;<br>           Sync Desktop &amp; Documents folders<br>          &lt;/FieldLabel&gt;<br>          &lt;FieldDescription&gt;<br>           Your Desktop &amp; Documents folders are being synced with<br>           iCloud Drive. You can access them from other devices.<br>          &lt;/FieldDescription&gt;<br>         &lt;/FieldContent&gt;<br>        &lt;/Field&gt;<br>       &lt;/FieldGroup&gt;</pre><h3>Radio</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o-pCDzJAXSp53TTl9a5VwQ.png" /></figure><pre>&lt;FieldSet className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldLegend variant=&quot;label&quot;&gt;Subscription Plan&lt;/FieldLegend&gt;<br>        &lt;FieldDescription&gt;<br>         Yearly and lifetime plans offer significant savings.<br>        &lt;/FieldDescription&gt;<br>        &lt;RadioGroup defaultValue=&quot;monthly&quot;&gt;<br>         &lt;Field orientation=&quot;horizontal&quot;&gt;<br>          &lt;RadioGroupItem value=&quot;monthly&quot; id=&quot;plan-monthly&quot; /&gt;<br>          &lt;FieldLabel htmlFor=&quot;plan-monthly&quot; className=&quot;font-normal&quot;&gt;<br>           Monthly ($9.99/month)<br>          &lt;/FieldLabel&gt;<br>         &lt;/Field&gt;<br>         &lt;Field orientation=&quot;horizontal&quot;&gt;<br>          &lt;RadioGroupItem value=&quot;yearly&quot; id=&quot;plan-yearly&quot; /&gt;<br>          &lt;FieldLabel htmlFor=&quot;plan-yearly&quot; className=&quot;font-normal&quot;&gt;<br>           Yearly ($99.99/year)<br>          &lt;/FieldLabel&gt;<br>         &lt;/Field&gt;<br>         &lt;Field orientation=&quot;horizontal&quot;&gt;<br>          &lt;RadioGroupItem value=&quot;lifetime&quot; id=&quot;plan-lifetime&quot; /&gt;<br>          &lt;FieldLabel htmlFor=&quot;plan-lifetime&quot; className=&quot;font-normal&quot;&gt;<br>           Lifetime ($299.99)<br>          &lt;/FieldLabel&gt;<br>         &lt;/Field&gt;<br>        &lt;/RadioGroup&gt;<br>       &lt;/FieldSet&gt;</pre><h3>Switch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZBis65_Q-dfZMhTYRTF3Q.png" /></figure><pre>&lt;Field orientation=&quot;horizontal&quot; className=&quot;w-fit&quot;&gt;<br>        &lt;FieldLabel htmlFor=&quot;2fa&quot;&gt;<br>         Multi-factor authentication<br>        &lt;/FieldLabel&gt;<br>        &lt;Switch id=&quot;2fa&quot; /&gt;<br>       &lt;/Field&gt;</pre><h3>Choice Card</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gi6NNzjK__tgwXTdtHH_zA.png" /></figure><pre>&lt;FieldGroup className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldSet&gt;<br>         &lt;FieldLegend variant=&quot;label&quot;&gt;Compute Environment&lt;/FieldLegend&gt;<br>         &lt;FieldDescription&gt;<br>          Select the compute environment for your cluster.<br>         &lt;/FieldDescription&gt;<br>         &lt;RadioGroup defaultValue=&quot;kubernetes&quot;&gt;<br>          &lt;FieldLabel htmlFor=&quot;kubernetes-r2h&quot;&gt;<br>           &lt;Field orientation=&quot;horizontal&quot;&gt;<br>            &lt;FieldContent&gt;<br>             &lt;FieldTitle&gt;Kubernetes&lt;/FieldTitle&gt;<br>             &lt;FieldDescription&gt;<br>              Run GPU workloads on a K8s cluster.<br>             &lt;/FieldDescription&gt;<br>            &lt;/FieldContent&gt;<br>            &lt;RadioGroupItem<br>             value=&quot;kubernetes&quot;<br>             id=&quot;kubernetes-r2h&quot;<br>            /&gt;<br>           &lt;/Field&gt;<br>          &lt;/FieldLabel&gt;<br>          &lt;FieldLabel htmlFor=&quot;vm-z4k&quot;&gt;<br>           &lt;Field orientation=&quot;horizontal&quot;&gt;<br>            &lt;FieldContent&gt;<br>             &lt;FieldTitle&gt;Virtual Machine&lt;/FieldTitle&gt;<br>             &lt;FieldDescription&gt;<br>              Access a cluster to run GPU workloads.<br>             &lt;/FieldDescription&gt;<br>            &lt;/FieldContent&gt;<br>            &lt;RadioGroupItem value=&quot;vm&quot; id=&quot;vm-z4k&quot; /&gt;<br>           &lt;/Field&gt;<br>          &lt;/FieldLabel&gt;<br>         &lt;/RadioGroup&gt;<br>        &lt;/FieldSet&gt;<br>       &lt;/FieldGroup&gt;</pre><h3>Field Group</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lkrOOZSjPe2akQpD6cnE6A.png" /></figure><pre>&lt;FieldGroup className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldSet&gt;<br>         &lt;FieldLabel&gt;Responses&lt;/FieldLabel&gt;<br>         &lt;FieldDescription&gt;<br>          Get notified when ChatGPT responds to requests that take<br>          time, like research or image generation.<br>         &lt;/FieldDescription&gt;<br>         &lt;FieldGroup data-slot=&quot;checkbox-group&quot;&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;push&quot; defaultChecked disabled /&gt;<br>           &lt;FieldLabel htmlFor=&quot;push&quot; className=&quot;font-normal&quot;&gt;<br>            Push notifications<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>         &lt;/FieldGroup&gt;<br>        &lt;/FieldSet&gt;<br>        &lt;FieldSeparator /&gt;<br>        &lt;FieldSet&gt;<br>         &lt;FieldLabel&gt;Tasks&lt;/FieldLabel&gt;<br>         &lt;FieldDescription&gt;<br>          Get notified when tasks you&amp;apos;ve created have updates.{&quot; &quot;}<br>          &lt;a href=&quot;#&quot;&gt;Manage tasks&lt;/a&gt;<br>         &lt;/FieldDescription&gt;<br>         &lt;FieldGroup data-slot=&quot;checkbox-group&quot;&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;push-tasks&quot; /&gt;<br>           &lt;FieldLabel htmlFor=&quot;push-tasks&quot; className=&quot;font-normal&quot;&gt;<br>            Push notifications<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>          &lt;Field orientation=&quot;horizontal&quot;&gt;<br>           &lt;Checkbox id=&quot;email-tasks&quot; /&gt;<br>           &lt;FieldLabel htmlFor=&quot;email-tasks&quot; className=&quot;font-normal&quot;&gt;<br>            Email notifications<br>           &lt;/FieldLabel&gt;<br>          &lt;/Field&gt;<br>         &lt;/FieldGroup&gt;<br>        &lt;/FieldSet&gt;<br>       &lt;/FieldGroup&gt;</pre><h3>Responsive Layout</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_ChHTvbZGV5_6tHlKovLg.png" /></figure><pre>&lt;form className=&quot;md:w-1/2&quot;&gt;<br>        &lt;FieldSet&gt;<br>         &lt;FieldLegend&gt;Profile&lt;/FieldLegend&gt;<br>         &lt;FieldDescription&gt;<br>          Fill in your profile information.<br>         &lt;/FieldDescription&gt;<br>         &lt;FieldGroup&gt;<br>          &lt;Field orientation=&quot;responsive&quot;&gt;<br>           &lt;FieldContent&gt;<br>            &lt;FieldLabel htmlFor=&quot;name&quot;&gt;Name&lt;/FieldLabel&gt;<br>            &lt;FieldDescription&gt;<br>             Provide your full name for identification<br>            &lt;/FieldDescription&gt;<br>           &lt;/FieldContent&gt;<br>           &lt;Input id=&quot;name&quot; placeholder=&quot;Evil Rabbit&quot; required /&gt;<br>          &lt;/Field&gt;<br>          &lt;Field orientation=&quot;responsive&quot;&gt;<br>           &lt;Button type=&quot;submit&quot;&gt;Submit&lt;/Button&gt;<br>           &lt;Button type=&quot;button&quot; variant=&quot;outline&quot;&gt;<br>            Cancel<br>           &lt;/Button&gt;<br>          &lt;/Field&gt;<br>         &lt;/FieldGroup&gt;<br>        &lt;/FieldSet&gt;<br>       &lt;/form&gt;</pre><h3>Validation &amp; Errors</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EmdNHKw0OzTYCCUsaLjGgA.png" /></figure><pre>&lt;FieldSet className=&quot;w-full max-w-xs&quot;&gt;<br>        &lt;FieldGroup&gt;<br>         &lt;Field data-invalid&gt;<br>          &lt;FieldLabel htmlFor=&quot;email&quot;&gt;Email&lt;/FieldLabel&gt;<br>          &lt;Input id=&quot;email&quot; type=&quot;email&quot; aria-invalid /&gt;<br>          &lt;FieldError&gt;Enter a valid email address.&lt;/FieldError&gt;<br>         &lt;/Field&gt;<br>        &lt;/FieldGroup&gt;<br>       &lt;/FieldSet&gt;</pre><h3>Important Architectural Rule</h3><p>Do not mix:</p><ul><li>Orientation variant</li><li>Manual flex/grid layout classes</li></ul><p>Let the component system handle layout.<br>Your earlier issue happened because layout was being overridden manually.</p><p>If vertical, horizontal, and responsive look identical — <br>it means something is overriding the variant classes.</p><p>Field must control layout discipline.<br>That’s the whole point of this abstraction.</p><h3>Accessibility Notes</h3><p>Field ensures:</p><ul><li>Proper label association</li><li>Structured grouping</li><li>Clear error messaging</li><li>Semantic fieldset usage</li><li>Role grouping via role=&quot;group&quot;</li></ul><p>Forms must be navigable.<br>Screen readers must understand relationships.</p><p>Structure defines accessibility.</p><h3>Field vs Just Using Divs</h3><p>You could write:</p><pre>&lt;div&gt;<br>  &lt;label /&gt;<br>  &lt;input /&gt;<br>  &lt;p /&gt;<br>&lt;/div&gt;</pre><p>But then:</p><p>Spacing varies<br>Error alignment differs<br>Horizontal layouts break<br>Responsiveness becomes manual</p><p>Field removes that repetition.</p><p>Consistency scales.<br>Manual styling does not.</p><h3>Best Practices</h3><p>Always wrap form controls in Field<br>Use FieldSet for grouped options<br>Do not place error messages outside Field<br>Use orientation intentionally<br>Keep descriptions concise<br>Avoid stacking too many nested groups</p><p>Forms are interaction-heavy.</p><p>Structure prevents chaos.</p><h3>Summary</h3><p>Field is structural form architecture<br>Separates layout from control logic<br>Supports vertical, horizontal, responsive layouts<br>Standardizes label, description, and error placement<br>Improves accessibility and consistency</p><p>Inputs collect data.<br>Field organizes meaning.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FV0IdVIIW1y5d6%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdTZlcmk2ZGRpeDNqZGs1cWplMHVud2wxNGQ4NzZteHM3eW9scGJkayZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FV0IdVIIW1y5d6%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia2.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbzh5ZjgyNHR3OW56YTVod243azFwNW50MHVsc3JmanhpeXVsajdidSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FV0IdVIIW1y5d6%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e6a732e3fae5443a37f5d11a0074285/href">https://medium.com/media/6e6a732e3fae5443a37f5d11a0074285/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdd7917feac6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 31] Switch: Expressive Binary Preference]]></title>
            <link>https://blog.stackademic.com/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/a41767c82df5</guid>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[radix-ui]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Thu, 19 Feb 2026 02:01:01 GMT</pubDate>
            <atom:updated>2026-02-19T07:59:00.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-26-button-group-structuring-related-actions-15b4a6716206">Part 26: Button Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6">Part 27: Toggle</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286">Part 28: Toggle Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1">Part 29: Checkbox</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de">Part 30: Radio Group</a></li><li>Part 31: Switch</li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/switch">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/switch">here</a></p><p>Switch is a binary control.</p><p>On.<br>Off.</p><p>Enabled.<br>Disabled.</p><p>Unlike Checkbox,<br>Switch feels immediate.</p><p>It communicates:</p><p>This setting changes behavior instantly.</p><p>You’ll commonly see it in:</p><p>Dark mode toggle<br>Notification preferences<br>Privacy settings<br>Feature flags<br>System configuration</p><p>Switch is about <strong>live preference control</strong> — <br>not form confirmation.</p><p>In this part, we’ll build an accessible Switch using <strong>Radix UI</strong>, understand its structure, and clarify when it should be used instead of Checkbox or Toggle.</p><h3>When Should You Use Switch?</h3><p>Use Switch when:</p><p>The state represents a preference<br>The change applies immediately<br>It behaves like a system setting<br>It’s clearly binary</p><p>Avoid Switch when:</p><p>Multiple options are required (use Radio Group)<br>It’s part of a traditional form submission (use Checkbox)<br>It’s a toolbar interaction (use Toggle)</p><p>Switch is expressive.<br>Not structural.</p><h3>Installation</h3><p>Switch is built on Radix UI.</p><pre>npm install @radix-ui/react-switch</pre><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ switch.tsx</pre><h3>Switch Component</h3><p>Switch is powered by:</p><ul><li>@radix-ui/react-switch</li><li>Thumb element for animation</li><li>ARIA attributes for accessibility</li></ul><p>Radix handles:</p><p>Keyboard interaction (Space / Enter)<br>Focus management<br>ARIA roles (role=&quot;switch&quot;)<br>Checked state logic</p><p>We focus on styling and motion.</p><h3>switch.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import * as SwitchPrimitive from &quot;@radix-ui/react-switch&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br><br>type SwitchProps = React.ComponentPropsWithoutRef&lt;<br> typeof SwitchPrimitive.Root<br>&gt; &amp; {<br> size?: &quot;sm&quot; | &quot;default&quot;;<br>};<br><br>const Switch = React.forwardRef&lt;<br> React.ElementRef&lt;typeof SwitchPrimitive.Root&gt;,<br> SwitchProps<br>&gt;(({ className, size = &quot;default&quot;, ...props }, ref) =&gt; {<br> return (<br>  &lt;SwitchPrimitive.Root<br>   ref={ref}<br>   data-size={size}<br>   className={cn(<br>    // Base<br>    &quot;relative inline-flex shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors outline-none&quot;,<br>    &quot;focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2&quot;,<br><br>    // State colors<br>    &quot;data-[state=checked]:bg-primary&quot;,<br>    &quot;data-[state=unchecked]:bg-input&quot;,<br><br>    // Disabled<br>    &quot;disabled:cursor-not-allowed disabled:opacity-50&quot;,<br><br>    // Sizes<br>    size === &quot;default&quot; &amp;&amp; &quot;h-6 w-11&quot;,<br>    size === &quot;sm&quot; &amp;&amp; &quot;h-4 w-8&quot;,<br><br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;SwitchPrimitive.Thumb<br>    className={cn(<br>     &quot;pointer-events-none block rounded-full bg-background shadow transition-transform&quot;,<br><br>     // Thumb size<br>     size === &quot;default&quot; &amp;&amp; &quot;h-5 w-5&quot;,<br>     size === &quot;sm&quot; &amp;&amp; &quot;h-3 w-3&quot;,<br><br>     // Movement<br>     size === &quot;default&quot; &amp;&amp;<br>      &quot;data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0&quot;,<br>     size === &quot;sm&quot; &amp;&amp;<br>      &quot;data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0&quot;,<br>    )}<br>   /&gt;<br>  &lt;/SwitchPrimitive.Root&gt;<br> );<br>});<br><br>Switch.displayName = SwitchPrimitive.Root.displayName;<br><br>export { Switch };</pre><h3>Basic Example</h3><pre>&lt;Switch /&gt;</pre><p>Click → state changes.<br>Feels instant.<br>Feels alive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*HYQ1D8HH6CyE9XnZwny7dQ.gif" /></figure><p>Switch is inherently interactive.</p><h3>With Label</h3><p>Always pair it with text.</p><pre>&lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>  &lt;Switch id=&quot;dark-mode&quot; /&gt;<br>  &lt;label htmlFor=&quot;dark-mode&quot;&gt;Dark Mode&lt;/label&gt;<br>&lt;/div&gt;</pre><p>Without context,<br>a Switch is just motion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*gJzDxfdV0C2tstUazPEk6Q.gif" /></figure><p>With context,<br> it becomes meaning.</p><h3>Controlled Mode</h3><pre>const [enabled, setEnabled] = React.useState(false)<br><br>&lt;Switch checked={enabled} onCheckedChange={setEnabled} /&gt;</pre><p>Use controlled mode when syncing with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*dO7_FBHqcI2ReNOxY5jb5g.gif" /></figure><p>Theme providers<br>Global state<br>API updates<br>Feature toggles</p><p>Switch often triggers side effects.<br>Control it intentionally.</p><h3>Size Variants</h3><p>This implementation supports:</p><pre>&lt;Switch size=&quot;default&quot; /&gt;<br>&lt;Switch size=&quot;sm&quot; /&gt;</pre><p>Small variants are useful in dense UI panels.<br>Default size works better in settings pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*7dpWpqGf2PrS6cgh299LZw.gif" /></figure><p>Scale should match context.</p><h3>Disabled State</h3><pre>&lt;Switch disabled /&gt;</pre><p>Muted visually.<br>Interaction blocked.<br>State preserved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*Dx7-7exPSRkQ9BeVkklFqA.png" /></figure><p>Never disable without explanation.</p><h3>Accessibility Notes</h3><p>Switch includes:</p><p>role=&quot;switch&quot;<br>aria-checked<br> Keyboard support<br> Visible focus ring</p><p>Best practices:</p><p>Always use labels<br>Ensure color contrast<br>Do not rely only on animation<br>Keep motion subtle</p><p>Switch communicates change — <br>but accessibility communicates clarity.</p><h3>Switch vs Checkbox</h3><p>Switch:</p><p>Instant preference<br>Feels like a system setting<br>More expressive</p><p>Checkbox:</p><p>Form submission<br>Explicit confirmation<br>Often part of larger form</p><p>Checkbox is structural.<br>Switch is behavioral.</p><h3>Switch vs Toggle</h3><p>Switch:</p><p>Binary state with meaning<br>Common in settings</p><p>Toggle:</p><p>Toolbar interaction<br>Active styling control</p><p>Switch is semantic preference.<br>Toggle is UI activation.</p><h3>Best Practices</h3><p>Use for clear binary choices<br>Avoid stacking too many in a small space<br>Keep labels concise<br>Provide immediate feedback<br>Avoid using for destructive actions</p><p>Switches should feel confident — <br>not ambiguous.</p><h3>Summary</h3><p>Switch is a binary preference control<br>Built on Radix for accessibility<br>Supports controlled and uncontrolled modes<br>Ideal for settings and live configuration<br>Not interchangeable with Checkbox or Toggle</p><p>UI components are not decoration.<br>They represent intent.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FoYtVHSxngR3lC%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExdTZlcmk2ZGRpeDNqZGs1cWplMHVud2wxNGQ4NzZteHM3eW9scGJkayZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FoYtVHSxngR3lC%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNDFuZXFkNXQyeHduZ3MxamNsZG52NTVmdWo2dWhvdnZ5a2tvNmphMyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FoYtVHSxngR3lC%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="313" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebe5f1933b7ee79c8921283964bb0eb1/href">https://medium.com/media/ebe5f1933b7ee79c8921283964bb0eb1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a41767c82df5" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5">[Shadcn/ui React Series — Part 31] Switch: Expressive Binary Preference</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 30] Radio Group: Single Selection with Intent]]></title>
            <link>https://medium.com/codetodeploy/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/176c6194b3de</guid>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <category><![CDATA[radix-ui]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <category><![CDATA[react-tutorial]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Wed, 18 Feb 2026 02:01:01 GMT</pubDate>
            <atom:updated>2026-02-19T16:13:19.048Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/codetodeploy/master-ai-cloud-coding-in-3-months-start-today-395947ebfd2c">Master AI, Cloud &amp; Coding in 3 Months — Start Today</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-26-button-group-structuring-related-actions-15b4a6716206">Part 26: Button Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6">Part 27: Toggle</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286">Part 28: Toggle Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1">Part 29: Checkbox</a></li><li>Part 30: Radio Group</li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5">Part 31: Switch</a></li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/radio-group">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/radio-group">here</a></p><p>Radio Group is a form control used when <strong>only one option can be selected</strong> from a list.</p><p>Unlike Checkbox,<br>Radio Group enforces exclusivity.</p><p>It communicates:</p><p>You must choose one.<br>Not zero.<br>Not multiple.<br>Exactly one.</p><p>You’ll commonly see it in:</p><p>Payment methods<br>Shipping options<br>Plan selection<br>Survey answers<br>Configuration steps</p><p>Radio Group is about <strong>mutual exclusivity inside form semantics</strong>.</p><p>In this part, we’ll build an accessible Radio Group using <strong>Radix UI</strong>, understand its structure, and clarify when it should be used instead of Checkbox or Toggle Group.</p><h3>When Should You Use Radio Group?</h3><p>Use Radio Group when:</p><p>The user must select exactly one option<br>The value is part of form submission<br>Options are mutually exclusive<br>You need semantic form behavior</p><p>Avoid Radio Group when:</p><p>Multiple selections are allowed (use Checkbox)<br>It’s purely UI toggling (use Toggle Group)<br>You want a visual preference switch (use Switch)</p><p>Radio Group is about <strong>forced clarity in choice</strong>.</p><h3>Installation</h3><p>Radio Group is built on Radix UI.</p><pre>npm install @radix-ui/react-radio-group</pre><p>Lucide is used for the inner circle icon.</p><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ radio-group.tsx</pre><h3>Radio Group Component</h3><p>Radio Group is powered by:</p><ul><li>@radix-ui/react-radio-group</li><li>Indicator for selected state</li><li>ARIA attributes for accessibility</li></ul><p>Radix handles:</p><p>Keyboard navigation (Arrow keys)<br>Focus management<br>ARIA roles<br>Roving tab index behavior</p><p>We focus on styling and consistency.</p><h3>radio-group.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import { RadioGroup as RadioGroupPrimitive } from &quot;radix-ui&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { CircleIcon } from &quot;lucide-react&quot;;<br><br>function RadioGroup({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof RadioGroupPrimitive.Root&gt;) {<br> return (<br>  &lt;RadioGroupPrimitive.Root<br>   data-slot=&quot;radio-group&quot;<br>   className={cn(&quot;grid gap-2 w-full&quot;, className)}<br>   {...props}<br>  /&gt;<br> );<br>}<br>function RadioGroupItem({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof RadioGroupPrimitive.Item&gt;) {<br> return (<br>  &lt;RadioGroupPrimitive.Item<br>   data-slot=&quot;radio-group-item&quot;<br>   className={cn(<br>    &quot;border-input text-primary dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 flex size-4 rounded-full focus-visible:ring-3 aria-invalid:ring-3 group/radio-group-item peer relative aspect-square shrink-0 border outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;RadioGroupPrimitive.Indicator<br>    data-slot=&quot;radio-group-indicator&quot;<br>    className=&quot;group-aria-invalid/radio-group-item:text-destructive text-primary flex size-4 items-center justify-center&quot;<br>   &gt;<br>    &lt;CircleIcon className=&quot;absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 fill-current&quot; /&gt;<br>   &lt;/RadioGroupPrimitive.Indicator&gt;<br>  &lt;/RadioGroupPrimitive.Item&gt;<br> );<br>}<br>export { RadioGroup, RadioGroupItem };</pre><h3>Basic Example</h3><pre>&lt;RadioGroup defaultValue=&quot;card&quot;&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;card&quot; id=&quot;card&quot; /&gt;<br>         &lt;label htmlFor=&quot;card&quot;&gt;Credit Card&lt;/label&gt;<br>        &lt;/div&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;paypal&quot; id=&quot;paypal&quot; /&gt;<br>         &lt;label htmlFor=&quot;paypal&quot;&gt;PayPal&lt;/label&gt;<br>        &lt;/div&gt;<br>       &lt;/RadioGroup&gt;</pre><p>Select one → the other is automatically deselected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*QtTgRCh1k3ki0FjYYRNkUA.gif" /></figure><p>That exclusivity is enforced by design.</p><h3>Controlled Mode</h3><p>If you need full control:</p><pre>const [value, setValue] = React.useState(&quot;card&quot;)<br><br>&lt;RadioGroup defaultValue=&quot;card&quot;&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;card&quot; id=&quot;card&quot; /&gt;<br>         &lt;label htmlFor=&quot;card&quot;&gt;Credit Card&lt;/label&gt;<br>        &lt;/div&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;paypal&quot; id=&quot;paypal&quot; /&gt;<br>         &lt;label htmlFor=&quot;paypal&quot;&gt;PayPal&lt;/label&gt;<br>        &lt;/div&gt;<br>       &lt;/RadioGroup&gt;</pre><p>Use controlled mode when syncing with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*QtTgRCh1k3ki0FjYYRNkUA.gif" /></figure><p>Form libraries<br>Global state<br>API payload preparation<br>Validation logic</p><p>Radio Group works cleanly in both modes.</p><h3>Disabled State</h3><pre>&lt;RadioGroup defaultValue=&quot;card&quot;&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;card&quot; id=&quot;card&quot; disabled /&gt;<br>         &lt;label htmlFor=&quot;card&quot;&gt;Credit Card&lt;/label&gt;<br>        &lt;/div&gt;<br>        &lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>         &lt;RadioGroupItem value=&quot;paypal&quot; id=&quot;paypal&quot; /&gt;<br>         &lt;label htmlFor=&quot;paypal&quot;&gt;PayPal&lt;/label&gt;<br>        &lt;/div&gt;<br>       &lt;/RadioGroup&gt;</pre><p>Visually muted.<br>Interaction blocked.<br>Semantics preserved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*S09v2jneruhF62byjY3Xfw.png" /></figure><p>Disabled options still communicate information — <br>just not availability.</p><h3>Accessibility Notes</h3><p>Radio Group includes:</p><p>role=&quot;radiogroup&quot;<br>role=&quot;radio&quot;<br>aria-checked<br> Keyboard support (Arrow keys + Space)<br> Focus ring visibility</p><p>Best practices:</p><p>Always use labels<br>Keep options clearly spaced<br>Do not rely only on color<br>Ensure focus state is visible</p><p>Radio Groups must be navigable without a mouse.</p><h3>Radio Group vs Checkbox</h3><p>Radio Group:</p><p>Only one selection<br>Mutually exclusive<br>Required choice scenarios</p><p>Checkbox:</p><p>Multiple selections allowed<br>Optional confirmations<br>Independent values</p><p>Checkbox is independent.<br>Radio Group is exclusive.</p><h3>Radio Group vs Toggle Group</h3><p>Radio Group:</p><p>Form semantic<br>Participates in submission<br>Accessible by default</p><p>Toggle Group:</p><p>UI interaction<br>Toolbar-like controls<br>Not inherently form-driven</p><p>Radio Group is structural.<br>Toggle Group is behavioral.</p><h3>Best Practices</h3><p>Keep options vertically aligned<br>Always pair with labels<br>Avoid too many choices<br>Group logically related items<br>Provide a default when appropriate</p><p>If the user hesitates,<br>your options are unclear.</p><h3>Summary</h3><p>Radio Group enforces single selection<br>Built on Radix for accessibility<br>Supports controlled and uncontrolled modes<br>Ideal for mutually exclusive form inputs<br>Not interchangeable with Checkbox or Toggle Group</p><p>Form components carry meaning.<br>Clarity in intent defines the right choice.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F2vBIaOa6X7VGQOOeet%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPWVjZjA1ZTQ3anNyN2tzY21nZ3Z2OHZyNXN1YXo5NDJ2dGNpNjA5a2hoZW5qcmJ5ZyZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2F2vBIaOa6X7VGQOOeet%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExbjFpbGg1MmlvZ3prdnQzajducDljb3pmdTBucHozd3huczAyNWp6NCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2F2vBIaOa6X7VGQOOeet%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/9405f7587f59688491da05428146180c/href">https://medium.com/media/9405f7587f59688491da05428146180c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=176c6194b3de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codetodeploy/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de">[Shadcn/ui React Series — Part 30] Radio Group: Single Selection with Intent</a> was originally published in <a href="https://medium.com/codetodeploy">CodeToDeploy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 29] Checkbox: Handling Form State with Clarity]]></title>
            <link>https://javascript.plainenglish.io/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/4560c35832e1</guid>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[radix-ui]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 02:01:04 GMT</pubDate>
            <atom:updated>2026-02-19T07:57:44.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-26-button-group-structuring-related-actions-15b4a6716206">Part 26: Button Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6">Part 27: Toggle</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286">Part 28: Toggle Group</a></li><li>Part 29: Checkbox</li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de">Part 30: Radio Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5">Part 31: Switch</a></li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/checkbox">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/checkbox">here</a></p><p>Checkbox is a form control used to represent a true/false value.</p><p>Unlike Toggle,<br>Checkbox is semantic.</p><p>It participates in form submission.<br>It represents user consent or selection.<br>It communicates data — not just UI state.</p><p>You’ll commonly see it in:</p><p>Terms and conditions<br>Multi-select forms<br>Preferences<br>Filter panels<br>Settings forms</p><p>Checkbox is about form intent — <br>not quick visual interaction.</p><p>In this part, we’ll build an accessible Checkbox using Radix UI, understand its states, and clarify when it should be used instead of Toggle or Switch.</p><h3>When Should You Use Checkbox?</h3><p>Use Checkbox when:</p><p>The value is part of form data<br>Multiple selections are allowed<br>You need explicit user confirmation<br>The state affects submission</p><p>Avoid Checkbox when:</p><p>You need instant UI-only state (use Toggle)<br>The selection is mutually exclusive (use Radio Group)<br>You want a mobile-style preference switch (use Switch)</p><p>Checkbox is about form semantics.</p><h3>Installation</h3><p>Checkbox is built on Radix UI.</p><pre>npm install @radix-ui/react-checkbox</pre><p>Lucide is used for the check icon.</p><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ checkbox.tsx</pre><h3>Checkbox Component</h3><p>Checkbox is powered by:</p><p>@radix-ui/react-checkbox<br>Indicator for checked state<br>ARIA attributes for accessibility</p><p>Radix handles:</p><p>Keyboard interaction<br>Focus management<br>Indeterminate state<br>ARIA roles</p><p>We focus on styling and consistency.</p><h3>checkbox.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import { Checkbox as CheckboxPrimitive } from &quot;radix-ui&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { CheckIcon } from &quot;lucide-react&quot;;<br><br>function Checkbox({<br> className,<br> ...props<br>}: React.ComponentProps&lt;typeof CheckboxPrimitive.Root&gt;) {<br> return (<br>  &lt;CheckboxPrimitive.Root<br>   data-slot=&quot;checkbox&quot;<br>   className={cn(<br>    &quot;border-input dark:bg-input/30 data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary data-checked:border-primary aria-invalid:aria-checked:border-primary aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 flex size-4 items-center justify-center rounded-[4px] border transition-colors group-has-disabled/field:opacity-50 focus-visible:ring-3 aria-invalid:ring-3 peer relative shrink-0 outline-none after:absolute after:-inset-x-3 after:-inset-y-2 disabled:cursor-not-allowed disabled:opacity-50&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;CheckboxPrimitive.Indicator<br>    data-slot=&quot;checkbox-indicator&quot;<br>    className=&quot;[&amp;&gt;svg]:size-3.5 grid place-content-center text-current transition-none&quot;<br>   &gt;<br>    &lt;CheckIcon /&gt;<br>   &lt;/CheckboxPrimitive.Indicator&gt;<br>  &lt;/CheckboxPrimitive.Root&gt;<br> );<br>}<br>export { Checkbox };</pre><h3>Basic Example</h3><pre>&lt;Checkbox /&gt;</pre><p>Click once → checked<br>Click again → unchecked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*dAuf6NWwFzKUfPAhq_j8cg.gif" /></figure><p>State is managed internally.</p><h3>With Label</h3><p>Checkbox without label is unclear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*S_BGUZDHfV7iQR6Eb0kYTQ.gif" /></figure><p>Always pair it with text.</p><pre>&lt;div className=&quot;flex items-center gap-2&quot;&gt;<br>  &lt;Checkbox id=&quot;terms&quot; /&gt;<br>  &lt;label htmlFor=&quot;terms&quot;&gt;<br>    I agree to the terms and conditions<br>  &lt;/label&gt;<br>&lt;/div&gt;</pre><p>Labels improve accessibility and usability.</p><h3>Controlled Mode</h3><p>If you need to control it manually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*n2hxsYr9ArgUGBjtPPscUQ.gif" /></figure><pre>type CheckedState = boolean | &quot;indeterminate&quot;;<br><br>const [checked, setChecked] = React.useState&lt;CheckedState&gt;(false);<br><br>&lt;Checkbox<br>  checked={checked}<br>  onCheckedChange={setChecked}<br>/&gt;</pre><p>Use controlled mode when syncing with:</p><p>Form libraries<br>Global state<br>API payload preparation<br>Validation logic</p><h3>Indeterminate State</h3><p>Checkbox supports an indeterminate state.</p><p>Useful for:</p><p>Select all patterns<br>Tree structures<br>Partial selections</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*O34ImITL7WDWdvUL4XV5Dg.png" /></figure><pre>&lt;Checkbox checked=&quot;indeterminate&quot; /&gt;</pre><p>This communicates partial selection clearly.</p><h3>Disabled State</h3><pre>&lt;Checkbox disabled /&gt;</pre><p>Visually muted.<br>Interaction blocked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*kFSOGbjPEdu_lFV1F4FV2w.png" /></figure><p>Always reflect disabled logic in UI.</p><h3>Accessibility Notes</h3><p>Checkbox includes:</p><p>aria-checked<br>Keyboard support (Space)<br>Focus ring visibility<br>Proper role=”checkbox”</p><p>Best practices:</p><p>Always use a label<br>Ensure contrast is visible<br>Do not rely only on color<br>Respect disabled semantics</p><p>Form controls must be predictable.</p><h3>Checkbox vs Toggle</h3><p>Checkbox:</p><p>Form control<br>Semantic meaning<br>Used in submission</p><p>Toggle:</p><p>UI state control<br>Toolbar interaction<br>Not inherently form-driven</p><p>Checkbox is about data.<br>Toggle is about interaction.</p><h3>Checkbox vs Switch</h3><p>Checkbox:</p><p>Explicit selection<br>Often multiple options<br>Common in forms</p><p>Switch:</p><p>Binary preference<br>Feels like system setting<br>More visual emphasis</p><p>Switch is expressive.<br>Checkbox is structural.</p><h3>Best Practices</h3><p>Always pair with labels<br>Avoid oversized checkbox grids<br>Keep spacing clean<br>Group related options<br>Use indeterminate carefully</p><p>Checkboxes should communicate clearly — <br>not create doubt.</p><h3>Summary</h3><p>Checkbox is a semantic form control<br>Built on Radix for accessibility<br>Supports checked and indeterminate states<br>Works in controlled or uncontrolled mode<br>Ideal for multi-select forms and confirmations</p><p>UI components are not interchangeable — <br>intent defines the right choice.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FcUwGgCXXyPtrq%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPWVjZjA1ZTQ3MTZiZGQ1NXJuZXB5azQ1dTd5c2k4Y2JtZTgya2l1OGE4bWtkZXF6aiZlcD12MV9naWZzX3JlbGF0ZWQmY3Q9Zw%2FcUwGgCXXyPtrq%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExZGNobmxpOWpxcnUwOGFnbGpoOG1vY245dnFhMTZvc2Y1dHVtcXpuayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FcUwGgCXXyPtrq%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="257" frameborder="0" scrolling="no"><a href="https://medium.com/media/63e75f1e772bf02131c1e3f735ffda22/href">https://medium.com/media/63e75f1e772bf02131c1e3f735ffda22/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4560c35832e1" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1">[Shadcn/ui React Series — Part 29] Checkbox: Handling Form State with Clarity</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 28] Toggle Group: Managing Multiple States in One Control]]></title>
            <link>https://medium.com/coding-nexus/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/25cb33863286</guid>
            <category><![CDATA[radix-ui]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 01:26:44 GMT</pubDate>
            <atom:updated>2026-02-19T07:56:55.991Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-26-button-group-structuring-related-actions-15b4a6716206">Part 26: Button Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6">Part 27: Toggle</a></li><li>Part 28: Toggle Group</li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1">Part 29: Checkbox</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de">Part 30: Radio Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5">Part 31: Switch</a></li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/toggle-group">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/toggle-group">here</a></p><p>Toggle Group allows you to combine multiple Toggle items into a single logical control.</p><p>Instead of managing one binary state, you manage a <strong>set of related states</strong>.</p><p>You’ll commonly see it in:</p><p>Text alignment (Left / Center / Right)<br>View switchers (Grid / List / Compact)<br>Editor toolbars<br>Segmented controls<br>Filter modes</p><p>A Toggle Group is not just a visual wrapper — <br>it defines how toggles behave together.</p><p>In this part, we’ll build a flexible Toggle Group powered by Radix UI, support spacing and orientation, and understand when to use single vs multiple selection modes.</p><h3>When Should You Use Toggle Group?</h3><p>Use Toggle Group when:</p><p>You have multiple related options<br>The options belong to the same category<br>You want compact grouped interaction<br>You need single or multiple selection logic</p><p>Avoid Toggle Group when:</p><p>Options are unrelated<br>You need full form semantics (use Radio Group instead)<br>Actions are independent (use separate Toggle components)</p><p>Toggle Group is about grouped state management — <br>not form submission.</p><h3>Installation</h3><p>Toggle Group is built on Radix UI.</p><pre>npm install @radix-ui/react-toggle-group</pre><p>(If you’re already using Toggle from the previous part, you’re halfway there.)</p><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      ├─ toggle.tsx<br>      └─ toggle-group.tsx</pre><h3>Toggle Group Component</h3><p>Toggle Group is powered by:</p><p>@radix-ui/react-toggle-group<br>Context for shared variant/size<br>data attributes for styling<br>Single or multiple selection modes</p><p>Radix handles:</p><p>Keyboard navigation<br>Roving focus<br>ARIA roles<br>State logic</p><p>We focus on structure, spacing, and visual consistency.</p><h3>toggle-group.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import { type VariantProps } from &quot;class-variance-authority&quot;;<br>import { ToggleGroup as ToggleGroupPrimitive } from &quot;radix-ui&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { toggleVariants } from &quot;./toggle.variants&quot;;<br><br>const ToggleGroupContext = React.createContext&lt;<br> VariantProps&lt;typeof toggleVariants&gt; &amp; {<br>  spacing?: number;<br>  orientation?: &quot;horizontal&quot; | &quot;vertical&quot;;<br> }<br>&gt;({<br> size: &quot;default&quot;,<br> variant: &quot;default&quot;,<br> spacing: 0,<br> orientation: &quot;horizontal&quot;,<br>});<br>function ToggleGroup({<br> className,<br> variant,<br> size,<br> spacing = 0,<br> orientation = &quot;horizontal&quot;,<br> children,<br> ...props<br>}: React.ComponentProps&lt;typeof ToggleGroupPrimitive.Root&gt; &amp;<br> VariantProps&lt;typeof toggleVariants&gt; &amp; {<br>  spacing?: number;<br>  orientation?: &quot;horizontal&quot; | &quot;vertical&quot;;<br> }) {<br> return (<br>  &lt;ToggleGroupPrimitive.Root<br>   data-slot=&quot;toggle-group&quot;<br>   data-variant={variant}<br>   data-size={size}<br>   data-spacing={spacing}<br>   data-orientation={orientation}<br>   style={{ &quot;--gap&quot;: spacing } as React.CSSProperties}<br>   className={cn(<br>    &quot;rounded-lg data-[size=sm]:rounded-[min(var(--radius-md),10px)] group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] data-vertical:flex-col data-vertical:items-stretch&quot;,<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   &lt;ToggleGroupContext.Provider<br>    value={{ variant, size, spacing, orientation }}<br>   &gt;<br>    {children}<br>   &lt;/ToggleGroupContext.Provider&gt;<br>  &lt;/ToggleGroupPrimitive.Root&gt;<br> );<br>}<br>function ToggleGroupItem({<br> className,<br> children,<br> variant = &quot;default&quot;,<br> size = &quot;default&quot;,<br> ...props<br>}: React.ComponentProps&lt;typeof ToggleGroupPrimitive.Item&gt; &amp;<br> VariantProps&lt;typeof toggleVariants&gt;) {<br> const context = React.useContext(ToggleGroupContext);<br> return (<br>  &lt;ToggleGroupPrimitive.Item<br>   data-slot=&quot;toggle-group-item&quot;<br>   data-variant={context.variant || variant}<br>   data-size={context.size || size}<br>   data-spacing={context.spacing}<br>   className={cn(<br>    &quot;group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-l-lg group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-lg group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-r-lg group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-lg shrink-0 focus:z-10 focus-visible:z-10 group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:border-l-0 group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:border-t-0 group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-l group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-t&quot;,<br>    toggleVariants({<br>     variant: context.variant || variant,<br>     size: context.size || size,<br>    }),<br>    className,<br>   )}<br>   {...props}<br>  &gt;<br>   {children}<br>  &lt;/ToggleGroupPrimitive.Item&gt;<br> );<br>}<br>export { ToggleGroup, ToggleGroupItem };</pre><h3>Single Selection Mode</h3><p>Use type=&quot;single&quot; when only one item can be active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*odV3htiUOFEzwbh83DCnlQ.gif" /></figure><pre>&lt;ToggleGroup type=&quot;single&quot; defaultValue=&quot;left&quot;&gt;<br>        &lt;ToggleGroupItem value=&quot;left&quot;&gt;Left&lt;/ToggleGroupItem&gt;<br>        &lt;ToggleGroupItem value=&quot;center&quot;&gt;Center&lt;/ToggleGroupItem&gt;<br>        &lt;ToggleGroupItem value=&quot;right&quot;&gt;Right&lt;/ToggleGroupItem&gt;<br>       &lt;/ToggleGroup&gt;</pre><p>Perfect for:</p><p>Text alignment<br>View mode selection<br>Segmented controls</p><p>Only one item stays active at a time.</p><h3>Multiple Selection Mode</h3><p>Use type=&quot;multiple&quot; when multiple items can be active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*6OXygj5Woxo081Lltm0rGw.gif" /></figure><pre>&lt;ToggleGroup type=&quot;multiple&quot;&gt;<br>  &lt;ToggleGroupItem value=&quot;bold&quot;&gt;Bold&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;italic&quot;&gt;Italic&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;underline&quot;&gt;Underline&lt;/ToggleGroupItem&gt;<br>&lt;/ToggleGroup&gt;</pre><p>Common in editor toolbars.</p><p>Each item maintains its own state.</p><h3>With Spacing</h3><p>You can control spacing between items.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*rLYjXyThOnMNh9ByB-GClw.gif" /></figure><pre>&lt;ToggleGroup type=&quot;single&quot; spacing={4}&gt;<br>  &lt;ToggleGroupItem value=&quot;grid&quot;&gt;Grid&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;list&quot;&gt;List&lt;/ToggleGroupItem&gt;<br>&lt;/ToggleGroup&gt;</pre><p>spacing={0} creates a seamless segmented control.<br> Higher spacing separates items visually.</p><h3>Vertical Orientation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*7SNmG3Dz7I5R0r6Dx8Xe9Q.gif" /></figure><pre>&lt;ToggleGroup type=&quot;single&quot; orientation=&quot;vertical&quot;&gt;<br>  &lt;ToggleGroupItem value=&quot;top&quot;&gt;Top&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;middle&quot;&gt;Middle&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;bottom&quot;&gt;Bottom&lt;/ToggleGroupItem&gt;<br>&lt;/ToggleGroup&gt;</pre><p>Great for side panels and compact menus.</p><h3>Controlled Mode</h3><p>If you need full control:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*N7UbNngRiErsDoNydaBDJA.gif" /></figure><pre>const [value, setValue] = React.useState(&quot;left&quot;)<br><br>&lt;ToggleGroup<br>  type=&quot;single&quot;<br>  value={value}<br>  onValueChange={setValue}<br>&gt;<br>  &lt;ToggleGroupItem value=&quot;left&quot;&gt;Left&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;center&quot;&gt;Center&lt;/ToggleGroupItem&gt;<br>  &lt;ToggleGroupItem value=&quot;right&quot;&gt;Right&lt;/ToggleGroupItem&gt;<br>&lt;/ToggleGroup&gt;</pre><p>Use controlled mode when syncing with:</p><p>Editor state<br>URL parameters<br>Global store<br>Persistent settings</p><h3>Accessibility Notes</h3><p>Toggle Group includes:</p><p>Proper ARIA roles<br>Keyboard navigation (Arrow keys)<br>Roving focus management<br>Clear pressed state</p><p>Best practices:</p><p>Use clear value labels<br>Avoid icon-only items without tooltip<br>Ensure active contrast is visible<br>Keep grouping logical</p><p>Grouped interaction must feel predictable.</p><h3>Toggle Group vs Radio Group</h3><p>Toggle Group (single):</p><p>UI state control<br>Instant visual feedback<br>Toolbar usage</p><p>Radio Group:</p><p>Form control<br>Submission semantics<br>Traditional form behavior</p><p>If it’s about UI state — use Toggle Group.<br>If it’s about form data — use Radio Group.</p><h3>Toggle Group vs Button Group</h3><p>Button Group:</p><p>Visual grouping only<br>No persistent state</p><p>Toggle Group:</p><p>Manages active state<br>Controls selection logic</p><p>State is the difference.</p><h3>Best Practices</h3><p>Keep items consistent in size<br>Avoid mixing too many variants<br>Use spacing intentionally<br>Prefer single selection for mutually exclusive options<br>Use multiple only when truly needed</p><p>A Toggle Group should feel tight and intentional — <br>not scattered.</p><h3>Summary</h3><p>Toggle Group manages related toggle states<br>Built on Radix for accessibility<br>Supports single and multiple selection<br>Handles spacing and orientation<br>Ideal for toolbars and segmented controls</p><p>Good component design isn’t about grouping buttons — <br>it’s about grouping meaning.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FizxssunslJds0wvn7H%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExaXB2cnJvZ21vdXh1ajd6aW1teDdoNGNzMTR6bGI1ZHZnMWl1MzltcCZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FizxssunslJds0wvn7H%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExY2RkMDhwejdoeW1wN2ZwYW8yaXBrem94YWNkb3lrMmpsdXplZ2V4MCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FizxssunslJds0wvn7H%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/b373c02fd3b593e7061a52221828b000/href">https://medium.com/media/b373c02fd3b593e7061a52221828b000/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25cb33863286" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coding-nexus/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286">[Shadcn/ui React Series — Part 28] Toggle Group: Managing Multiple States in One Control</a> was originally published in <a href="https://medium.com/coding-nexus">Coding Nexus</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Shadcn/ui React Series — Part 27] Toggle: Controlling Binary Actions with Precision]]></title>
            <link>https://medium.com/codetodeploy/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6?source=rss-d27cc2537172------2</link>
            <guid isPermaLink="false">https://medium.com/p/9972883676a6</guid>
            <category><![CDATA[radix-ui-react-tutorial]]></category>
            <category><![CDATA[react-action-components]]></category>
            <category><![CDATA[react-design-systems]]></category>
            <category><![CDATA[shadcn-ui-button-group]]></category>
            <dc:creator><![CDATA[Rivai Nasution]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 02:01:00 GMT</pubDate>
            <atom:updated>2026-02-19T15:43:11.700Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F-_QNyXJx9rcRkhN" /></figure><p><strong>Shadcn/ui React Series Actions Components:</strong></p><ul><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-26-button-group-structuring-related-actions-15b4a6716206">Part 26: Button Group</a></li><li>Part 27: Toggle</li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-28-toggle-group-managing-multiple-states-in-one-control-25cb33863286">Part 28: Toggle Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-29-checkbox-handling-form-state-with-clarity-4560c35832e1">Part 29: Checkbox</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-30-radio-group-single-selection-with-intent-176c6194b3de">Part 30: Radio Group</a></li><li><a href="https://medium.com/@rivainasution/shadcn-ui-react-series-part-31-switch-expressive-binary-preference-a41767c82df5">Part 31: Switch</a></li></ul><p>Read documentation <a href="https://ui.shadcn.com/docs/components/radix/toggle">here</a></p><p>Demo in <a href="https://kairos-nine-pi.vercel.app/ui/toggle">here</a></p><blockquote>🚀 Master AI, Cloud &amp; Coding in 3 Months — Start Today</blockquote><blockquote>— <a href="https://www.dpbolvw.net/click-101641947-17135603">Start Your Free Trial Now!</a></blockquote><p>Toggle is a two-state button component used to represent an on/off condition.</p><p>Unlike a regular button, a Toggle maintains state.</p><p>You’ll commonly see it in:</p><p>Text formatting tools (Bold, Italic, Underline)<br>View mode switchers (Grid / List)<br>Feature activation controls<br>Filter chips<br>Compact toolbars</p><p>A Toggle is not just a button — <br>it visually communicates whether something is active.</p><p>In this part, we’ll build an accessible Toggle component using Radix UI, explore variants and sizes, and understand when Toggle is the right choice.</p><h3>When Should You Use Toggle?</h3><p>Use Toggle when:</p><ul><li>You need a binary on/off state</li><li>The state must be visually persistent</li><li>You’re building toolbars or formatting controls</li><li>You want compact interaction</li></ul><p>Avoid Toggle when:</p><ul><li>The action is one-time only (use Button instead)</li><li>You need multiple selections (use Toggle Group)</li><li>The state affects form submission (consider Checkbox)</li></ul><p>Toggle is about immediate UI state — not form semantics.</p><h3>Installation</h3><p>Toggle is built on Radix UI.</p><pre>npm install @radix-ui/react-toggle<br>npm install class-variance-authority</pre><h3>File Structure</h3><pre>src/<br>└─ components/<br>   └─ ui/<br>      └─ toggle.tsx</pre><h3>Toggle Component</h3><p>Toggle is powered by:</p><ul><li>@radix-ui/react-toggle</li><li>data-state=&quot;on&quot; for styling</li><li>aria-pressed for accessibility</li></ul><p>Radix handles:</p><ul><li>Keyboard interaction</li><li>Focus management</li><li>ARIA roles</li><li>State control</li></ul><p>We focus on styling and flexibility.</p><h3>toggle.variants.tsx</h3><pre>import { cva } from &quot;class-variance-authority&quot;;<br><br>export const toggleVariants = cva(<br> &quot;inline-flex items-center justify-center gap-1 whitespace-nowrap rounded-sm text-sm font-medium transition-all outline-none focus-visible:ring-[3px] focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&amp;_svg]:pointer-events-none [&amp;_svg]:shrink-0&quot;,<br> {<br>  variants: {<br>   variant: {<br>    default:<br>     &quot;bg-transparent hover:bg-muted data-[state=on]:bg-green-700 data-[state=on]:text-primary-foreground&quot;,<br>    outline:<br>     &quot;border border-input bg-transparent hover:bg-muted data-[state=on]:bg-green-700 data-[state=on]:text-primary-foreground data-[state=on]:border-green-700&quot;,<br>   },<br>   size: {<br>    default: &quot;h-8 min-w-8 px-2&quot;,<br>    sm: &quot;h-7 min-w-7 px-1.5 text-xs&quot;,<br>    lg: &quot;h-9 min-w-9 px-2.5&quot;,<br>   },<br>  },<br>  defaultVariants: {<br>   variant: &quot;default&quot;,<br>   size: &quot;default&quot;,<br>  },<br> },<br>);</pre><h3>toggle.tsx</h3><pre>import * as React from &quot;react&quot;;<br>import * as TogglePrimitive from &quot;@radix-ui/react-toggle&quot;;<br>import { type VariantProps } from &quot;class-variance-authority&quot;;<br>import { cn } from &quot;@/lib/utils&quot;;<br>import { toggleVariants } from &quot;./toggle.variants&quot;;<br><br>export function Toggle({<br> className,<br> variant,<br> size,<br> ...props<br>}: React.ComponentProps&lt;typeof TogglePrimitive.Root&gt; &amp;<br> VariantProps&lt;typeof toggleVariants&gt;) {<br> return (<br>  &lt;TogglePrimitive.Root<br>   data-slot=&quot;toggle&quot;<br>   className={cn(<br>    toggleVariants({ variant, size }),<br>    &quot;rtl:flex-row-reverse&quot;,<br>    className,<br>   )}<br>   {...props}<br>  /&gt;<br> );<br>}</pre><h3>Basic Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*xF93D__AaX1XcKaaesE7kw.gif" /></figure><pre>&lt;Toggle&gt;Bold&lt;/Toggle&gt;</pre><p>Click once → active<br>Click again → inactive</p><p>State is managed automatically by Radix.</p><h3>With Icon</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*0DzYr1usd5wJFVNlMvhNEg.gif" /></figure><pre>import { Bold } from &quot;lucide-react&quot;<br><br>&lt;Toggle&gt;<br>  &lt;Bold size={16} /&gt;<br>  Bold<br>&lt;/Toggle&gt;</pre><p>Great for formatting controls.</p><h3>Outline Variant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Jgikmflfc8GDBH15WrawwQ.gif" /></figure><pre>&lt;Toggle variant=&quot;outline&quot;&gt;<br>  Italic<br>&lt;/Toggle&gt;</pre><p>Adds a subtle border for stronger separation.</p><h3>Sizes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*Wpkvn23ehoYd1OODlb9oVA.gif" /></figure><pre>&lt;Toggle size=&quot;sm&quot;&gt;Small&lt;/Toggle&gt;<br>&lt;Toggle size=&quot;default&quot;&gt;Default&lt;/Toggle&gt;<br>&lt;Toggle size=&quot;lg&quot;&gt;Large&lt;/Toggle&gt;</pre><p>Keep sizing consistent inside toolbars.</p><h3>Controlled Mode</h3><p>If you need to control state manually:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*fPNUAgO5Uh3zQonS6AAU5g.gif" /></figure><pre>const [pressed, setPressed] = React.useState(false)<br><br>&lt;Toggle<br>  pressed={pressed}<br>  onPressedChange={setPressed}<br>&gt;<br>  Dark Mode<br>&lt;/Toggle&gt;</pre><p>Use controlled mode when syncing with:</p><ul><li>Global state</li><li>URL parameters</li><li>Editor state</li><li>Settings persistence</li></ul><h3>Disabled State</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*N0eTEisbPn8LfEK2jvHWFQ.png" /></figure><pre>&lt;Toggle disabled&gt;<br>  Locked<br>&lt;/Toggle&gt;</pre><p>Interaction is blocked and visually muted.</p><h3>RTL Support</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*n-xRUTch8Ma3lxDhmVmacA.gif" /></figure><pre>&lt;div dir=&quot;rtl&quot;&gt;<br>  &lt;Toggle&gt;<br>    تنسيق<br>  &lt;/Toggle&gt;<br>&lt;/div&gt;</pre><p>Layout automatically mirrors.</p><h3>Accessibility Notes</h3><p>Toggle includes:</p><ul><li>aria-pressed</li><li>Keyboard interaction (Enter / Space)</li><li>Focus visibility</li><li>Proper role handling</li></ul><p>Best practices:</p><ul><li>Use clear labels</li><li>Avoid icon-only toggles without tooltip</li><li>Ensure active state contrast is visible</li></ul><p>Accessibility is not optional — it’s part of component design.</p><h3>Toggle vs Button</h3><p>Button:</p><ul><li>Triggers an action</li><li>No persistent state</li></ul><p>Toggle:</p><ul><li>Maintains active/inactive state</li><li>Represents a condition</li></ul><p>If users need to see whether something is active — use Toggle.</p><h3>Toggle vs Checkbox</h3><p>Toggle:</p><ul><li>UI state control</li><li>Often instant feedback</li><li>Used in toolbars</li></ul><p>Checkbox:</p><ul><li>Form control</li><li>Used in submissions</li><li>Typically part of form data</li></ul><p>Different intent. Different semantics.</p><h3>Best Practices</h3><p>Keep toggles minimal<br>Use icons for clarity<br>Avoid mixing too many visual variants<br>Group related toggles together<br>Maintain consistent sizing</p><p>A toggle should feel immediate and responsive — not heavy.</p><h3>Summary</h3><p>Toggle is a binary state button<br>Built on Radix for accessibility<br>Supports variants and sizes<br>Can be controlled or uncontrolled<br>Ideal for formatting and quick UI actions</p><p>Good UI design isn’t about adding switches everywhere — <br>it’s about giving users clear state feedback.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FQUENDfi6DEMLzQ0CKt%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExMHRpYmgxbW82ZDR4NzZuZDI5czV4c3RvYWtnajU0eGRuNW54ZnkxdyZlcD12MV9naWZzX3NlYXJjaCZjdD1n%2FQUENDfi6DEMLzQ0CKt%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExcXRydjIzdnFzdXFscmJwNnY3anNoeXR1azN1dmpldDJ4aHUzZG91aCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FQUENDfi6DEMLzQ0CKt%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac71357db127561b7bab53e93cd03094/href">https://medium.com/media/ac71357db127561b7bab53e93cd03094/href</a></iframe><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9QTaaaxboQP_gKSLedW_w.png" /></figure><p>👉 Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></p><p>👉 Follow us: <a href="https://www.linkedin.com/in/code-to-deploy-3784391b9/"><strong>Linkedin</strong></a>| <a href="https://medium.com/codetodeploy"><strong>Medium</strong></a></p><p>👉 CodeToDeploy Tech Community is live on Discord — <a href="https://discord.gg/ZpwhHq6D"><strong>Join now!</strong></a></p><p><strong>Note:</strong> This Post may contain affiliate links.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9972883676a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codetodeploy/shadcn-ui-react-series-part-27-toggle-controlling-binary-actions-with-precision-9972883676a6">[Shadcn/ui React Series — Part 27] Toggle: Controlling Binary Actions with Precision</a> was originally published in <a href="https://medium.com/codetodeploy">CodeToDeploy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>