Issue with triggering blur event in Internet Explorer while using Angular 2+

The issue discussed in the Blur not working - Angular 2 thread is relevant here.

I have a custom select shared component and I am attempting to implement a blur event to close it when the component loses focus.

// HTML

<div (blur)="closeDropDown()" tabindex="0">
  <span (click)="selectClicked()" class="placeholder">
    Select Item 
  </span>
  <div class="options">
    <ul>
       <li *ngFor="let item of data"> 
       <span>{{item}}</span></li>
    </ul>
  </div>

//TS

 selectClicked() {
   this.dropdownOpen = true;
 }

 closeDropDown() {
   this.dropdownOpen = false;
 }

I successfully added the blur event using the mentioned tabindex workaround (works in all browsers except IE). However, the blur event does not work in IE version > 10.

I attempted to use focusout instead of blur but the selected value does not get attached to the custom select and requires multiple selections to choose an option.

Why isn't the blur event triggering on the div element, and are there any alternative methods that can be used for block-level elements?

Answer №1

After encountering an issue, I found a solution by including focusout and tabindex=-1 in a div element. However, this caused a problem where the value was not being set for my custom dropdown.

The root of the issue lied in the fact that the use of focusout resulted in the event bubbling up to the parent element, causing a delay in setting the dropdown value post-selection.

In order to rectify this issue, I realized that I had forgotten to prevent the event from propagating further. The correction involved stopping the propagation of the event.

// html
<div (focusout)="closeDropDown($event)" tabindex="-1"></div>

// ts
closeDropDown(event) {
  event.stopPropagation();
  this.dropdownOpen = false;
}

The focusout event is triggered when an element is on the brink of losing focus. One key distinction between this event and blur is that focusout bubbles while blur does not.

For more information, check out blur vs focusout -- any real differences? and https://developer.mozilla.org/en-US/docs/Web/API/Element/focusout_event

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issues arise with Shared Module imports not functioning properly within Shared components following an upgrade to Angular 9

I recently updated my project to the following versions: Node from 11 -> 12 Angular from 8 -> 9 After the upgrade, I started encountering compile time errors in my application. The application consists of numerous shared components that are declare ...

Tips for relocating the indicators of a react-material-ui-carousel

I am working with a carousel and dots indicators, but I want to move the indicators from the bottom to the circular position as shown in the image below. I attempted using a negative margin-top, but the indicators ended up being hidden. Is there another ...

"Enhance your website with a unique Bootstrap 5 carousel featuring multiple

As a beginner in Bootstrap, I am currently working on an ecommerce template to learn about Bootstrap 5. I am interested in creating a carousel that displays multiple slides at once, like a products slider with left and right arrows. Is this possible in Bo ...

Unable to download essential dependencies using NPM

After cloning a repository for a MEAN stack application, the first step was to run npm install. The installation process resulted in: added 1580 packages from 1887 contributors and audited 15249 packages in 281.586s found 18 vulnerabilities (5 low, 12 mod ...

Using JavaScript to create an image slider

My image slideshow with prototyping is not working properly and I am struggling to fix it. I have tried binding the setInterval function but it's not working. I also attempted to wrap it, but that didn't work either. What should I do to solve thi ...

Organizing menu options into subcategories using jQuery UI for easy sorting

I am currently working on a horizontal jQuery menu item that includes the sortable option and has one submenu. My goals for this project are as follows: To keep the menu item with the submenu locked at the end of the list To be able to drag menu items fr ...

What is the method for retrieving a value using the Angular forEach function?

I'm encountering an issue with retrieving values from an angular forEach loop. Below is the data I am working with: vm.memberDetails={ "member": [ { "firstName": "HARRY UTTWO", "lastName": "POTTER", } ...

Retrieve a targeted table from a webpage through Ajax refresh

On a webpage, I have a table that has two different views: simple and collapsible. I want to be able to toggle between these views using a button click without the need to refresh the entire page. Below is the code snippet I am currently using: $(&apo ...

Issue with AngularJS ng-model not updating the value of a hidden input

My goal is to transmit form data using hidden input like this: <input type="hidden" required ng-model="formHolder.template[position].itemKey[itr]" ng-value="[[ formItem ]]" /> The value of formItem can be any string. Issues arise when the strings c ...

Navigating JSON data in a POST request using C# in .NET Core version 3.1

Previously, in my .Net Core 2.1 project, I had implemented a method to handle JSON data successfully as shown below: [HttpPost] [Route("sendJsonData")] public JObject saveTemplate(JObject jsonString) { string templateName = (string)jsonString.Sel ...

"Implementing automated default values for Select/dropdown lists in ReactJs, with the added capability to manually revert back to the default selection

After browsing multiple websites, I couldn't find a clear solution on how to both set and select a default value in a select element. Most resources only explain how to set the value, without addressing how to reselect the default value. My Requireme ...

Updating the parameters when clicking on each pagination button: A guide

Does anyone have advice on implementing pagination? I am currently working on loading a datatable with a few records initially. Once the page is loaded, I want to be able to click on pagination buttons like next or any pagination buttons to display a new s ...

transferring attributes from a component iterated over to a component it renders

Admitting my lack of expertise, I am seeking assistance with the implementation of the following code. This is my "posts" component responsible for making an API call to fetch all post data: import React from 'react' import Post from '../pos ...

Issue with mouseover in the jQuery area

As I navigate through a WordPress website, I am attempting to create a mandala using dynamic images. Utilizing jQuery and CSS areas, I aim to display the corresponding image when hovering over a specific section. However, I am facing an issue where there ...

Utilize the dimensions of one image to resize others using the JavaScript method .getBoundingClientRect

I am attempting to transfer the width and height measurements of the initial image to all subsequent images on the page. Currently, I have successfully applied the dimensions of the first image to the second one, but I am facing difficulties with the thir ...

When utilizing the map function with an array containing 168 objects in the state of a React application, a freeze of around 1

I encountered an issue when trying to update a property in a state array of objects after executing an axios.put request. Here is my code: States - useEffect //... const [volunteers, setVolunteers] = useState([]); //... useEffect(() => { async fu ...

How to make an Ajax "POST" request to the server using jQuery or AngularJS without sending any parameter data

"Execute a 'POST' request to the server by using the code provided below However, the parameter data is not being sent to the server. I have attempted both the jQuery Way and var request = $.ajax({ url: baseUrl, type:'post', da ...

Get a collection of images packed into a single zip file

My current function downloads multiple images and saves them to a user's "download" folder, although it only works in Chrome. I am looking to enhance this function by combining the downloaded images into a single zip file. Below is my existing code. ...

Tips for increasing the size of Material-ui Rating icons

I am currently utilizing npm to develop a widget. I aim to utilize the material-ui Rating component and have successfully integrated it. However, when I embed the widget on a webpage, the html font-size is set at 62.5%, causing the component to appear too ...

AngularJS: accessing remote systems - a guide

I am looking to explain my objective clearly I need guidance on how to establish a remote desktop connection from my Angular.js application to a windows application running system. The server I am using is Google App Engine. My current ideas: The Windo ...