Skip to content

Commit 48c723b

Browse files
ysdsmdo
authored andcommitted
Fix custom range thumb style (twbs#26385)
* Fix focus box shadow of custom ranges * Put `:focus` selector right after `.custom-range` * Remove unnecessary `outline: none` * Fix box-shadow issues in IE/Edge * Better align * Fix thumb vertical positions in IE/Edge * Fix incorrect formula of thumb vertical positions in Webkit * Fix an incorrect comment * Fix incorrect box-shadow-width
1 parent 0fd4083 commit 48c723b

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

scss/_custom-forms.scss

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@
320320

321321
&:focus {
322322
outline: none;
323+
324+
// Pseudo-elements must be split across multiple rulesets to have an affect.
325+
// No box-shadow() mixin for focus accessibility.
326+
&::-webkit-slider-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
327+
&::-moz-range-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
328+
&::-ms-thumb { box-shadow: $custom-range-thumb-focus-box-shadow; }
323329
}
324330

325331
&::-moz-focus-outer {
@@ -329,19 +335,14 @@
329335
&::-webkit-slider-thumb {
330336
width: $custom-range-thumb-width;
331337
height: $custom-range-thumb-height;
332-
margin-top: -($custom-range-thumb-width * .25); // Webkit specific?
338+
margin-top: (($custom-range-track-height - $custom-range-thumb-height) / 2); // Webkit specific
333339
@include gradient-bg($custom-range-thumb-bg);
334340
border: $custom-range-thumb-border;
335341
@include border-radius($custom-range-thumb-border-radius);
336342
@include box-shadow($custom-range-thumb-box-shadow);
337343
@include transition($custom-forms-transition);
338344
appearance: none;
339345

340-
&:focus {
341-
outline: none;
342-
box-shadow: $custom-range-thumb-focus-box-shadow; // No mixin for focus accessibility
343-
}
344-
345346
&:active {
346347
@include gradient-bg($custom-range-thumb-active-bg);
347348
}
@@ -368,11 +369,6 @@
368369
@include transition($custom-forms-transition);
369370
appearance: none;
370371

371-
&:focus {
372-
outline: none;
373-
box-shadow: $custom-range-thumb-focus-box-shadow; // No mixin for focus accessibility
374-
}
375-
376372
&:active {
377373
@include gradient-bg($custom-range-thumb-active-bg);
378374
}
@@ -392,18 +388,16 @@
392388
&::-ms-thumb {
393389
width: $custom-range-thumb-width;
394390
height: $custom-range-thumb-height;
391+
margin-top: 0; // Edge specific
392+
margin-right: $custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
393+
margin-left: $custom-range-thumb-focus-box-shadow-width; // Workaround that overflowed box-shadow is hidden.
395394
@include gradient-bg($custom-range-thumb-bg);
396395
border: $custom-range-thumb-border;
397396
@include border-radius($custom-range-thumb-border-radius);
398397
@include box-shadow($custom-range-thumb-box-shadow);
399398
@include transition($custom-forms-transition);
400399
appearance: none;
401400

402-
&:focus {
403-
outline: none;
404-
box-shadow: $custom-range-thumb-focus-box-shadow; // No mixin for focus accessibility
405-
}
406-
407401
&:active {
408402
@include gradient-bg($custom-range-thumb-active-bg);
409403
}

scss/_variables.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,15 @@ $custom-range-track-bg: $gray-300 !default;
537537
$custom-range-track-border-radius: 1rem !default;
538538
$custom-range-track-box-shadow: inset 0 .25rem .25rem rgba($black, .1) !default;
539539

540-
$custom-range-thumb-width: 1rem !default;
541-
$custom-range-thumb-height: $custom-range-thumb-width !default;
542-
$custom-range-thumb-bg: $component-active-bg !default;
543-
$custom-range-thumb-border: 0 !default;
544-
$custom-range-thumb-border-radius: 1rem !default;
545-
$custom-range-thumb-box-shadow: 0 .1rem .25rem rgba($black, .1) !default;
546-
$custom-range-thumb-focus-box-shadow: 0 0 0 1px $body-bg, $input-btn-focus-box-shadow !default;
547-
$custom-range-thumb-active-bg: lighten($component-active-bg, 35%) !default;
540+
$custom-range-thumb-width: 1rem !default;
541+
$custom-range-thumb-height: $custom-range-thumb-width !default;
542+
$custom-range-thumb-bg: $component-active-bg !default;
543+
$custom-range-thumb-border: 0 !default;
544+
$custom-range-thumb-border-radius: 1rem !default;
545+
$custom-range-thumb-box-shadow: 0 .1rem .25rem rgba($black, .1) !default;
546+
$custom-range-thumb-focus-box-shadow: 0 0 0 1px $body-bg, $input-btn-focus-box-shadow !default;
547+
$custom-range-thumb-focus-box-shadow-width: $input-btn-focus-width !default; // For focus box shadow issue in IE/Edge
548+
$custom-range-thumb-active-bg: lighten($component-active-bg, 35%) !default;
548549

549550
$custom-file-height: $input-height !default;
550551
$custom-file-height-inner: $input-height-inner !default;

0 commit comments

Comments
 (0)