Skip to content

[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

Merged
merged 9 commits into from
Aug 8, 2025

Conversation

zoehe-sc
Copy link
Contributor

@zoehe-sc zoehe-sc commented Aug 8, 2025

jira: https://skyscanner.atlassian.net/browse/CYB-3904
link wrapper
image

Summary

This PR updates BpkGraphicPromo to render its outer wrapper as a semantic <a> tag when an href 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" and tabIndex="0" on a <div>, which are not meaningful for crawlers or semantic analysis.

SEO Benefits

  • Enables search engines to discover and index links rendered by this component.
  • Improves semantic correctness of markup, allowing better accessibility and link intent recognition.
  • Avoids div-based "fake links", which are often missed by SEO tools and crawlers.

Changes

  • Added a Wrapper component to render either <a> or <div> safely with appropriate props.
  • If href is present, the component now renders as <a> instead of <div>.

Remember to include the following changes:

  • Ensure the PR title includes the name of the component you are changing so it's clear in the release notes for consumers of the changes in the version e.g [Clover-123][BpkButton] Updating the colour
  • README.md (If you have created a new component)
  • Component README.md
  • Tests
  • Accessibility tests
    • The following checks were performed:
      • Ability to navigate using a keyboard only
      • Zoom functionality (Deque University explanation):
        • The page SHOULD be functional AND readable when only the text is magnified to 200% of its initial size
        • Pages must reflow as zoom increases up to 400% so that content continues to be presented in only one column i.e. Content MUST NOT require scrolling in two directions (both vertically and horizontally)
      • Ability to navigate using a screen reader only
  • Storybook examples created/updated
  • For breaking changes or deprecating components/properties, migration guides added to the description of the PR. If the guide has large changes, consider creating a new Markdown page inside the component's docs folder and link it here

@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 03:59
Copy link
Contributor

@Copilot Copilot AI left a 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

@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser.

@zoehe-sc zoehe-sc changed the title [wip]add a tag for graphic promo [CYB-3502][BpkGraphicPromo] Use anchor tag as wrapper for better semantics and accessibility Aug 8, 2025
@skyscanner-backpack-bot
Copy link

skyscanner-backpack-bot bot commented Aug 8, 2025

Warnings
⚠️

Package source files (e.g. packages/package-name/src/Component.js) were updated, but snapshots weren't. Have you checked that the tests still pass?

Browser support

If this is a visual change, make sure you've tested it in multiple browsers.

Generated by 🚫 dangerJS against 4a9276e

@zoehe-sc zoehe-sc added the minor Non breaking change label Aug 8, 2025
@zoehe-sc zoehe-sc changed the title [CYB-3502][BpkGraphicPromo] Use anchor tag as wrapper for better semantics and accessibility [CYB-3502][BpkGraphicPromo] Render wrapper as semantic anchor tag to improve SEO Aug 8, 2025
@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser.

@zoehe-sc zoehe-sc changed the title [CYB-3502][BpkGraphicPromo] Render wrapper as semantic anchor tag to improve SEO [CYB-3904][BpkGraphicPromo] Render wrapper as semantic anchor tag to improve SEO Aug 8, 2025
>
{children}
</div>

Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

Copy link
Contributor

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}
Copy link
Contributor

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?

Copy link
Contributor Author

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

@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser.

@skyscanner-backpack-bot
Copy 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');

Copy link
Contributor

Choose a reason for hiding this comment

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

empty line 😄

Comment on lines 143 to 144


Copy link
Contributor

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?

Copy link
Contributor Author

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?

@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser.

@skyscanner-backpack-bot
Copy link

Visit https://backpack.github.io/storybook-prs/3904 to see this build running in a browser.

@GCpigsic GCpigsic merged commit 5a3b558 into main Aug 8, 2025
10 checks passed
@GCpigsic GCpigsic deleted the graphic_promo_link branch August 8, 2025 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Non breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants