From 2255f479177ae869b2fb29bb259170e963ef744c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Alcaraz=20Mart=C3=ADnez?= Date: Sun, 17 Jul 2022 12:24:36 +0200 Subject: [PATCH] feat: Toggles focusable from the keyboard - By default tabindex is set to 0 - The tabindex attribute of the checkbox is propagated to the toggle Refs: Closes palcarazm/bootstrap5-toggle#38 --- js/bootstrap5-toggle.ecmas.js | 3 +++ js/bootstrap5-toggle.ecmas.min.js | 2 +- js/bootstrap5-toggle.ecmas.min.js.map | 2 +- js/bootstrap5-toggle.js | 7 +++++-- js/bootstrap5-toggle.min.js | 2 +- js/bootstrap5-toggle.min.js.map | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/js/bootstrap5-toggle.ecmas.js b/js/bootstrap5-toggle.ecmas.js index b86502a..fc167c9 100644 --- a/js/bootstrap5-toggle.ecmas.js +++ b/js/bootstrap5-toggle.ecmas.js @@ -26,6 +26,7 @@ style: '', width: null, height: null, + tabindex: 0 }; options = options || {}; @@ -42,6 +43,7 @@ style: this.element.getAttribute('data-style') || options.style || DEFAULTS.style, width: this.element.getAttribute('data-width') || options.width || DEFAULTS.width, height: this.element.getAttribute('data-height') || options.height || DEFAULTS.height, + tabindex: this.element.getAttribute('tabindex') || options.tabindex || DEFAULTS.tabindex, }; // LAST: Render Toggle @@ -105,6 +107,7 @@ let ecmasToggle = document.createElement('div'); ecmasToggle.setAttribute('class', 'toggle btn'); ecmasToggle.classList.add(this.element.checked ? 'btn-' + this.options.onstyle : 'btn-' + this.options.offstyle); + ecmasToggle.setAttribute('tabindex',this.options.tabindex); if (!this.element.checked) ecmasToggle.classList.add('off'); if (this.options.size) ecmasToggle.classList.add(size); if (this.options.style) { diff --git a/js/bootstrap5-toggle.ecmas.min.js b/js/bootstrap5-toggle.ecmas.min.js index b7e2299..9870cfc 100644 --- a/js/bootstrap5-toggle.ecmas.min.js +++ b/js/bootstrap5-toggle.ecmas.min.js @@ -8,5 +8,5 @@ * @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE */ -"use strict";!function(){class i{constructor(e,t){const s="On",i="primary",l="Off",o="secondary",n="",a="",d=null,h=null;t=t||{},this.element=e,this.options={on:this.element.getAttribute("data-on")||t.on||s,onstyle:this.element.getAttribute("data-onstyle")||t.onstyle||i,off:this.element.getAttribute("data-off")||t.off||l,offstyle:this.element.getAttribute("data-offstyle")||t.offstyle||o,size:this.element.getAttribute("data-size")||t.size||n,style:this.element.getAttribute("data-style")||t.style||a,width:this.element.getAttribute("data-width")||t.width||d,height:this.element.getAttribute("data-height")||t.height||h},this.render()}render(){function e(e){var t=window.getComputedStyle(e),e=e.offsetHeight,s=parseFloat(t.borderTopWidth);return e-parseFloat(t.borderBottomWidth)-s-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)}let t;switch(this.options.size){case"large":case"lg":t="btn-lg";break;case"small":case"sm":t="btn-sm";break;case"mini":case"xs":t="btn-xs";break;default:t=""}let s=document.createElement("label"),i=(s.setAttribute("class","btn btn-"+this.options.onstyle+" "+t),s.setAttribute("for",this.element.id),s.innerHTML=this.options.on,document.createElement("label")),l=(i.setAttribute("class","btn btn-"+this.options.offstyle+" "+t),i.setAttribute("for",this.element.id),i.innerHTML=this.options.off,document.createElement("span")),o=(l.setAttribute("class","toggle-handle btn "+t),document.createElement("div")),n=(o.setAttribute("class","toggle-group"),o.appendChild(s),o.appendChild(i),o.appendChild(l),document.createElement("div"));n.setAttribute("class","toggle btn"),n.classList.add(this.element.checked?"btn-"+this.options.onstyle:"btn-"+this.options.offstyle),this.element.checked||n.classList.add("off"),this.options.size&&n.classList.add(t),this.options.style&&this.options.style.split(" ").forEach(e=>{n.classList.add(e)}),(this.element.disabled||this.element.readOnly)&&(n.classList.add("disabled"),n.setAttribute("disabled","disabled")),this.element.parentElement.insertBefore(n,this.element),n.appendChild(this.element),n.appendChild(o),n.style.width=(this.options.width||Math.max(s.getBoundingClientRect().width,i.getBoundingClientRect().width)+l.getBoundingClientRect().width/2)+"px",n.style.height=(this.options.height||Math.max(s.getBoundingClientRect().height,i.getBoundingClientRect().height))+"px",s.classList.add("toggle-on"),i.classList.add("toggle-off"),this.options.height&&(s.style.lineHeight=e(s)+"px",i.style.lineHeight=e(i)+"px"),n.addEventListener("touchstart",e=>{this.toggle(),e.preventDefault()}),n.addEventListener("click",e=>{this.toggle(),e.preventDefault()}),this.ecmasToggle=n,this.element.bsToggle=this}toggle(e=!1){this.element.checked?this.off(e):this.on(e)}on(e=!1){if(this.element.disabled||this.element.readOnly)return!1;this.ecmasToggle.classList.remove("btn-"+this.options.offstyle),this.ecmasToggle.classList.add("btn-"+this.options.onstyle),this.ecmasToggle.classList.remove("off"),this.element.checked=!0,e||this.trigger()}off(e=!1){if(this.element.disabled||this.element.readOnly)return!1;this.ecmasToggle.classList.remove("btn-"+this.options.onstyle),this.ecmasToggle.classList.add("btn-"+this.options.offstyle),this.ecmasToggle.classList.add("off"),this.element.checked=!1,e||this.trigger()}enable(){this.ecmasToggle.classList.remove("disabled"),this.ecmasToggle.removeAttribute("disabled"),this.element.removeAttribute("disabled"),this.element.removeAttribute("readonly")}disable(){this.ecmasToggle.classList.add("disabled"),this.ecmasToggle.setAttribute("disabled",""),this.element.setAttribute("disabled",""),this.element.removeAttribute("readonly")}readonly(){this.ecmasToggle.classList.add("disabled"),this.ecmasToggle.setAttribute("disabled",""),this.element.removeAttribute("disabled"),this.element.setAttribute("readonly","")}update(e){this.element.disabled?this.disable():this.element.readOnly?this.readonly():this.enable(),this.element.checked?this.on(e):this.off(e)}trigger(e){e||this.element.dispatchEvent(new Event("change",{bubbles:!0}))}destroy(){this.ecmasToggle.parentNode.insertBefore(this.element,this.ecmasToggle),this.ecmasToggle.parentNode.removeChild(this.ecmasToggle),delete this.element.bsToggle,delete this.ecmasToggle}}Element.prototype.bootstrapToggle=function(e,t){let s=this.bsToggle||new i(this,e);e&&"string"==typeof e&&("toggle"==e.toLowerCase()?s.toggle(t):"on"==e.toLowerCase()?s.on(t):"off"==e.toLowerCase()?s.off(t):"enable"==e.toLowerCase()?s.enable():"disable"==e.toLowerCase()?s.disable():"readonly"==e.toLowerCase()?s.readonly():"destroy"==e.toLowerCase()&&s.destroy())},"undefined"!=typeof window&&(window.onload=function(){document.querySelectorAll('input[type=checkbox][data-toggle="toggle"]').forEach(function(e){e.bootstrapToggle()})}),"undefined"!=typeof module&&module.exports&&(module.exports=i)}(); +"use strict";!function(){class i{constructor(e,t){const s="On",i="primary",l="Off",o="secondary",n="",a="",d=null,h=null,r=0;t=t||{},this.element=e,this.options={on:this.element.getAttribute("data-on")||t.on||s,onstyle:this.element.getAttribute("data-onstyle")||t.onstyle||i,off:this.element.getAttribute("data-off")||t.off||l,offstyle:this.element.getAttribute("data-offstyle")||t.offstyle||o,size:this.element.getAttribute("data-size")||t.size||n,style:this.element.getAttribute("data-style")||t.style||a,width:this.element.getAttribute("data-width")||t.width||d,height:this.element.getAttribute("data-height")||t.height||h,tabindex:this.element.getAttribute("tabindex")||t.tabindex||r},this.render()}render(){function e(e){var t=window.getComputedStyle(e),e=e.offsetHeight,s=parseFloat(t.borderTopWidth);return e-parseFloat(t.borderBottomWidth)-s-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)}let t;switch(this.options.size){case"large":case"lg":t="btn-lg";break;case"small":case"sm":t="btn-sm";break;case"mini":case"xs":t="btn-xs";break;default:t=""}let s=document.createElement("label"),i=(s.setAttribute("class","btn btn-"+this.options.onstyle+" "+t),s.setAttribute("for",this.element.id),s.innerHTML=this.options.on,document.createElement("label")),l=(i.setAttribute("class","btn btn-"+this.options.offstyle+" "+t),i.setAttribute("for",this.element.id),i.innerHTML=this.options.off,document.createElement("span")),o=(l.setAttribute("class","toggle-handle btn "+t),document.createElement("div")),n=(o.setAttribute("class","toggle-group"),o.appendChild(s),o.appendChild(i),o.appendChild(l),document.createElement("div"));n.setAttribute("class","toggle btn"),n.classList.add(this.element.checked?"btn-"+this.options.onstyle:"btn-"+this.options.offstyle),n.setAttribute("tabindex",this.options.tabindex),this.element.checked||n.classList.add("off"),this.options.size&&n.classList.add(t),this.options.style&&this.options.style.split(" ").forEach(e=>{n.classList.add(e)}),(this.element.disabled||this.element.readOnly)&&(n.classList.add("disabled"),n.setAttribute("disabled","disabled")),this.element.parentElement.insertBefore(n,this.element),n.appendChild(this.element),n.appendChild(o),n.style.width=(this.options.width||Math.max(s.getBoundingClientRect().width,i.getBoundingClientRect().width)+l.getBoundingClientRect().width/2)+"px",n.style.height=(this.options.height||Math.max(s.getBoundingClientRect().height,i.getBoundingClientRect().height))+"px",s.classList.add("toggle-on"),i.classList.add("toggle-off"),this.options.height&&(s.style.lineHeight=e(s)+"px",i.style.lineHeight=e(i)+"px"),n.addEventListener("touchstart",e=>{this.toggle(),e.preventDefault()}),n.addEventListener("click",e=>{this.toggle(),e.preventDefault()}),this.ecmasToggle=n,this.element.bsToggle=this}toggle(e=!1){this.element.checked?this.off(e):this.on(e)}on(e=!1){if(this.element.disabled||this.element.readOnly)return!1;this.ecmasToggle.classList.remove("btn-"+this.options.offstyle),this.ecmasToggle.classList.add("btn-"+this.options.onstyle),this.ecmasToggle.classList.remove("off"),this.element.checked=!0,e||this.trigger()}off(e=!1){if(this.element.disabled||this.element.readOnly)return!1;this.ecmasToggle.classList.remove("btn-"+this.options.onstyle),this.ecmasToggle.classList.add("btn-"+this.options.offstyle),this.ecmasToggle.classList.add("off"),this.element.checked=!1,e||this.trigger()}enable(){this.ecmasToggle.classList.remove("disabled"),this.ecmasToggle.removeAttribute("disabled"),this.element.removeAttribute("disabled"),this.element.removeAttribute("readonly")}disable(){this.ecmasToggle.classList.add("disabled"),this.ecmasToggle.setAttribute("disabled",""),this.element.setAttribute("disabled",""),this.element.removeAttribute("readonly")}readonly(){this.ecmasToggle.classList.add("disabled"),this.ecmasToggle.setAttribute("disabled",""),this.element.removeAttribute("disabled"),this.element.setAttribute("readonly","")}update(e){this.element.disabled?this.disable():this.element.readOnly?this.readonly():this.enable(),this.element.checked?this.on(e):this.off(e)}trigger(e){e||this.element.dispatchEvent(new Event("change",{bubbles:!0}))}destroy(){this.ecmasToggle.parentNode.insertBefore(this.element,this.ecmasToggle),this.ecmasToggle.parentNode.removeChild(this.ecmasToggle),delete this.element.bsToggle,delete this.ecmasToggle}}Element.prototype.bootstrapToggle=function(e,t){let s=this.bsToggle||new i(this,e);e&&"string"==typeof e&&("toggle"==e.toLowerCase()?s.toggle(t):"on"==e.toLowerCase()?s.on(t):"off"==e.toLowerCase()?s.off(t):"enable"==e.toLowerCase()?s.enable():"disable"==e.toLowerCase()?s.disable():"readonly"==e.toLowerCase()?s.readonly():"destroy"==e.toLowerCase()&&s.destroy())},"undefined"!=typeof window&&(window.onload=function(){document.querySelectorAll('input[type=checkbox][data-toggle="toggle"]').forEach(function(e){e.bootstrapToggle()})}),"undefined"!=typeof module&&module.exports&&(module.exports=i)}(); //# sourceMappingURL=bootstrap5-toggle.ecmas.min.js.map \ No newline at end of file diff --git a/js/bootstrap5-toggle.ecmas.min.js.map b/js/bootstrap5-toggle.ecmas.min.js.map index d2116dc..7d41fc1 100644 --- a/js/bootstrap5-toggle.ecmas.min.js.map +++ b/js/bootstrap5-toggle.ecmas.min.js.map @@ -1 +1 @@ -{"version":3,"file":"bootstrap5-toggle.ecmas.min.js","sources":["bootstrap5-toggle.ecmas.js"],"names":["Toggle","constructor","element","options","DEFAULTS","this","on","getAttribute","onstyle","off","offstyle","size","style","width","height","render","calcH","el","styles","window","getComputedStyle","offsetHeight","borderTopWidth","parseFloat","borderBottomWidth","paddingTop","paddingBottom","let","ecmasToggleOn","document","createElement","ecmasToggleOff","setAttribute","id","innerHTML","ecmasToggleHandle","ecmasToggleGroup","ecmasToggle","appendChild","classList","add","checked","split","forEach","disabled","readOnly","parentElement","insertBefore","Math","max","getBoundingClientRect","lineHeight","addEventListener","toggle","e","preventDefault","bsToggle","silent","remove","trigger","enable","removeAttribute","disable","readonly","update","dispatchEvent","Event","bubbles","destroy","parentNode","removeChild","Element","protot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UN,YAQnC,oBAAXjD,SACVA,OAAOyD,OAAS,WACf/C,SAASgD,iBAAiB,8CAA8ClC,QAAQ,SAASmC,GACxFA,EAAIL,sBAKe,oBAAXM,QAA0BA,OAAOC,UAC3CD,OAAOC,QAAUhF,GAvPnB"} \ No newline at end of file +{"version":3,"file":"bootstrap5-toggle.ecmas.min.js","sources":["bootstrap5-toggle.ecmas.js"],"names":["Toggle","constructor","element","options","DEFAULTS","this","on","getAttribute","onstyle","off","offstyle","size","style","width","height","tabindex","render","calcH","el","styles","window","getComputedStyle","offsetHeight","borderTopWidth","parseFloat","borderBottomWidth","paddingTop","paddingBottom","let","ecmasToggleOn","document","createElement","ecmasToggleOff","setAttribute","id","innerHTML","ecmasToggleHandle","ecmasToggleGroup","ecmasToggle","appendChild","classList","add","checked","split","forEach","disabled","readOnly","parentElement","insertBefore","Math","max","getBoundingClientRect","lineHeight","addEventListener","toggle","e","preventDefault","bsToggle","silent","remove","trigger","enable","removeAttribute","disable","readonly","update","dispatchEvent","Event","bubbles","destroy","parentNode","removeChild","Element","prototype","bootstrapToggle","_bsToggle","toLowerCase","onload","querySelectorAll","ele","module","exports"],"mappings":"cAaA,iBAIOA,EACLC,YAAYC,EAASC,GACpB,MAAMC,EACD,KADCA,EAEI,UAFJA,EAGA,MAHAA,EAIK,YAJLA,EAKC,GALDA,EAME,GANFA,EAOE,KAPFA,EAQG,KARHA,EASK,EAEXD,EAAUA,GAAW,GAGrBE,KAAKH,QAAUA,EAGfG,KAAKF,QAAU,CACdG,GAAID,KAAKH,QAAQK,aAAa,YAAcJ,EAAQG,IAAMF,EAC1DI,QAASH,KAAKH,QAAQK,aAAa,iBAAmBJ,EAAQK,SAAWJ,EACzEK,IAAKJ,KAAKH,QAAQK,aAAa,aAAeJ,EAAQM,KAAOL,EAC7DM,SAAUL,KAAKH,QAAQK,aAAa,kBAAoBJ,EAAQO,UAAYN,EAC5EO,KAAMN,KAAKH,QAAQK,aAAa,cAAgBJ,EAAQQ,MAAQP,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WAChC3D,KAAKwD,SACNxD,KAAKH,QAAQwC,QAASrC,KAAKC,GAAGoD,GAC7BrD,KAAKI,IAAIiD,GAGfE,QAAQF,GACFA,GAAQrD,KAAKH,QAAQgE,cAAc,IAAIC,MAAM,SAAU,CAAEC,SAAS,KAGxEC,UAEChE,KAAKiC,YAAYgC,WAAWtB,aAAa3C,KAAKH,QAASG,KAAKiC,aAC5DjC,KAAKiC,YAAYgC,WAAWC,YAAYlE,KAAKiC,oBAGtCjC,KAAKH,QAAQuD,gBACbpD,KAAKiC,aAQdkC,QAAQC,UAAUC,gBAAkB,SAASvE,EAASuD,GACrD9B,IAAI+C,EAAYtE,KAAKoD,UAAY,IAAIzD,EAAOK,KAAMF,GAG9CA,GAA8B,iBAAZA,IACQ,UAAzBA,EAAQyE,cAA2BD,EAAUrB,OAAOI,GACtB,MAAzBvD,EAAQyE,cAAuBD,EAAUrE,GAAGoD,GACnB,OAAzBvD,EAAQyE,cAAwBD,EAAUlE,IAAIiD,GACrB,UAAzBvD,EAAQyE,cAA2BD,EAAUd,SACpB,WAAzB1D,EAAQyE,cAA4BD,EAAUZ,UACrB,YAAzB5D,EAAQyE,cAA6BD,EAAUX,WACtB,WAAzB7D,EAAQyE,eAA4BD,EAAUN,YAQnC,oBAAXjD,SACVA,OAAOyD,OAAS,WACf/C,SAASgD,iBAAiB,8CAA8ClC,QAAQ,SAASmC,GACxFA,EAAIL,sBAKe,oBAAXM,QAA0BA,OAAOC,UAC3CD,OAAOC,QAAUjF,GA1PnB"} \ No newline at end of file diff --git a/js/bootstrap5-toggle.js b/js/bootstrap5-toggle.js index 1ad0f38..fb2592b 100644 --- a/js/bootstrap5-toggle.js +++ b/js/bootstrap5-toggle.js @@ -32,7 +32,8 @@ size: 'normal', style: '', width: null, - height: null + height: null, + tabindex: 0, } Toggle.prototype.defaults = function() { @@ -44,7 +45,8 @@ size: this.$element.attr('data-size') || Toggle.DEFAULTS.size, style: this.$element.attr('data-style') || Toggle.DEFAULTS.style, width: this.$element.attr('data-width') || Toggle.DEFAULTS.width, - height: this.$element.attr('data-height') || Toggle.DEFAULTS.height + height: this.$element.attr('data-height') || Toggle.DEFAULTS.height, + tabindex: this.$element.attr('tabindex') || Toggle.DEFAULTS.tabindex, } } @@ -89,6 +91,7 @@ let $toggle = $('
') .addClass( this.$element.prop('checked') ? 'btn-' +this.options.onstyle : 'btn-' +this.options.offstyle+' off' ) .addClass(size).addClass(this.options.style) + .attr('tabindex', this.options.tabindex) if (this.$element.prop('disabled') || this.$element.prop('readonly')){ $toggle.addClass('disabled') $toggle.attr('disabled', 'disabled') diff --git a/js/bootstrap5-toggle.min.js b/js/bootstrap5-toggle.min.js index 96a3a16..9dc6e8e 100644 --- a/js/bootstrap5-toggle.min.js +++ b/js/bootstrap5-toggle.min.js @@ -8,5 +8,5 @@ * @see https://github.com/palcarazm/bootstrap5-toggle/blob/master/LICENSE */ -!function(a){"use strict";function l(t,e){this.$element=a(t),this.options=a.extend({},this.defaults(),e),this.render()}l.DEFAULTS={on:"On",off:"Off",onstyle:"primary",offstyle:"secondary",size:"normal",style:"",width:null,height:null},l.prototype.defaults=function(){return{on:this.$element.attr("data-on")||l.DEFAULTS.on,off:this.$element.attr("data-off")||l.DEFAULTS.off,onstyle:this.$element.attr("data-onstyle")||l.DEFAULTS.onstyle,offstyle:this.$element.attr("data-offstyle")||l.DEFAULTS.offstyle,size:this.$element.attr("data-size")||l.DEFAULTS.size,style:this.$element.attr("data-style")||l.DEFAULTS.style,width:this.$element.attr("data-width")||l.DEFAULTS.width,height:this.$element.attr("data-height")||l.DEFAULTS.height}},l.prototype.render=function(){let t;switch(this.options.size){case"large":case"lg":t="btn-lg";break;case"small":case"sm":t="btn-sm";break;case"mini":case"xs":t="btn-xs";break;default:t=""}let e=a('