Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom range input #25600

Merged
merged 19 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/4.0/components/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,22 @@ As is the `size` attribute:
</select>
{% endexample %}

### Range

Create custom `<input type="range">` controls with `.custom-range`. The track (the background) and thumb (the value) are both styled to appear the same across browsers. As only IE and Firefox support "filling" their track from the left or right of the thumb as a means to visually indicate progress, we do not currently support it.

{% example html %}
<label for="customRange1">Example range</label>
<input type="range" class="custom-range" id="customRange1">
{% endexample %}

Range inputs have implicit values for `min` and `max`—`0` and `100`, respectively. You may specify new values for those using the `min` and `max` attributes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also include at the end:

By default, range inputs "snap" to integer values. To change this, you can specify a `step` value.

and then perhaps add step="0.5" to the following example? Or is that getting too specific?


{% example html %}
<label for="customRange2">Example range</label>
<input type="range" class="custom-range" min="0" max="5" id="customRange2">
{% endexample %}

### File browser

The file input is the most gnarly of the bunch and requires additional JavaScript if you'd like to hook them up with functional *Choose file...* and selected file name text.
Expand Down
117 changes: 117 additions & 0 deletions scss/_custom-forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,120 @@
@include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
}
}

// Range
//
// Style range inputs the same across browsers. Vendor-specific rules for psuedo
// elements cannot be mixed. As such, there are no shared styles for focus or
// active states on prefixed selectors.

.custom-range {
width: 100%;
padding-left: 0; // Firefox specific
background-color: transparent;
appearance: none;

&:focus {
outline: none;
}

&::-moz-focus-outer {
border: 0;
}

&::-webkit-slider-thumb {
width: $custom-control-indicator-size;
height: $custom-control-indicator-size;
margin-top: -($custom-control-indicator-size * .25);
background-color: $custom-control-indicator-checked-bg;
border: 0;
border-radius: $custom-control-indicator-size;
appearance: none;

&:focus {
outline: none;
box-shadow: $custom-control-indicator-focus-box-shadow;
}

&:active {
background-color: $custom-control-indicator-active-bg;
}
}

&::-webkit-slider-runnable-track {
width: 100%;
height: $custom-control-indicator-size * .5;
color: transparent;
cursor: pointer;
background-color: $custom-control-indicator-bg;
border-color: transparent;
border-radius: $custom-control-indicator-size;
}

&::-moz-range-thumb {
width: $custom-control-indicator-size;
height: $custom-control-indicator-size;
background-color: $custom-control-indicator-checked-bg;
border: 0;
border-radius: $custom-control-indicator-size;
appearance: none;

&:focus {
outline: none;
box-shadow: $custom-control-indicator-focus-box-shadow;
}

&:active {
background-color: $custom-control-indicator-active-bg;
}
}

&::-moz-range-track {
width: 100%;
height: $custom-control-indicator-size * .5;
color: transparent;
cursor: pointer;
background-color: $custom-control-indicator-bg;
border-color: transparent;
border-radius: $custom-control-indicator-size;
}

&::-ms-thumb {
width: $custom-control-indicator-size;
height: $custom-control-indicator-size;
background-color: $custom-control-indicator-checked-bg;
border: 0;
border-radius: $custom-control-indicator-size;
appearance: none;

&:focus {
outline: none;
box-shadow: $custom-control-indicator-focus-box-shadow;
}

&:active {
background-color: $custom-control-indicator-active-bg;
}
}

&::-ms-track {
width: 100%;
height: $custom-control-indicator-size * .5;
color: transparent;
cursor: pointer;
background-color: transparent;
border-color: transparent;
border-width: ($custom-control-indicator-size * .5);
}

&::-ms-fill-lower {
background-color: $custom-control-indicator-bg;
border-radius: $custom-control-indicator-size;
}

&::-ms-fill-upper {
margin-right: 15px;
background-color: $custom-control-indicator-bg;
border-radius: $custom-control-indicator-size;
}
}