-
Notifications
You must be signed in to change notification settings - Fork 129
Fix URL link hidden by autofocus is still clickable #3407
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
base: main
Are you sure you want to change the base?
Fix URL link hidden by autofocus is still clickable #3407
Conversation
raineorshine
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your submission.
This solves the problem, but I'm not sure yet if this is the best solution.
First, there is a bit of forensics that is needed to understand the current use of pointerEvents: all. What purpose does it serve? When was it added and why? Is it overriding an inherited value? The default value is auto so it's not obvious why it would need to be set to all. We always make sure to understand the cause of the problem first before attempting a fix. Git blame will help here.
Second, the assignment of responsibility seems wrong here. Why should UrlIconLink have to know whether it is hidden or not? If an ancestor controls its visibility, it seems like the ancestor should be responsible for this.
src/components/icons/UrlIcon.tsx
Outdated
| // Make sure the icon doesn't take up extra space. | ||
| padding: '0.05em 0.167em 0.167em 0', | ||
| cursor: 'pointer', | ||
| pointerEvents: 'all', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this to reduce the depth of prop drilling of isVisible property.
Instead, I used that pointerEvents: 'all' in UrlIconLink.
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
| pointerEvents: 'none', |
Please notice that
Subthought has pointerEvents: 'none'
So the children inside ThoughtAnnotationWrapper cannot be clickable. To solve that, the previous developer added this property - pointerEvents: 'all' (to override inherited value).
em/src/components/ThoughtAnnotation.tsx
Lines 162 to 165 in ab158c2
| { | |
| // do not render url icon on root thoughts in publish mode | |
| url && !(publishMode() && simplePath.length === 1) && <UrlIconLink url={url} /> | |
| } |
src/components/ThoughtAnnotation.tsx
Outdated
| rel='noopener noreferrer' | ||
| target='_blank' | ||
| className={urlLinkStyle} | ||
| className={cx(urlLinkStyle, css({ pointerEvents: !isVisible ? 'none' : 'all' }))} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UrlIconLink has UrlIcon as a child.
In UrlIcon component, there is a style pointerEvents: 'all'.
I extracted out pointerEvents property from that component to reduce the depth of prop drilling of isVisible.
This property is calculated here. And it is drilled down to children deeply (in original approach).
em/src/components/Subthought.tsx
Line 67 in ab158c2
| const isVisible = zoomCursor || autofocus === 'show' || autofocus === 'dim' |
raineorshine
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, why should UrlIconLink have to know if it is visible or not? Components are not usually made aware of ancestor responsibilities.
The solution is not there yet. You will need to either find a way to remove the pointerEvents override mess, or add comments in the code that clarify their purpose and the implicit dependencies that exist. Just because the previous developer didn't document it properly doesn't take us off the hook.
In other cases we use PandaCSS to provide more typesafe overriding of inherited styles, e.g. in https://github.com/cybersemics/em/blob/main/src/recipes/toolbarPointerEvents.ts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for your submission. Is there any chance there is a simpler way to do this? The PandaCSS recipe does provide some type safety, but now we have a double override. Plus, & > * is a child selector, which creates a type unsafe connection to the DOM hierarchy. We typically try to avoid selectors like this.
I would like to think that a more elegant solution exists. Let me know if you have any other ideas!
It might also be worth investigating the original reason why pointerEvents: none was set on the ThoughtAnnotation. Maybe there is a different way to achieve that, and avoid the need for awkward overrides.
@raineorshine, We need it now.
We are doing this currently:
I have some ideas of alternatives:
So current approach is reasonable. The override pattern is:
|
Just confirming that it is still needed. When I remove
That still doesn't address the double override and the child selector, mentioned above. So far I'm not sold on this solution. |
Did try to remove |
|
Correct |
|
@BayuAri Ready for testing! Since it is not mobile-specific, this requires testing on desktop Chrome only. |
BayuAri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue is still reproducible.
Hidden url is still clickable.
Step to reproduce
- Create some thought
- Add a url as a subthought in one of them
- Click a thought that has no url
- Click url icon on the thought that has url as subthought from step 2
Current behavior
url is clickable and new browser is opened
See below video:
Hidden.URL.icon.is.stll.clickable.MOV
Expected behavior
Nothing should happen because the url is hidden under
Fix: #3245
Remove
pointerEvent: "none"fromThoughtAnnotationWrapper.This way is fine, because of the rendering order.
So first
ThoughtAnnotationWrapperis rendered and after that,ThoughtAnnotationis rendered. SoThoughtAnnotationoverlaps theThoughtAnnotationWrapper.Before, I had mistake to understand the rendering order.
So there is no need to add property
pointerEvent: "all"to icon components.