diff --git a/dist/css/ionic.css b/dist/css/ionic.css index cb2aa5558a..1b112b6137 100644 --- a/dist/css/ionic.css +++ b/dist/css/ionic.css @@ -3911,31 +3911,27 @@ input[type="checkbox"][readonly] { position: relative; display: inline-block; } -.toggle input[type="checkbox"] { - /* set the actual checkbox input to have a width/height */ - /* but hide its appearance, then use :after to style it */ +/* hide the actual input checkbox */ +.toggle input { + display: none; } + +/* the track appearance when the toggle is "off" */ +.toggle .track { + display: inline-block; + box-sizing: border-box; width: 54px; height: 32px; - border: 0; - background: transparent; - -webkit-appearance: none; - /* the track appearance when the toggle is "off" */ } - .toggle input[type="checkbox"]:after { - display: inline-block; - box-sizing: border-box; - width: 100%; - height: 100%; - border: solid 2px #e5e5e5; - border-radius: 20px; - background-color: #e5e5e5; - content: ' '; - cursor: pointer; - transition-timing-function: ease-in-out; - transition-duration: 0.1s; - transition-property: background-color, border; } + border: solid 2px #e5e5e5; + border-radius: 20px; + background-color: #e5e5e5; + content: ' '; + cursor: pointer; + transition-timing-function: ease-in-out; + transition-duration: 0.1s; + transition-property: background-color, border; } /* the handle (circle) thats inside the toggle's track area */ -/* also the appearance when the handle is "off" */ +/* also the handle's appearance when it is "off" */ .toggle .handle { position: absolute; top: 2px; @@ -3945,25 +3941,26 @@ input[type="checkbox"][readonly] { height: 28px; border-radius: 50%; background-color: white; - transition: -webkit-transform 0.1s ease-in-out; + -webkit-transition: 0.1s ease-in-out; + transition: 0.1s ease-in-out; /* used to create a larger (but hidden) hit area to slide the handle */ } .toggle .handle:before { position: absolute; - top: -2px; - left: -16px; - display: table; - padding: 17px 30px; + top: -4px; + left: -22px; + padding: 19px 35px; content: " "; } -/* The track when the toggle is "on" */ -.toggle input:checked:after { +/* the track when the toggle is "on" */ +.toggle input:checked + .track { border-color: #4a87ee; background-color: #4a87ee; } /* the handle when the toggle is "on" */ -.toggle input:checked + .handle { - background-color: white; - -webkit-transform: translate3d(22px, 0, 0); } +.toggle input:checked + .track .handle { + -webkit-transform: translate(22px, 0); + transform: translate(22px, 0); + background-color: white; } /* make sure list item content have enough padding on right to fit the toggle */ .item-toggle .item-content { diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index 92040907e2..1c8c3215d1 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -1351,7 +1351,7 @@ angular.module('ionic.ui.toggle', []) replace: true, require: '?ngModel', scope: true, - template: '
', + template: '
', link: function($scope, $element, $attr, ngModel) { var checkbox, handle; diff --git a/js/ext/angular/src/directive/ionicToggle.js b/js/ext/angular/src/directive/ionicToggle.js index 4cf7831fff..809bf08a02 100644 --- a/js/ext/angular/src/directive/ionicToggle.js +++ b/js/ext/angular/src/directive/ionicToggle.js @@ -8,7 +8,7 @@ angular.module('ionic.ui.toggle', []) replace: true, require: '?ngModel', scope: true, - template: '
', + template: '
', link: function($scope, $element, $attr, ngModel) { var checkbox, handle; diff --git a/scss/_mixins.scss b/scss/_mixins.scss index 5649a0617d..a1a21ab97a 100644 --- a/scss/_mixins.scss +++ b/scss/_mixins.scss @@ -197,6 +197,13 @@ // CSS3 PROPERTIES // -------------------------------------------------- +// Appearance +@mixin appearance($val) { + -webkit-appearance: $val; + -moz-appearance: $val; + appearance: $val; +} + // Border Radius @mixin border-radius($radius) { -webkit-border-radius: $radius; diff --git a/scss/_toggle.scss b/scss/_toggle.scss index dc659ae9cd..96672337a2 100644 --- a/scss/_toggle.scss +++ b/scss/_toggle.scss @@ -8,35 +8,30 @@ display: inline-block; } -.toggle input[type="checkbox"] { - /* set the actual checkbox input to have a width/height */ - /* but hide its appearance, then use :after to style it */ +/* hide the actual input checkbox */ +.toggle input { + display: none; +} + +/* the track appearance when the toggle is "off" */ +.toggle .track { + display: inline-block; + box-sizing: border-box; width: $toggle-width; height: $toggle-height; - border: 0; - background: transparent; - -webkit-appearance: none; + border: solid $toggle-border-width $toggle-off-border-color; + border-radius: $toggle-border-radius; + background-color: $toggle-off-bg-color; + content: ' '; + cursor: pointer; - /* the track appearance when the toggle is "off" */ - &:after { - display: inline-block; - box-sizing: border-box; - width: 100%; - height: 100%; - border: solid $toggle-border-width $toggle-off-border-color; - border-radius: $toggle-border-radius; - background-color: $toggle-off-bg-color; - content: ' '; - cursor: pointer; - - transition-timing-function: ease-in-out; - transition-duration: $toggle-transition-duration; - transition-property: background-color, border; - } + transition-timing-function: ease-in-out; + transition-duration: $toggle-transition-duration; + transition-property: background-color, border; } /* the handle (circle) thats inside the toggle's track area */ -/* also the appearance when the handle is "off" */ +/* also the handle's appearance when it is "off" */ .toggle .handle { position: absolute; top: $toggle-border-width; @@ -46,29 +41,28 @@ height: $toggle-handle-height; border-radius: $toggle-handle-radius; background-color: $toggle-handle-off-bg-color; - transition: -webkit-transform $toggle-transition-duration ease-in-out; + @include transition($toggle-transition-duration ease-in-out); /* used to create a larger (but hidden) hit area to slide the handle */ &:before { position: absolute; - top: -2px; - left: ( ($toggle-handle-width / 2) * -1) - 2; - display: table; - padding: ($toggle-handle-height / 2) + 3 ($toggle-handle-width + 2); + top: -4px; + left: ( ($toggle-handle-width / 2) * -1) - 8; + padding: ($toggle-handle-height / 2) + 5 ($toggle-handle-width + 7); content: " "; } } -/* The track when the toggle is "on" */ -.toggle input:checked:after { +/* the track when the toggle is "on" */ +.toggle input:checked + .track { border-color: $toggle-on-border-color; background-color: $toggle-on-bg-color; } /* the handle when the toggle is "on" */ -.toggle input:checked + .handle { +.toggle input:checked + .track .handle { + @include translate($toggle-width - $toggle-handle-width - ($toggle-border-width * 2), 0); background-color: $toggle-handle-on-bg-color; - -webkit-transform: translate3d( $toggle-width - $toggle-handle-width - ($toggle-border-width * 2) ,0,0); } /* make sure list item content have enough padding on right to fit the toggle */ diff --git a/test/input-toggle.html b/test/input-toggle.html index a4bba7a002..81c845da8c 100644 --- a/test/input-toggle.html +++ b/test/input-toggle.html @@ -22,7 +22,9 @@