feat: add external prop to dropdown menu#648
Conversation
✅ Deploy Preview for pine-design-system ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@coderabbitai review this pr |
🧩 Analysis chain
🏁 Script executed: Length of output: 24141 Let me examine the complete 🏁 Script executed: Length of output: 5766
🔴 Critical Security IssueMissing The
Recommended Fix: In render() {
const targetValue = this.target || (this.external ? '_blank' : undefined);
const showExternalIcon = targetValue === '_blank';
const relValue = targetValue === '_blank' ? 'noopener noreferrer' : undefined;
return (
<a
class={this.classNames()}
href={this.href}
id={this.componentId}
part="link"
target={targetValue}
rel={relValue}
style={this.setLinkStyles()}
>
<slot>{this.href}</slot>
{showExternalIcon &&
<pds-icon icon={launch} size={this.fontSize}></pds-icon>
}
</a>
);
}✅ Positive Observations
📝 Additional Recommendations
it('sets rel="noopener noreferrer" when target is _blank', async () => {
const { root } = await newSpecPage({
components: [PdsLink],
html: `<pds-link href="https://example.com" target="_blank">Link</pds-link>`,
});
const linkElement = root?.shadowRoot?.querySelector('a');
expect(linkElement?.getAttribute('rel')).toBe('noopener noreferrer');
});
SummaryThe feature implementation is solid, but the security vulnerability with ✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis pull request extends link-opening behavior across the PdsLink and PdsDropdownMenuItem components. PdsLink gains a new optional 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@libs/core/src/components/pds-dropdown-menu/pds-dropdown-menu-item/readme.md`:
- Around line 13-14: Update the README table rows for the `destructive` and
`disabled` props to tighten wording by replacing "whether or not the
dropdown-item is destructive/disabled" with "whether the dropdown-item is
destructive/disabled"; edit the descriptions for the `destructive` and
`disabled` entries accordingly to use "whether" instead of "whether or not".
In `@libs/core/src/components/pds-link/pds-link.tsx`:
- Around line 88-104: In render(), when computing targetValue (const targetValue
= this.target || (this.external ? '_blank' : undefined)) ensure you also add
rel="noopener noreferrer" to the anchor only when targetValue === '_blank' to
prevent tabnabbing; update the <a> element rendered by the pds-link component to
conditionally include a rel attribute (e.g., compute a relValue and pass it as
rel={relValue}) while keeping existing classNames(), href, id, part, target and
style usage and preserving showExternalIcon logic for the <pds-icon>.
libs/core/src/components/pds-dropdown-menu/pds-dropdown-menu-item/readme.md
Show resolved
Hide resolved
pixelflips
left a comment
There was a problem hiding this comment.
A couple of small nitpicks, otherwise nice work!
libs/core/src/components/pds-dropdown-menu/pds-dropdown-menu-item/pds-dropdown-menu-item.tsx
Outdated
Show resolved
Hide resolved
libs/core/src/components/pds-dropdown-menu/pds-dropdown-menu-item/pds-dropdown-menu-item.tsx
Outdated
Show resolved
Hide resolved
libs/core/src/components/pds-dropdown-menu/pds-dropdown-menu-item/pds-dropdown-menu-item.tsx
Outdated
Show resolved
Hide resolved
|
|
||
| ### Target | ||
|
|
||
| The `target` prop specifies where to open the linked document. This provides more control than the `external` prop and supports all standard target values (`_blank`, `_self`, `_parent`, `_top`). When set to `_blank`, it automatically shows the external icon. |
There was a problem hiding this comment.
Should we always assume a new tab means it's external? I think external should handle the icon.
Description
Adds support for
externalandtargetprops topds-dropdown-menu-itemto enable proper external link behavior in dropdown menus.Problem
The
pds-dropdown-menu-itemcomponent wasn't passingtargetorexternalattributes through to the internal link element in its shadow DOM. When developers settarget="_blank"on a dropdown menu item (e.g., for "Preview" links in data tables), the attribute was applied to the host element but ignored by the actual<a>tag inside the shadow root, causing all links to open in the same tab.Solution
Added two complementary props that pass through to the internal
pds-linkcomponent:external(boolean) - Simpler API for the common case of opening in new tab (recommended)target(string) - Explicit control for all target values (_blank,_self,_parent,_top)Both approaches work, with
targettaking precedence when both are set.Components Modified
pds-dropdown-menu-item: Addedexternalandtargetpropspds-link: Addedtargetprop (already hadexternal)Fixes DSS-97
Type of change
How Has This Been Tested?
Visit the pds-dropdown-menu page to verify
Test Configuration:
Checklist:
If not applicable, leave options unchecked.