Disabling the Tailwind input ring

If you’ve ever worked with Tailwind components or TailwindUI, you’ve probably come across the “focus ring”. On inputs (checkboxes, fields, etc.), this ring is shown when you’ve clicked or tabbed onto a component, indicating that you have selected it. H…


This content originally appeared on DEV Community and was authored by Roman Sorin

If you’ve ever worked with Tailwind components or TailwindUI, you’ve probably come across the “focus ring”. On inputs (checkboxes, fields, etc.), this ring is shown when you’ve clicked or tabbed onto a component, indicating that you have selected it. Here’s an example:

Enabled ring on checkbox

Disabling the ring

I’ve seen myself and others try to disable this by simply calling the focus:ring-0 utility. This sort of works, but gives us this weird shadowing effect on the corners of our input:

Disabled ring, but persistent offset

By default, Tailwind will include this ring and an offset on certain input elements like checkboxes. If you’d rather not have this ring on all interactions, you can easily disable it:

<input type="checkbox" className="focus:ring-0 focus:ring-offset-0" />

With this, we’re able to get a nice looking checkbox, without the “ugly” looking ring:

Fully disabled ring on a checked checkbox

Keeping things clean

To reduce redundancy across my project, I created a class that I can globally apply:

.without-ring {
  @apply focus:ring-0 focus:ring-offset-0;
}

Now, instead of re-defining these utilities on all of my inputs, I can use the without-ring class to achieve the desired output:

<input type="checkbox" className="without-ring" />

Keeping it accessible

Accessibility is important, but to keep it short, I won’t cover it here. Instead, this post by David Gilbertson provides a simple, framework-agnostic solution to showing the focus ring only when a user is tabbing and making it hidden otherwise.


This content originally appeared on DEV Community and was authored by Roman Sorin


Print Share Comment Cite Upload Translate Updates
APA

Roman Sorin | Sciencx (2022-02-01T13:30:57+00:00) Disabling the Tailwind input ring. Retrieved from https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/

MLA
" » Disabling the Tailwind input ring." Roman Sorin | Sciencx - Tuesday February 1, 2022, https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/
HARVARD
Roman Sorin | Sciencx Tuesday February 1, 2022 » Disabling the Tailwind input ring., viewed ,<https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/>
VANCOUVER
Roman Sorin | Sciencx - » Disabling the Tailwind input ring. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/
CHICAGO
" » Disabling the Tailwind input ring." Roman Sorin | Sciencx - Accessed . https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/
IEEE
" » Disabling the Tailwind input ring." Roman Sorin | Sciencx [Online]. Available: https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/. [Accessed: ]
rf:citation
» Disabling the Tailwind input ring | Roman Sorin | Sciencx | https://www.scien.cx/2022/02/01/disabling-the-tailwind-input-ring/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.