-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! One suggestion, but not needed:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not needed. That condition would be redundant, as |
||||||
const Element = hasHref ? 'a' : 'button' | ||||||
const containerId = `${id}-container` | ||||||
return ( | ||||||
<> | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
> | ||||||
<span aria-hidden>{icon}</span> | ||||||
<span>{text}</span> | ||||||
|
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.