From 6a285db2ed5dbb4d094ba491f79deb28cd327d0a Mon Sep 17 00:00:00 2001 From: tg666 Date: Fri, 14 Apr 2023 16:35:47 +0200 Subject: [PATCH] Changed behaviour of switch buttons on enter keydown - enter submits associated form --- assets/js/plugin/toggle.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/assets/js/plugin/toggle.js b/assets/js/plugin/toggle.js index 22a47f9e..b9c82e80 100644 --- a/assets/js/plugin/toggle.js +++ b/assets/js/plugin/toggle.js @@ -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; },