Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit ae9e311

Browse files
committed
Update form inputs to new design
Add JS to float form labels above placeholder text
1 parent 527fee7 commit ae9e311

2 files changed

Lines changed: 75 additions & 16 deletions

File tree

src/forms/Inputs.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @overview A module that sets up form input behaviors and visual states
3+
* @module Inputs.js
4+
*/
5+
6+
export const Inputs = {
7+
8+
/**
9+
* Query DOM for form fields and setup their behaviors
10+
* @returns {void}
11+
*/
12+
init() {
13+
this.formFields = document.querySelectorAll(`.form-field`);
14+
this.setupFloatLabels();
15+
},
16+
17+
/**
18+
* Add event listeners to all form fields to float input labels above the
19+
* content when text is entered
20+
* @returns {void}
21+
*/
22+
setupFloatLabels() {
23+
[...this.formFields].forEach((el) => {
24+
const input = el.querySelector(`.form-input`);
25+
const checkForInput = () => {
26+
if (input.value) {
27+
el.classList.add(`has-text`);
28+
} else {
29+
el.classList.remove(`has-text`);
30+
}
31+
};
32+
33+
input.addEventListener(`keyup`, checkForInput);
34+
checkForInput();
35+
});
36+
},
37+
};

src/forms/_base.scss

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ input {
9191
line-height: 1;
9292
}
9393

94+
::placeholder {
95+
color: color(text);
96+
}
97+
9498
// Get rid of number dropdown "spinners" for an overwhelming amount of browsers
9599
input[type=number]::-webkit-inner-spin-button,
96100
input[type=number]::-webkit-outer-spin-button {
@@ -120,12 +124,6 @@ input[type="number"] {
120124
appearance: textfield;
121125
}
122126

123-
input[type="radio"] {
124-
-webkit-appearance: radio;
125-
border-radius: 50%;
126-
border: 1px solid gray;
127-
}
128-
129127
select {
130128
outline: 0;
131129
box-shadow: 0;
@@ -209,6 +207,7 @@ select {
209207
}
210208

211209
.form-field {
210+
position: relative;
212211
margin-bottom: 25px;
213212
}
214213

@@ -228,11 +227,22 @@ select {
228227

229228

230229
.form-label {
231-
@extend %headers;
232-
233-
@extend %h4;
234-
235-
display: block;
230+
position: absolute;
231+
top: ms(-4);
232+
left: 1.1rem;
233+
font-size: ms(-2);
234+
line-height: 1;
235+
color: color(text);
236+
opacity: 0;
237+
pointer-events: none;
238+
transform: translateY(ms(-9));
239+
transition: transform 0.25s ease-out, opacity 0.25s ease-out;
240+
241+
.has-text & {
242+
transform: translateY(0);
243+
opacity: 1;
244+
pointer-events: auto;
245+
}
236246
}
237247

238248

@@ -250,18 +260,19 @@ select {
250260

251261
.form-input {
252262
@extend %body--sans-small;
253-
263+
appearance: none;
254264
width: 100%;
255-
border: 1px solid color(border);
265+
border: 1px solid color(dark-border);
256266
margin: 0;
257-
padding: size(smaller) size(small);
258-
color: color(dark-text);
267+
padding: 0.85rem ms(0) 0.85rem;
268+
color: color(text);
259269
border-radius: size(normal-corners);
260270
background: color(background);
261271
cursor: auto;
272+
transition: padding 0.25s ease-out;
262273

263274
&:focus {
264-
border-color: color(gray--light3);
275+
border-color: color(primary);
265276
}
266277

267278
// these are for jquery validation plugin
@@ -270,6 +281,17 @@ select {
270281
&.error {
271282
border-color: color(accent);
272283
}
284+
285+
.has-text & {
286+
padding: 1.2rem ms(0) 0.5rem;
287+
}
288+
}
289+
290+
.form-input--textarea {
291+
292+
#{$focus} {
293+
outline: 0;
294+
}
273295
}
274296

275297
.form-input--select {

0 commit comments

Comments
 (0)