Detect the element that is receiving the focus on ionBlur
See original GitHub issueIonic version: (check one with “x”) [ ] 1.x (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1) [ ] 2.x [] 3.x [X] 4.x
I’m submitting a … (check one with “x”) [x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/
Current behavior: $event.relatedTarget is null upon an ionBlur event
Expected behavior: $event.relatedTarget should contain the element that is receiving the focus upon an ionBlur event
Steps to reproduce:
Related code:
@Directive({
selector: '[my-directive]',
host: {
//...
'(ionBlur)': 'onBlur($event)'
}
})
export class MyCustomDirective implements OnInit {
//...
onBlur($event) {
console.log(event) // This logs a CustomEvent that contains information only about the element that losing the focus
console.log(event.relatedTarget) // This logs undefined
}
//...
}
I am using this diective with an ion-input
:
<ion-input my-directive></ion-input>
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
ionBlur Event: Detect the element that is receiving the focus
Ionic 5.3 finally added this feature. You can now access the element which is gaining focus via ionBlurEvent.detail.relatedTarget .
Read more >Detect the element that is receiving the focus on ionBlur #17363
onBlur ($event) { console.log(event) // This logs a CustomEvent that contains information only about the element that losing the focus console.
Read more >ionBlur event triggered on focus of an element - Ionic Forum
The focus event occurs when an element gets focus (when selected by a mouse click or by “tab-navigating” to it).
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
Focusing : focus/blur. An element receives the focus when the user either clicks on it or uses the Tab key on the keyboard....
Read more >Element: focus event - Web APIs | MDN
The focus event fires when an element has received focus. The event does not bubble, but the related focusin event that follows does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve encountered this same error (missing relatedTarget) in a simpler way, without any custom directive:
<ion-textarea (ionBlur)="onBlur($event)"></ion-textarea>
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.