Skip to content
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

fix: nav link target #166

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/navigation/GlobalNavigation/NavigationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface INavigationItemProps {
isActive?: boolean
onClick?: (e: MouseEvent) => void // link only
href?: string // link only
hrefTarget?: '_self' | '_blank' // link only
Copy link
Collaborator

@tibuurcio tibuurcio Mar 22, 2024

Choose a reason for hiding this comment

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

Could we make this into the href property itself? Something like this example. We won't need hrefTarget to be defined without href so it seems like a good case for that. The less props we have the better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

interesting! i like it, but i dont like as much the normalizeLabel method they need to create (thats not mentioned anywhere else)

what about using hrefOptions?: { link: string, target?: '_self' | '_blank' }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems okay, I would only change link for href maybe, to keep it consistent with the HTML option. Not ideal having hrefOptions and href again inside of it but would be ok with that.

Copy link
Collaborator

@tibuurcio tibuurcio Mar 22, 2024

Choose a reason for hiding this comment

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

That's also a breaking change for the current platforms, so one drawback of using it like you suggested. I think that's fine for the moment we are but future updates should account for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is true its a breaking change for the prop, but, none of the platforms currently use this [analytics is on 1.8.2, cdp is on 1.7.9, cortex on 1.7.9] so not a real issue for us now

}

export function NavigationItem(props: INavigationItemProps) {
Expand All @@ -31,7 +32,16 @@ export function NavigationItem(props: INavigationItemProps) {
/>
)

const resultNavigationIcon = props.href ? <a href={props.href}>{navigationIcon}</a> : navigationIcon
const resultNavigationIcon = props.href ? (
<a
href={props.href}
target={props.hrefTarget ?? '_self'}
rel={props.hrefTarget === '_blank' ? 'noopener' : undefined}>
{navigationIcon}
</a>
) : (
navigationIcon
)

if (props.hideLabel) {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/navigation/Steps/Steps.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,4 @@ export const ExampleInline: Story = {
</ExampleStory>
)
},
}
}
Loading