Refactor toggles to work without JS, add specs
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ "button", "switch", "input" ]
|
||||
static targets = [ "button", "switch", "checkbox" ]
|
||||
static values = { switchEnabled: Boolean }
|
||||
|
||||
connect () {
|
||||
this.buttonTarget.classList.remove("hidden")
|
||||
this.checkboxTarget.classList.add("hidden")
|
||||
}
|
||||
|
||||
toggleSwitch () {
|
||||
this.switchEnabledValue = !this.switchEnabledValue
|
||||
this.inputTarget.value = this.switchEnabledValue.toString()
|
||||
this.checkboxTarget.checked = this.switchEnabledValue
|
||||
|
||||
if (this.switchEnabledValue) {
|
||||
this.buttonTarget.setAttribute("aria-checked", "true");
|
||||
|
||||
Reference in New Issue
Block a user