Link: Honor openInNewTab consistently#77422
Conversation
openInNewTab consistently
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.75 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 478ac67. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24560614440
|
aduth
left a comment
There was a problem hiding this comment.
This makes sense to me, and I appreciate the additional context around why it was added 👍
| expect( ref.current ).toBeInstanceOf( HTMLAnchorElement ); | ||
| } ); | ||
|
|
||
| it( 'calls onClick when clicked', async () => { |
There was a problem hiding this comment.
Outside the context of this specific change, this doesn't feel like a particularly noteworthy test beyond ensuring that the spread props to the link are respected. It feels rather "open box" implementation-aware testing in how we were previously handling the hash behavior.
Personally, I'd either remove it, or generalize it that the link element receives additional spread props.
There was a problem hiding this comment.
It was added intentionally, because from my experience click handlers on components like this are heavily used in practice by third parties (for analytics code) but hard for maintainers to notice regressions because they don't appear in Gutenberg code 😄 And it is actually a regression-prone path because onClicks tend to be mucked with in component internals like we were just doing here before the change.
I can maybe add a clarification in the test description about it's significance.
There was a problem hiding this comment.
Fair enough, and yeah, an inline comment describing the type of regression we're trying to protect against would be helpful 👍
# Conflicts: # packages/ui/CHANGELOG.md
What?
This updates
@wordpress/ui'sLinkto honoropenInNewTabconsistently instead of treating hash links as a special case.Why?
Linkis a generic primitive, soopenInNewTabshould reflect explicit caller intent for anyhref. The previous behavior was inherited from editor-specificExternalLinklogic (#42259) and made#...links render new-tab affordances while cancelling the click, which was surprising and hard to justify. Even the implementer was questioning why theExternalLinkcomponent was used for non-external links.In our new
Linkcomponent,openInNewTabis an opt-in behavior, and there's no reason for a consumer to opt into that if they're rendering a hash link.How?
onClickpass through via the rest props.openInNewTabdocs to match the simplified behavior.defaultPreventedinternals.Testing Instructions
npm run test:unit -- packages/ui/src/link/test/index.test.tsx --runInBand.