Skip to content

Commit 5e0f2c0

Browse files
committed
Add FormField-select for controlling select elements
1 parent 6e337a2 commit 5e0f2c0

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Read more about [SUIT CSS](https://github.com/suitcss/suit/).
2323

2424
* `FormField` - Containing element. Apply state classes to this
2525
* `FormField-input` - Consistent rendering of various form inputs
26+
* `FormField-select` - Used for select elements only (instead of `FormField-input`)
2627
* `FormField-label` - Label text for the input
2728
* `FormField-text` - Used to display help text or validation messages
2829
* `FormField-check` - Wraps around `input` and `label` when using either radio
@@ -48,6 +49,21 @@ This works with other inputs such as `textarea`, `range` and `file`.
4849
</div>
4950
```
5051

52+
### Select elements
53+
54+
Select elements require their own class name to ensure consistent rendering in
55+
Blink/Webkit.
56+
57+
```html
58+
<div class="FormField">
59+
<label class="FormField-label" for="select">Select</label>
60+
<select class="FormField-select">
61+
<option>Some option</option>
62+
<option>Another option</option>
63+
</select>
64+
</div>
65+
```
66+
5167
### Using a `label` container
5268

5369
```html
@@ -154,6 +170,10 @@ The following achieves an inline form effect
154170
* `--FormField-text-fontSize`
155171
* `--FormField-text-marginTop`
156172

173+
#### `FormField-select`
174+
175+
* `--FormField-select-height`
176+
157177
#### `FormField-check`
158178

159179
* `--FormField-check-gutter` - Space between checkbox/radio and the label

lib/form-field.css

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
--FormField-text-fontSize: inherit;
2323
--FormField-text-marginTop: 0.25em;
2424

25+
--FormField-select-height: 30px;
26+
2527
--FormField-check-gutter: 0.5em;
2628

2729
/* States */
@@ -43,6 +45,7 @@
4345
margin-top: 0;
4446
}
4547

48+
.FormField-select,
4649
.FormField-input {
4750
background-color: #fff;
4851
border-color: var(--FormField-input-borderColor);
@@ -59,6 +62,15 @@
5962
width: 100%;
6063
}
6164

65+
/*
66+
* Control height manually on select elements as Webkit/Blink does not respect
67+
* padding values
68+
*/
69+
70+
.FormField-select:not([size]):not([multiple]) {
71+
height: var(--FormField-select-height);
72+
}
73+
6274
/*
6375
* Remove native search input styling
6476
*/
@@ -121,7 +133,8 @@
121133
* Validation states
122134
*/
123135

124-
.FormField.is-error .FormField-input {
136+
.FormField.is-error .FormField-input,
137+
.FormField.is-error .FormField-select {
125138
border-color: var(--FormField-onError-color);
126139
}
127140

@@ -130,7 +143,8 @@
130143
color: var(--FormField-onError-color);
131144
}
132145

133-
.FormField.is-warning .FormField-input {
146+
.FormField.is-warning .FormField-input,
147+
.FormField.is-warning .FormField-select {
134148
border-color: var(--FormField-onWarning-color);
135149
}
136150

@@ -139,7 +153,8 @@
139153
color: var(--FormField-onWarning-color);
140154
}
141155

142-
.FormField.is-success .FormField-input {
156+
.FormField.is-success .FormField-input,
157+
.FormField.is-success .FormField-select {
143158
border-color: var(--FormField-onSuccess-color);
144159
}
145160

test/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ <h3 class="Test-it">should render a label and input</h3>
3434
<input class="FormField-input" type="file" id="file">
3535
</div>
3636

37+
<div class="FormField">
38+
<label class="FormField-label" for="select">Select</label>
39+
<select class="FormField-select" id="select" name="select">
40+
<option value="a">Some option</option>
41+
<option value="b">Another option</option>
42+
</select>
43+
</div>
44+
45+
<div class="FormField">
46+
<label class="FormField-label" for="select-multi">Select multiple</label>
47+
<select class="FormField-select" size="6" multiple id="select-multi" name="multiple">
48+
<option value="American">American flamingo</option>
49+
<option value="Andean">Andean flamingo</option>
50+
<option value="Chilean">Chilean flamingo</option>
51+
<option value="Greater">Greater flamingo</option>
52+
<option value="James's">James's flamingo</option>
53+
<option value="Lesser">Lesser flamingo</option>
54+
</select>
55+
</div>
56+
3757
<div class="FormField">
3858
<label class="FormField-label" for="password">Password</label>
3959
<input class="FormField-input" type="password" id="password">

0 commit comments

Comments
 (0)