question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Detect the element that is receiving the focus on ionBlur

See original GitHub issue

Ionic 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:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
datawaslostcommented, Jun 14, 2019

I’ve encountered this same error (missing relatedTarget) in a simpler way, without any custom directive:

<ion-textarea (ionBlur)="onBlur($event)"></ion-textarea>

    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
    }
0reactions
ionitron-bot[bot]commented, Aug 16, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found