Skip to content

Commit 2779a67

Browse files
committed
Update README
1 parent 2626d3e commit 2779a67

File tree

1 file changed

+56
-22
lines changed

1 file changed

+56
-22
lines changed

README.md

+56-22
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,53 @@ module.exports = {
3131
}
3232
```
3333

34-
## Usage
34+
## Basic usage
3535

3636
[**View the live demo**](https://tailwindcss-forms.vercel.app/)
3737

3838
All of the basic form elements you use will now have some simple default styles that are easy to override with utilities.
3939

40-
There's currently two options you can choose in how we we add basic utility-friendly form styles:
40+
Currently we add basic utility-friendly form styles for the following form element types:
41+
42+
- `input[type='text']`
43+
- `input[type='password']`
44+
- `input[type='email']`
45+
- `input[type='number']`
46+
- `input[type='url']`
47+
- `input[type='date']`
48+
- `input[type='datetime-local']`
49+
- `input[type='month']`
50+
- `input[type='week']`
51+
- `input[type='time']`
52+
- `input[type='search']`
53+
- `input[type='tel']`
54+
- `input[type='checkbox']`
55+
- `input[type='radio']`
56+
- `select`
57+
- `select[multiple]`
58+
- `textarea`
59+
60+
**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.
4161

42-
- `base` - The default selector strategy
43-
- `class` - Requires a `form-` class to be applied to the form element in order for styles to be applied
62+
Every element has been normalized/reset to a simple visually consistent style that is easy to customize with utilities, even elements like `<select>` or `<input type="checkbox">` that normally need to be reset with `appearance: none` and customized using custom CSS:
63+
64+
```html
65+
<!-- You can actually customize padding on a select element now: -->
66+
<select class="px-4 py-3 rounded-full">
67+
<!-- ... -->
68+
</select>
69+
70+
<!-- Or change a checkbox color using text color utilities: -->
71+
<input type="checkbox" class="rounded text-pink-500" />
72+
```
73+
74+
More customization examples and best practices coming soon.
75+
76+
### Using classes instead of element selectors
77+
78+
Although we recommend thinking of this plugin as a "form reset" rather than a collection of form component styles, in some cases our default approach may be too heavy-handed, especially when integrating this plugin into existing projects.
79+
80+
For situations where the default strategy doesn't work well with your project, you can use the `class` strategy to make all form styling _opt-in_ instead of applied globally:
4481

4582
```js
4683
// tailwind.config.js
@@ -51,6 +88,20 @@ plugins: [
5188
],
5289
```
5390

91+
When using the `class` strategy, form elements do not receive any reset styles by default, and reset styles are added per element using a new set of `form-*` classes generated by the plugin:
92+
93+
```html
94+
<input type="email" class="form-input px-4 py-3 rounded-full">
95+
96+
<select class="form-select px-4 py-3 rounded-full">
97+
<!-- ... -->
98+
</select>
99+
100+
<input type="checkbox" class="form-checkbox rounded text-pink-500" />
101+
```
102+
103+
Here is a complete table of the provided `form-*` classes for reference:
104+
54105
| Base | Class |
55106
| ------------------------- | ------------------ |
56107
| `[type='text']` | `form-input` |
@@ -65,25 +116,8 @@ plugins: [
65116
| `[type='tel']` | `form-input` |
66117
| `[type='time']` | `form-input` |
67118
| `[type='week']` | `form-input` |
68-
| `[multiple]` | `form-multiselect` |
69119
| `textarea` | `form-textarea` |
70120
| `select` | `form-select` |
121+
| `select[multiple]` | `form-multiselect` |
71122
| `[type='checkbox']` | `form-checkbox` |
72123
| `[type='radio']` | `form-radio` |
73-
| `[type='file']` | `form-file` |
74-
75-
**Note that for text inputs, when using the default `base` strategy, 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.
76-
77-
Every element has been normalized/reset to a simple visually consistent style that is easy to customize with utilities, even elements like `<select>` or `<input type="checkbox">` that normally need to be reset with `appearance: none` and customized using custom CSS:
78-
79-
```html
80-
<!-- You can actually customize padding on a select element now: -->
81-
<select class="px-4 py-3 rounded-full">
82-
<!-- ... -->
83-
</select>
84-
85-
<!-- Or change a checkbox color using text color utilities: -->
86-
<input type="checkbox" class="rounded text-pink-500" />
87-
```
88-
89-
More customization examples and best practices coming soon.

0 commit comments

Comments
 (0)