Files
shoelace/source/docs/forms.md
2017-08-08 17:41:40 -04:00

8.8 KiB
Raw Blame History

layout, title, description
layout title description
default.html Forms Default form control styles.

Forms

Shoelace gives you beautiful forms without hassle. Most form controls dont need a special class for styling.

Form Controls

Form controls are styled at 100% of the width of their parent element.

Input Type Example
<input type="checkbox"> Checkbox 1
Checkbox 2
<input type="color">
<input type="date">
<input type="email">
<input type="file">
File inputs arent supported. Use a file button instead.
Select File
<input type="number">
<input type="password">
<input type="radio"> Radio 1
Radio 2
<input type="range">
<input type="search">
<input type="text">
<input type="time">
<progress></progress>
<select> Item 1 Item 2 Item 3
<textarea>

You can change the size of most form controls with the input-small and input-big modifiers.

<input type="text" class="input-small" placeholder="Small">
<input type="text" placeholder="Default">
<input type="text" class="input-big" placeholder="Big">

<select class="input-small"><option>Item</option></select>
<select><option>Item</option></select>
<select class="input-big"><option>Item</option></select>

Item

Item

Item

Disabled form controls look like this:

Checkbox Radio

Read-only form controls look like this:

Form Control Spacing

For proper spacing of individual form controls, wrap them in input-single containers.

<div class="input-single">
  <label>Name</label>
  <input type="text">
</div>

<div class="input-single">
  <label>Password</label>
  <input type="password">
</div>

<div class="input-single">
  <label><input type="checkbox"> Remember me</label>
</div>
Username
Password
Remember me

Input Groups

Form controls and buttons can be grouped by wrapping them in input-group containers.

<div class="input-group">
  <input type="text">
  <button type="button" class="button">Submit</button>
</div>

<div class="input-group">
  <button type="button" class="button">Submit</button>
  <input type="text">
</div>

<div class="input-group">
  <input type="text" placeholder="First">
  <input type="text" placeholder="Middle">
  <input type="text" placeholder="Last">
  <button type="button" class="button">Submit</button>
</div>

<div class="input-group">
  <button type="button" class="button">Option 1</button>
  <button type="button" class="button">Option 2</button>
  <button type="button" class="button">Option 3</button>
</div>
Submit
Submit
Submit
Option 1 Option 2 Option 3

Input Addons

To create an input addon, use <span class="input-addon">. Addons can appear anywhere inside an input group. Use the input-addon-small and input-addon-big modifiers to change the size to match adjacent form controls.

<div class="input-group">
  <span class="input-addon input-addon-small">$</span>
  <input type="text" class="input-small">
  <span class="input-addon input-addon-small">.00</span>
</div>

<div class="input-group">
  <span class="input-addon">$</span>
  <input type="text">
  <span class="input-addon">.00</span>
</div>

<div class="input-group">
  <span class="input-addon input-addon-big">$</span>
  <input type="text" class="input-big">
  <span class="input-addon input-addon-big">.00</span>
</div>
$ .00
$ .00
$ .00

Form Groups

Related form controls can be grouped in a <fieldset>. An optional <legend> can be used to display a name for the group.

<fieldset>
  <legend>User</legend>
  ...
</fieldset>
Login
Username
Password
Remember me
Login

Validation

Form controls can be made valid or invalid using the input-valid and input-invalid modifiers. Its better to apply modifiers to the surrounding input-single so labels will be styled as well, but modifiers can be applied directly to form controls as needed.

<div class="input-single input-valid">
  <label>Valid</label>
  <input type="text">
</div>

<div class="input-single input-invalid">
  <label>Invalid</label>
  <input type="text">
</div>
Valid
Invalid