Skip to content

Commit

Permalink
feat: Toggles focusable from the keyboard
Browse files Browse the repository at this point in the history
- By default tabindex is set to 0
- The tabindex attribute of the checkbox is propagated to the toggle

Refs: Closes #38
  • Loading branch information
palcarazm committed Jul 17, 2022
1 parent ad01c1d commit 2255f47
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions js/bootstrap5-toggle.ecmas.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
style: '',
width: null,
height: null,
tabindex: 0
};
options = options || {};

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion js/bootstrap5-toggle.ecmas.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2255f47

Please sign in to comment.