Skip to content

fix(aio): handle clicks deep within anchor tags - #16131

Merged
petebacondarwin merged 1 commit into
angular:masterfrom
IdeaBlade:aio-fix-click-handling
Apr 20, 2017
Merged

petebacondarwin merged 1 commit into
angular:masterfrom
IdeaBlade:aio-fix-click-handling

Conversation

@wardbell

@wardbell wardbell commented Apr 18, 2017 •

Copy link
Copy Markdown
Contributor

Several docs (e.g., "Docs" guide page) surround arbitrary HTML content in anchor tags. Our previous logic in AppComponent looked only at the eventTarget parent (and then only if the eventTarget was an image). This was inadequate. Clicking on any other nested content triggered an unwanted page refresh because we did not find the anchor.

In this fix, the click interception analysis climbs the ancestor tree until it finds an anchor tag to analyze and, potentially, intercept. If it doesn't find an anchor, the default click handling is allowed (returns true).

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

@wardbell wardbell self-assigned this Apr 18, 2017
@wardbell wardbell mentioned this pull request Apr 18, 2017
2 of 3 tasks
@mary-poppins

Copy link
Copy Markdown

The angular.io preview for b52f0de76e577eb8a4036a218de83082b1894828 is available here.

@wardbell

Copy link
Copy Markdown
Contributor Author

Failing the Travis saucelabs task. Flake?

@wardbell wardbell added the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 19, 2017

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder (mostly ooc) why we have stuff wrapped deeply in anchors, but if we must this LGTM (with the test fixed).

Comment thread aio/src/app/app.component.spec.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

imageElement --> divElement

Comment thread aio/src/app/app.component.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for instanceof check any more. If it is truthy, it will be an HTMLAnchorElement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@petebacondarwin petebacondarwin added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 19, 2017
Comment thread aio/src/app/app.component.spec.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest that you simplify this code by using innerHTML which makes the whole thing way more readable:

fixture.nativeElement.innerHTML="<a href='some/url'><div><img></div></a>"
const imageElement = fixture.nativeElement.findElementByTagName('img');
imageElement.click();

3 readable lines vs 8 error prone lines of code. simple is better. :)

Comment thread aio/src/app/app.component.spec.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use the same declarative approach as I explained above.

Comment thread aio/src/app/app.component.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@wardbell
wardbell force-pushed the aio-fix-click-handling branch from b52f0de to e760b2d Compare April 19, 2017 22:28
@wardbell wardbell added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Apr 19, 2017
@wardbell

Copy link
Copy Markdown
Contributor Author

Thanks. Review again please.

@mary-poppins

Copy link
Copy Markdown

The angular.io preview for e760b2d is available here.

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 20, 2017
@petebacondarwin
petebacondarwin merged commit f902581 into angular:master Apr 20, 2017
@wardbell
wardbell deleted the aio-fix-click-handling branch April 21, 2017 18:34
@gkalpak gkalpak mentioned this pull request May 7, 2017
2 of 3 tasks
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants