question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(custom-range): Add support for input-group and validation

See original GitHub issue

Currently the .custom-range input does not support validation styling, nor is .custom-range supported inside .input-groups.

I suggest CSS similar to the following to handle both input-groups and validation

Basic validation:

.custom-range {
  border: 1px solid transparent;
  border-radius: .25rem;
}
/* leave above out to not have the non .input-group ranges
 * bordered when invalid or valid
 */

.custom-range.is-invalid,
.was-validated .custom-range:invalid {
  border-color: #dc3545;
}
.custom-range.is-invalid:focus,
.was-validated .custom-range:invalid:focus {
  border-color: #dc3545;
  box-shadow: 0 0 0 .2rem rgba(220,53,69,.25);
}
.custom-range.is-valid,
.was-validated .custom-range:valid {
  border-color: #28a745;
}
.custom-range.is-valid:focus,
.was-validated .custom-range:valid:focus {
  border-color: #28a745;
  box-shadow: 0 0 0 .2rem rgba(40,167,69,.25);
}

Input groups:

.input-group > .custom-range {
  display: block;
  height: calc(2.25rem + 2px);
  padding: 0 .75rem;
  font-size: 1rem;
  line-height: 1.5;
  background-clip: padding-box;
  border: 1px solid #ced4da;
  border-radius: .25rem;
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.input-group > .custom-range {
  position: relative;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  width: 1%;
  margin-bottom: 0;
}
.input-group > .custom-range:focus {
  z-index: 3;
}
.input-group-sm > .custom-range {
  height: calc(1.8125rem + 2px);
  padding: 0 .5rem;
  font-size: .875rem;
  line-height: 1.5;
  border-radius: .2rem;
}
.input-group-lg > .custom-range {
  height: calc(2.875rem + 2px);
  padding-left: 0 1rem;
  font-size: 1.25rem;
  line-height: 1.5;
  border-radius: .3rem;
}
.input-group > .custom-range:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.input-group > .custom-range:not(:first-child) {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/* Style for focusing custom-range when inside an .input-group.
 * Normally only the range thumb has focus styling, but this keeps
 * input-group inputs looking consistent during validation
 */
.input-group .custom-range:focus {
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(0,123,255,.25);
}

Results: image

An alternative to using the borders of .custom-range that is not inside an .input-group, would be to change the background color of the track (maybe use the .alert-danger and .alert-success background or border colors), and to color the range handle to match validation.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
ysdscommented, Nov 1, 2018

I understood about a scenario with server side validation. But I feel strange about the border around a slider control. I prefer without borders style.

2018-11-02 1 33 35

https://codepen.io/anon/pen/OBKGKY

1reaction
mdocommented, Nov 1, 2018

I’m a no on the input group—input groups were always designed for textual inputs first and foremost. In general I don’t see much usage of range inputs already, and putting them inside an input group feels premature at this point. I like the min/max demo, but not enough to see it added 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

InputGroup - React-Bootstrap
InputGroup. Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file...
Read more >
Input group · Bootstrap v5.0
Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs....
Read more >
Bootstrap Input group - examples & tutorial
Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs....
Read more >
Bootstrap 3 form using input-group-addon wrapping error ...
As the error label is added dynamically by the jQuery Validate plugin, this solution does not help. – Debiprasad. Jul 26, 2017 at...
Read more >
Bootstrap 4 Form Input Group - W3Schools
The .input-group class is a container to enhance an input by adding an icon, text or a button in front or behind the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found