Skip to content

feat: support target and rel on LinkMenuItem - #354

Open
jacobo-dominguez-wgu wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:link-menu-item-target
Open

jacobo-dominguez-wgu wants to merge 1 commit into
openedx:mainfrom
WGU-Open-edX:link-menu-item-target

Conversation

@jacobo-dominguez-wgu

Copy link
Copy Markdown
Contributor

Description

Adds optional target and rel props to LinkMenuItem so shell menu items can open in a new tab or a named window. This brings frontend-base up to the same behavior as the Studio header menu items in frontend-component-header openedx/frontend-component-header#687. Since that repo is in maintenance mode, the feature has to land here first.

Part of: openedx/frontend-app-authoring#3052

Changes

  • Adds target?: React.HTMLAttributeAnchorTarget and rel?: string to LinkMenuItemProps, each with a doc comment.
  • Resolves rel the same way frontend-component-header does: rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined). A comment explains that the default protects against reverse tabnabbing.
    • No target: neither attribute is rendered.
    • target="_blank" without rel: rel="noopener noreferrer" is rendered.
    • Explicit rel: used unchanged.
    • Any other target (e.g. studio-help): passed through, with no rel.
  • Spreads { target, rel } after getLinkProps(finalUrl) for all four variants (hyperlink, navLink, navDropdownItem, dropdownItem). getLinkProps is unchanged.

Testing

  • npx jest shell/menus/LinkMenuItem.test.tsx: 31 of 31 pass.
  • Every variant covers the four cases above, using getByRole('link', { name }).
  • Every variant covers an internal route (role: accountRole) with target="_blank". This confirms that react-router's Link forwards both attributes to the <a>.
  • eslint is clean on the changed files.
  • npm run typecheck reports no errors in the changed files.

Notes for reviewers

  • The hyperlink variant differs from the header in three ways, all from Paragon's Hyperlink (v23.18.1):

    • It renders target="_self" when no target is set. This is already the case on main.
    • On _blank links, it adds noopener noreferrer to any explicit rel, so rel="noopener" becomes noopener noreferrer.
    • On _blank links, it adds a new-tab icon and "in a new tab" screen-reader text to the link's accessible name.

    These are as safe or safer than the header's behavior. The tests record them in a per-variant expected table.

  • Type cast: Paragon types Hyperlink's target as '_blank' | '_self', but any value reaches the anchor at runtime. The Hyperlink call site casts target, with a comment explaining why.

  • Compatibility: the change is additive and non-breaking under ADR 0018 (docs/decisions/0018-app-breaking-changes.rst). Both props are optional, and callers that don't pass them render as before.

  • Unchanged callers: ProfileLinkMenuItem and HelpButton don't forward or set the new props. Their behavior is unchanged.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Nov 17, 2026
@openedx-webhooks

openedx-webhooks commented Nov 17, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @jacobo-dominguez-wgu!

This repository is currently maintained by @openedx/axim-engineering.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 17, 2026
@jacobo-dominguez-wgu
jacobo-dominguez-wgu marked this pull request as ready for review November 17, 2026 18:51
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Nov 24, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Nov 24, 2026
url?: string;
variant?: 'hyperlink' | 'navLink' | 'navDropdownItem' | 'dropdownItem';
/** Where to open the link, such as `_blank` for a new tab. */
target?: React.HTMLAttributeAnchorTarget;

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'd add screen-reader-only "opens in a new tab" text to the other three variants when target is _blank, with a new message in Shell.messages.ts.

Right now only hyperlink warns screen reader users, and the issue's own case is a dropdown item, which stays silent. shell/menus/LinkMenuItem.tsx:61-78

Comment on lines +48 to +50
// Default rel for new tabs to protect against reverse tabnabbing: without noopener, the
// opened page gets a window.opener handle and can redirect this one.
rel: rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined),

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'd drop the default rel and pass through whatever the caller gives.

Supported browsers already treat _blank as noopener, so the default only adds noreferrer, which hides where the user came from, even on the same site. If parity with the header PR matters more, at least fix the comment.

<Hyperlink {...linkProps}>
// Paragon types Hyperlink's target as '_blank' | '_self', but it passes any value through to
// the anchor.
<Hyperlink {...linkProps} target={target as ComponentProps<typeof Hyperlink>['target']}>

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'd move the cast into the shared link props and drop the extra prop on Hyperlink.

The extra prop overrides the spread, so a later change to how target is set would quietly skip this variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

4 participants