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.

slFocus and slBlur events fire twice on slSelect component

See original GitHub issue

Describe the bug When an slSelect component gains or loses focus, the slFocus and slBlur events are called twice.

To Reproduce Steps to reproduce the behavior:

  1. On https://shoelace.style/components/select add an event listener to a sl-select element in the console, $0.addEventListener('slFocus', () => console.log('slFocus'))
  2. Focus the sl-select by clicking on it
  3. slFocus is shown twice in the console
  4. Repeat for the slBlur event

Expected behavior The slFocus and slBlur events should just be fired once.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
claviskacommented, Sep 4, 2020

Fixed in b51978b

0reactions
Marvinifiedcommented, Sep 4, 2020

@claviska after further digging I found out that the slBlur & slFocus event handlers for sl-select are also linked to sl-input that is being used in the component which is why the handler is being called twice.

This means there would be no need to remove the event emmiter in sl-select as I suggested before.

I would suggest just detaching the handler from sl-input here👇🏻 so it doesn’t get emitted twice.

https://github.com/shoelace-style/shoelace/blob/84d4421575c530f9145bea88b77cf06591bcf698/src/components/select/select.tsx#L409-L410

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent BLUR event from firing multiple times?
The reason it is firing multiple times is because you place another copy of the blur handler on the input element every single...
Read more >
Focus and blur handlers triggered twice when switching tabs
Issue 124583: Focus and blur handlers triggered twice when switching tabs ... What steps will reproduce the problem? ... What is the expected...
Read more >
Delegate focus/blur event fires twice - jQuery - Bug Tracker
Attaching focus/blur with delegation using a * selector causes handlers to be fired twice on input elements that are within a form.
Read more >
OnFocus fires twice when window restored - Bugzilla@Mozilla
The problem here is the Windows OS. Windows dispatches focus and activation events in reverse order when a window is minimized and also...
Read more >
Focusing: focus/blur - The Modern JavaScript Tutorial
The focus event is called on focusing, and blur – when the element loses the focus. Let's use them for validation of an...
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