-
Notifications
You must be signed in to change notification settings - Fork 203
[CYB-3904][BpkGraphicPromo] Render wrapper as semantic anchor tag to improve SEO #3904
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
Conversation
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.
Pull Request Overview
This PR adds the ability to render the BpkGraphicPromo
component as a semantic anchor tag (<a>
) instead of a <div>
when a URL is provided, improving SEO and semantic HTML structure.
- Introduces an optional
href
prop that conditionally renders the component as an anchor tag - Refactors the component structure using a new
Wrapper
component to handle conditional rendering - Adds appropriate CSS styling for anchor tag behavior
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
BpkGraphicPromo.tsx | Adds href prop and Wrapper component for conditional anchor/div rendering |
BpkGraphicPromo.module.scss | Adds CSS styles for anchor tag behavior (display block, text decoration) |
BpkGraphicPromo-test.tsx | Adds test coverage for both anchor and div rendering scenarios |
stories.js | Exports new LinkWrapper story example |
examples.js | Implements LinkWrapperExample demonstrating href functionality |
packages/bpk-component-graphic-promotion/src/BpkGraphicPromo.tsx
Outdated
Show resolved
Hide resolved
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
> | ||
{children} | ||
</div> | ||
|
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.
Nit, could you help remove the redundant empty line?
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.
Done
onClick, | ||
onKeyDown, | ||
style = {}, | ||
tabIndex = 0, |
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.
Should tabIndex=0
still be needed here, or we can just set the tabIndex as 0 when rendering div ? Seems we already set the element as a
when href is provided
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.
Good point!
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.
Seems we can remove this in WrapperProps
, just pass the tabIndex=0 in line 136, what do you think?
id={contentId || ''} | ||
className={cardClasses} | ||
cardClasses={cardClasses} |
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.
why do we change it to cardClasses here?
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.
Because elint does not allow adding className attributes to components that are not basic components, so I changed the prop name
packages/bpk-component-graphic-promotion/src/BpkGraphicPromo.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: GC Zhu <171069086@qq.com>
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
…ckpack into graphic_promo_link
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
const renderedElement = screen.getByRole('link'); | ||
|
||
expect(renderedElement.tagName.toLowerCase()).toBe('div'); | ||
|
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.
empty line 😄
|
||
|
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.
empty line, could you format the file before submiting?
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.
Does executing lint:js:fix
not work?
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser. |
jira: https://skyscanner.atlassian.net/browse/CYB-3904

link wrapper
Summary
This PR updates
BpkGraphicPromo
to render its outer wrapper as a semantic<a>
tag when anhref
is provided, in order to improve SEO and HTML semantics.Using a native anchor tag allows search engines to crawl and index the link correctly, instead of relying on
role="link"
andtabIndex="0"
on a<div>
, which are not meaningful for crawlers or semantic analysis.SEO Benefits
div
-based "fake links", which are often missed by SEO tools and crawlers.Changes
Wrapper
component to render either<a>
or<div>
safely with appropriate props.href
is present, the component now renders as<a>
instead of<div>
.Remember to include the following changes:
[Clover-123][BpkButton] Updating the colour
README.md
(If you have created a new component)README.md