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(AppMenuItem): Make app menu external links open in new browser tab. #1022

Merged
merged 2 commits into from
Oct 6, 2023

Conversation

binh-dam-ibigroup
Copy link
Collaborator

@binh-dam-ibigroup binh-dam-ibigroup commented Oct 4, 2023

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:

  • Does the code follow accessibility standards (WCAG 2.1 AA Compliant)?
  • Are all languages supported (Internationalization/Localization)?
  • Are appropriate Typescript types implemented?

Copy link
Contributor

@amy-corson-ibigroup amy-corson-ibigroup left a 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')
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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')
Copy link
Member

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:

Suggested change
const isAbsolute = otherProps.href?.startsWith('http')
const isAbsolute = hasHref && otherProps.href?.startsWith('http')

Copy link
Collaborator Author

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.hrefis 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}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
target={hasHref && isAbsolute ? '_blank' : undefined}
target={isAbsolute ? '_blank' : undefined}

@binh-dam-ibigroup binh-dam-ibigroup merged commit 0896680 into dev Oct 6, 2023
7 checks passed
@binh-dam-ibigroup binh-dam-ibigroup deleted the app-menu-ext-links branch October 6, 2023 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants