Skip to content

Commit

Permalink
Changed behaviour of switch buttons on enter keydown - enter submits …
Browse files Browse the repository at this point in the history
…associated form
  • Loading branch information
tg666 committed Apr 25, 2023
1 parent 87aa3d8 commit 6a285db
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions assets/js/plugin/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ function Toggle(Alpine) {
['x-on:click']() {
this.doToggle();
},
['x-on:keydown.enter.prevent']() {
const $form = this.$el.form;

if (!$form) {
return;
}

const $submitButton = $form.querySelector('input[type="submit"], button[type="submit"]');

if ($submitButton) {
$submitButton.click();
}
},
[':aria-checked']() {
return this.checked;
},
Expand Down

0 comments on commit 6a285db

Please sign in to comment.