bootstrap-hover-dropdown icon indicating copy to clipboard operation
bootstrap-hover-dropdown copied to clipboard

When the 'a' tag has child elements the hover doesnt always work because of the event.target

Open aamjsadiq opened this issue 8 years ago • 12 comments

When i tried something like

<a href="#">
 <i class="fa fa-icon-blah"></i>
<span>Something</span>
</a>

And the icon and the span are block elements the hover doesnt always seems to work.

I figured its because of the event.target check thats been

if(!$parent.hasClass('open') && !$parent.is(event.target)) {

And

if(!$parent.hasClass('open') && !$this.is(event.target) )

By changing these to:

if(!$parent.hasClass('open') && !$.contains($parent[0], $(event.target)[0])) {

And

if(!$parent.hasClass('open') && !$.contains($this[0], $(event.target)[0])) {

Seems to be fixing the issue.

aamjsadiq avatar Jul 10 '16 10:07 aamjsadiq

Thanks for sharing the code! It's working for me! 👍

clemens7haar avatar Aug 05 '16 10:08 clemens7haar

This has solved issues for me as well. Thanks for posting your fix.

revolutionaries avatar Aug 29 '16 13:08 revolutionaries

I don't understand... what element do you have that's triggering the hover? I didn't see the attributes to trigger it. I mean, with just that markup, it shouldn't work at all.

CWSpear avatar Aug 29 '16 18:08 CWSpear

Hi - I assume @aamjsadiq is referring to code within a Nav <li>, I have a similar scenario and his fix solved the intermittent hover issues for me.

revolutionaries avatar Sep 06 '16 10:09 revolutionaries

Hi @CWSpear ,

Sorry for posting a dummy code.

The Actual code looks somewhat similar to below.

<a href="#" data-toggle="dropdown" data-delay="10" data-hover="dropdown" data-close-others="true" class="main">
  <span class="icon-home"></span>
   Text For Link 
</a>

The issue happens when your mouse hover target is actually the span , as per existing code it checks whether the target is <a> , but the fix checks for any child elements inside the<a> as well.

aamjsadiq avatar Sep 06 '16 15:09 aamjsadiq

+1

joshudev avatar Sep 30 '16 15:09 joshudev

We also needed this tweak, thanks!

GhostLtd avatar Feb 06 '17 10:02 GhostLtd

Exactly same issue, and this worked fine. Thanks.

orion3dgames avatar Feb 20 '17 00:02 orion3dgames

+1 it has to be in the main branch

R-G-B avatar Apr 25 '17 14:04 R-G-B

@aamjsadiq can you provide a PR for this making it easier for @CWSpear to adopt it?

holtkamp avatar May 05 '17 09:05 holtkamp

@aamjsadiq thank you for this patch.

Why is this issue still open?

mathisvester avatar Apr 10 '18 13:04 mathisvester

I guess a Pull Request would make it easier for the maintainer to merge...

holtkamp avatar Apr 10 '18 15:04 holtkamp