Skip to content

Commit 75b83df

Browse files
author
Aaron Shekey
committed
Merge pull request #132 from primer/error-states
Inline error state styling
2 parents c9165b9 + 175f09a commit 75b83df

File tree

3 files changed

+98
-47
lines changed

3 files changed

+98
-47
lines changed

docs/docs.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,22 @@ body {
296296
dl.form {
297297
margin: 15px 0;
298298

299+
&:first-child {
300+
margin-top: 0;
301+
}
302+
303+
&:last-child {
304+
margin-bottom: 0;
305+
}
306+
299307
> dt {
300308
margin: 0 0 6px;
301309
font-style: normal;
302310
}
303311

304312
> dd {
305313
padding: 0;
314+
margin-bottom: 0;
306315
}
307316
}
308317

docs/forms.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,26 @@ Use the `.select-sm` class to resize both default and custom `<select>`s to matc
175175
</form>
176176
{% endexample %}
177177

178+
## Form group validation
179+
180+
Convey errors and warnings for form groups. Add the appropriate class—either `.errored` or `.warn`—to the `<dl class="form">` to start. Then, house your error messaging in an additional `<dd>` with either `.error` or `.warning`.
181+
182+
{% example html %}
183+
<form>
184+
<dl class="form errored">
185+
<dt><label>Example Text</label></dt>
186+
<dd><input type="text" value="Example Value"></dd>
187+
<dd class="error">This example input has an error.</dd>
188+
</dl>
189+
<br>
190+
<dl class="form warn">
191+
<dt><label>Example Text</label></dt>
192+
<dd><input type="text" value="Example Value"></dd>
193+
<dd class="warning">This example input has a warning.</dd>
194+
</dl>
195+
</form>
196+
{% endexample %}
197+
178198
## Checkboxes and radios
179199

180200
Utilities to spice up the alignment and styling of checkbox and radio controls.

scss/_forms.scss

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ textarea {
2929
vertical-align: middle;
3030
background-color: #fff;
3131
background-repeat: no-repeat; // Repeat and position set for form states (success, error, etc)
32-
background-position: right center;
32+
background-position: right 8px center; // For form validation. This keeps images 8px from right and centered vertically.
3333
border: 1px solid #ccc;
3434
border-radius: 3px;
3535
outline: none;
@@ -140,7 +140,6 @@ dl.form {
140140
width: 440px;
141141
max-width: 100%;
142142
margin-right: 5px;
143-
background-position-x: 98%;
144143
}
145144

146145
input {
@@ -220,64 +219,87 @@ dl.form {
220219
}
221220
}
222221

222+
// Form validation
223+
//
224+
// Our inline errors
225+
226+
&.warn,
223227
&.errored {
224-
> dt label {
225-
color: #900;
228+
dd.warning,
229+
dd.error {
230+
display: inline-block;
231+
position: absolute;
232+
max-width: 450px; // Keep our long errors readable
233+
z-index: 10;
234+
margin: 2px 0 0;
235+
padding: 5px 8px;
236+
font-size: 13px;
237+
font-weight: normal;
238+
border-radius: 3px;
226239
}
227240

228-
// General text next to the field
229-
.error {
230-
display: inline;
231-
color: #900;
241+
dd.warning:after,
242+
dd.warning:before,
243+
dd.error:after,
244+
dd.error:before {
245+
bottom: 100%;
246+
z-index: 15;
247+
left: 10px;
248+
border: solid transparent;
249+
content: " ";
250+
height: 0;
251+
width: 0;
252+
position: absolute;
253+
pointer-events: none;
232254
}
233255

234-
// Specific error explanations from the server
235-
dd.error,
236-
dd.warning {
237-
display: inline-block;
238-
padding: 5px;
239-
font-size: 11px;
240-
color: #494620;
241-
background: #f7ea57;
242-
border: 1px solid #c0b536;
243-
border-top-color: #fff;
244-
border-bottom-right-radius: 3px;
245-
border-bottom-left-radius: 3px;
256+
dd.warning:after,
257+
dd.error:after {
258+
border-width: 5px;
246259
}
247-
}
248260

249-
&.warn {
250-
// General text next to the field
251-
.warning {
252-
display: inline;
253-
color: #900;
261+
dd.warning:before,
262+
dd.error:before {
263+
border-width: 6px;
264+
margin-left: -1px;
254265
}
266+
}
255267

256-
// Specific warning explanations from the server
268+
&.warn {
257269
dd.warning {
258-
display: inline-block;
259-
padding: 5px;
260-
font-size: 11px;
261-
color: #494620;
262-
background: #f7ea57;
263-
border: 1px solid #c0b536;
264-
border-top-color: #fff;
265-
border-bottom-right-radius: 3px;
266-
border-bottom-left-radius: 3px;
270+
color: #4e401e;
271+
background-color: #ffe5a7;
272+
border: 1px solid #e7ce94;
273+
274+
&:after {
275+
border-bottom-color: #ffe5a7;
276+
}
277+
278+
&:before {
279+
border-bottom-color: #cdb683;
280+
}
267281
}
268282
}
269283

270-
.form-note {
271-
display: inline-block;
272-
padding: 5px;
273-
margin-top: -1px;
274-
font-size: 11px;
275-
color: #494620;
276-
background: #f7ea57;
277-
border: 1px solid #c0b536;
278-
border-top-color: #fff;
279-
border-bottom-right-radius: 3px;
280-
border-bottom-left-radius: 3px;
284+
&.errored {
285+
> dt label {
286+
color: $brand-red;
287+
}
288+
289+
dd.error {
290+
color: #fff;
291+
background-color: #bf1515;
292+
border-color: #911;
293+
font-size: 13px;
294+
295+
&:after {
296+
border-bottom-color: #bf1515;
297+
}
298+
299+
&:before {
300+
border-bottom-color: #911;
301+
}
302+
}
281303
}
282304
}
283305

0 commit comments

Comments
 (0)