|
2 | 2 |
|
3 | 3 | A plugin that provides basic default form styles that are easy to override with utilities. Hopefully the successor to `@tailwindcss/custom-forms`.
|
4 | 4 |
|
5 |
| - |
6 | 5 | ## Installation
|
7 | 6 |
|
8 | 7 | Install the plugin from npm:
|
@@ -32,4 +31,57 @@ module.exports = {
|
32 | 31 |
|
33 | 32 | ## Usage
|
34 | 33 |
|
35 |
| -All of the basic form elements you use will now have some sensible default styles that are easy to override with utilities. Works basically like the `@tailwindcss/custom-forms` plugin in terms of how you modify things using utility classes. More details eventually. |
| 34 | +All of the basic form elements you use will now have some sensible default styles that are easy to override with utilities. |
| 35 | + |
| 36 | +Currently we add basic utility-friendly form styles for the following form element types: |
| 37 | + |
| 38 | +- `input[type='text']` |
| 39 | +- `input[type='password']` |
| 40 | +- `input[type='email']` |
| 41 | +- `input[type='number']` |
| 42 | +- `input[type='url']` |
| 43 | +- `input[type='date']` |
| 44 | +- `input[type='datetime-local']` |
| 45 | +- `input[type='month']` |
| 46 | +- `input[type='week']` |
| 47 | +- `input[type='time']` |
| 48 | +- `input[type='search']` |
| 49 | +- `input[type='tel']` |
| 50 | +- `input[type='checkbox']` |
| 51 | +- `input[type='radio']` |
| 52 | +- `select` |
| 53 | +- `select[multiple]` |
| 54 | +- `textarea` |
| 55 | + |
| 56 | +**Note that for text inputs, you must add the `type="text"` attribute for these styles to take effect.** This is a necessary trade-off to avoid relying on the overly greedy `input` selector and unintentionally styling elements we don't have solutions for yet, like `input[type="range"]` for example. |
| 57 | + |
| 58 | +Every element has been normalized/reset in a way that they look pretty great without doing anything to them at all: |
| 59 | + |
| 60 | +```html |
| 61 | +<!-- This just looks good! --> |
| 62 | +<input type="text"> |
| 63 | +``` |
| 64 | + |
| 65 | +The real benefit of this plugin however is that all of these elements are easy to modify on the fly with utilities, which is not possible with user agent form styles: |
| 66 | + |
| 67 | +```html |
| 68 | +<!-- You can customize padding on a select element! Oh my god! --> |
| 69 | +<select class="px-4 py-3 rounded-full"> |
| 70 | + <!-- ... --> |
| 71 | +</select> |
| 72 | +``` |
| 73 | + |
| 74 | +We've baked in a few useful tricks, like making the checkbox and radio controls use `currentColor` for their checked state, so you can even customize how those look using text color utilities: |
| 75 | + |
| 76 | +```html |
| 77 | +<!-- This will be blue when checked --> |
| 78 | +<input type="checkbox" class="text-blue-500"> |
| 79 | + |
| 80 | +<!-- This will be pink when checked --> |
| 81 | +<input type="checkbox" class="text-pink-500"> |
| 82 | + |
| 83 | +<!-- This will be green when checked --> |
| 84 | +<input type="checkbox" class="text-green-500"> |
| 85 | +``` |
| 86 | + |
| 87 | +More customization examples and best practices coming soon. |
0 commit comments