From ba8d8f489607537b3dac915cfc9f2c32a74b994c Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Mon, 10 Mar 2025 09:01:37 -0700 Subject: [PATCH] fix(toggle): trigger focus and blur on click (#30234) Issue number: N/A --------- ## What is the current behavior? The blur and focus events do not trigger when clicking even though the value changes. Those events are only triggered when dragged. This leads to Angular validation to not work accurately when clicking so the `ion-touched` is never added to the toggle since it relies on the blur event. ## What is the new behavior? - The blur and focus events also trigger on click. This follows the same logic as `ion-checkbox`. ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information How to test: Recommendation to use `toggle/test/basic/index.html`: [Preview](https://ionic-framework-git-toggle-focus-ionic1.vercel.app/src/components/toggle/test/basic) Add the following script: ```js ``` Verify that the focus and blur events trigger when clicking and dragging. --- core/src/components/toggle/toggle.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/components/toggle/toggle.tsx b/core/src/components/toggle/toggle.tsx index b20ef320f0..ca553594f2 100644 --- a/core/src/components/toggle/toggle.tsx +++ b/core/src/components/toggle/toggle.tsx @@ -138,6 +138,7 @@ export class Toggle implements ComponentInterface { const isNowChecked = !checked; this.checked = isNowChecked; + this.setFocus(); this.ionChange.emit({ checked: isNowChecked, value,