-
Notifications
You must be signed in to change notification settings - Fork 53
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(AppMenuItem): Make app menu external links open in new browser tab. #1022
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a url gets passed without an http should it still open a new browser tab?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it would be a relative URL (like the route viewer or another resource), but that's a good question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, relative URLs open in the same window per PR description.
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One suggestion, but not needed:
const isAbsolute = otherProps.href?.startsWith('http') | |
const isAbsolute = hasHref && otherProps.href?.startsWith('http') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not needed. That condition would be redundant, as otherProps.href?.startsWith(...)
is null if otherProps.href
is null, and can't be non-null unless otherProps.href
is non null. Same for your other suggestion.
@@ -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} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target={hasHref && isAbsolute ? '_blank' : undefined} | |
target={isAbsolute ? '_blank' : undefined} |
Description
This PR makes external links in the app menu open in a new browser tab.
There are no changes to external link configurations.
(Relative links would still open in the same window.)
PR Checklist: