Skip to content

Commit

Permalink
Merge pull request #1022 from opentripplanner/app-menu-ext-links
Browse files Browse the repository at this point in the history
fix(AppMenuItem): Make app menu external links open in new browser tab.
  • Loading branch information
binh-dam-ibigroup authored Oct 6, 2023
2 parents 0537e10 + 72d84a3 commit 0896680
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/components/app/app-menu-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export default class AppMenuItem extends Component<Props, State> {
render(): JSX.Element {
const { icon, id, onClick, subItems, text, ...otherProps } = this.props
const { isExpanded } = this.state
const Element = otherProps.href ? 'a' : 'button'
const hasHref = !!otherProps.href
const isAbsolute = otherProps.href?.startsWith('http')
const Element = hasHref ? 'a' : 'button'
const containerId = `${id}-container`
return (
<>
Expand All @@ -80,6 +82,7 @@ export default class AppMenuItem extends Component<Props, State> {
onClick={subItems ? this._toggleSubmenu : onClick}
onKeyDown={this._handleKeyDown}
{...otherProps}
target={hasHref && isAbsolute ? '_blank' : undefined}
>
<span aria-hidden>{icon}</span>
<span>{text}</span>
Expand Down

0 comments on commit 0896680

Please sign in to comment.