Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix isVisible false positives from deep nesting or alternate means #33960

Merged
merged 9 commits into from
May 20, 2021

Conversation

RyanBerliner
Copy link
Contributor

fixes #33914

@RyanBerliner RyanBerliner requested a review from a team as a code owner May 13, 2021 01:35
Copy link
Contributor

@alpadev alpadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't judge for the if-condition, but everything else LGTM, thank you! 👍

@alpadev
Copy link
Contributor

alpadev commented May 16, 2021

@RyanBerliner Hm wouldn't be checking getClientRects() enough to see if an element (or an ancestor of it) has display: none? 🤔

@RyanBerliner
Copy link
Contributor Author

RyanBerliner commented May 17, 2021

@RyanBerliner Hm wouldn't be checking getClientRects() enough to see if an element (or an ancestor of it) has display: none? 🤔

99% of the time, yes! However, so long as we keep the element.tagName !== 'AREA', then we'll still need to check the display property for supporting that specific tag name. I know we could also squeeze in a few more edge cases to support here, though I'd imagine it's preferred only to improve it as much as we think the framework will need it. I'm looking at this function through the lens of the most rigorous use case bootstrap will be using it for, which is probably #33865.

This is why I've decided to support the <area> edge case, and not (for example) the svg edge case. <area> is focusable by default, and I'd think someone is more likely to put an image map in a modal (still unlikely though lol) than an svg with an explicit tabindex. If you all have more insight into what edge cases you'd imagine should be supported I can adjust accordingly.

Copy link
Member

@GeoSot GeoSot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe window.getComputedStyle(x).getPropertyValue('visibility') would work without tricks
Example wrong link sorry
Example

const eligibleElement = el => el && el.style could by replaced be isElement?

@alpadev
Copy link
Contributor

alpadev commented May 18, 2021

@RyanBerliner From my observations getClientRects() seem to work for <area>. That's true at least with the latest versions of Chromium, FF and Safari. (The values of the DOMRect that is returned are wrong but it's not like we check those). I did some research and found a Chromium bug, that mentions, that they eventually changed that some years ago to match the FF behaviour. (https://bugs.chromium.org/p/chromium/issues/detail?id=416195#c6)

I couldn't find any informations in the spec tho, that would confirm if an HTMLAreaElement should or shouldn't have a bounding box.

Also I found that even when you apply display: none to an <area> or <map> element, you can still tab to it and click it. So not sure if it makes sense even, to check if they are visible or not.

Maybe we should just risk it, and fix it if some issue pops up.

@RyanBerliner
Copy link
Contributor Author

Interesting - I'm starting to think we should just completely remove the edge case handling of <area> as it seems it's a little all over the place with browser behavior. Here is where I got my initial inspiration to handle <area> separately, fyi. Then we can completely remove the loop, rely entirely on getClientRect(), and do a final visibility check with the computed style property like @GeoSot suggested. Would that work with everyone or should I proceed with the other suggested changes while maintaining separate <area> checking?

@alpadev
Copy link
Contributor

alpadev commented May 18, 2021

To be honest, I don't really have a preference here. It's hard to argue when neither the browser nor the specification is clear about this behavior. I feel like image maps may be some abandoned thing since they lack of responsiveness or something.

I had a talk with Geo yesterday, and he asked about opacity. My guess that would require to have a loop, if we want to take care about that too.

Hard to say what's the best approach here, but I'm a bit concerned, that with that many iterations we will block you or kill your mood a bit. ❤️

@GeoSot
Copy link
Member

GeoSot commented May 18, 2021

IMO kill the 'AREA' thing. Is so rare.
The checks are already better than before.

As @alpadev said:

Maybe we should just risk it, and fix it if some issue pops up.

I cannot agree more.

@GeoSot GeoSot merged commit 4ac711b into twbs:main May 20, 2021
marvin-hinkley-vortx pushed a commit to Vortx-Inc/bootstrap that referenced this pull request May 20, 2021
@XhmikosR XhmikosR changed the title fix isVisible false positives from deep nesting or alternate means fix isVisible false positives from deep nesting or alternate means Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isVisible utility function returning false positives
4 participants