From 5a81033b1523c291e36ecc1b85f94bac926a9307 Mon Sep 17 00:00:00 2001 From: patrickhlauke Date: Mon, 27 May 2019 20:44:32 +0100 Subject: [PATCH 01/30] Fix keyboard behaviour for button plugin checkbox/radio buttons - remove `preventDefault()` which stopped regular keyboard behaviour (as currently using keyboard only changes styling on the `.btn`) - special-case checkbox input check in `toggle()` function, to avoid double-triggering (leaving checkbox back in its original state) when using mouse --- js/src/button.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/src/button.js b/js/src/button.js index fcf805502a33..25e4b3d68684 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -81,6 +81,10 @@ class Button { $(activeElement).removeClass(ClassName.ACTIVE) } } + } else if (input.type === 'checkbox') { + if (input.checked === this._element.classList.contains(ClassName.ACTIVE)) { + triggerChangeEvent = false + } } if (triggerChangeEvent) { @@ -140,8 +144,6 @@ class Button { $(document) .on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, (event) => { - event.preventDefault() - let button = event.target if (!$(button).hasClass(ClassName.BUTTON)) { From 639a2a23f225bdbfea3286da673b8018363a85b8 Mon Sep 17 00:00:00 2001 From: patrickhlauke Date: Mon, 27 May 2019 22:21:29 +0100 Subject: [PATCH 02/30] Make additional checkbox handling only apply when click happened on a label - while the ideal pattern for authors to use is ``, they MAY stray from it. in those cases, the extra check (which avoids the double-triggering, since we don't prevent default anymore) should not happen, as otherwise the checkbox would never get triggered --- js/src/button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/src/button.js b/js/src/button.js index 25e4b3d68684..075fbd69087c 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -82,7 +82,7 @@ class Button { } } } else if (input.type === 'checkbox') { - if (input.checked === this._element.classList.contains(ClassName.ACTIVE)) { + if (this._element.tagName === 'LABEL' && input.checked === this._element.classList.contains(ClassName.ACTIVE)) { triggerChangeEvent = false } } From 847cd68fc1e49e00075fe70382b6751964e0ac49 Mon Sep 17 00:00:00 2001 From: patrickhlauke Date: Mon, 27 May 2019 22:53:17 +0100 Subject: [PATCH 03/30] Change toggle selectable inputs unit test an admittedly jury-rigged tweak, but as running `trigger('click')` in qunit/headless chrome does not fire the same default behaviour as a real click on a `