Skip to content

Commit

Permalink
fix: move launch icon logic to Anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrekim committed Nov 28, 2023
1 parent fd42b41 commit 127c242
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/dnb-eufemia/src/components/anchor/Anchor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ export function AnchorInstance(localProps: AnchorAllProps) {
let suffix: React.ReactNode

const href = allProps.href || allProps.to
const showLaunchIcon =
allProps.target === '_blank' && !/^(mailto|tel|sms)/.test(href)
const showLaunchIcon = opensNewTab(allProps.target, href)
const showTooltip = (tooltip || showLaunchIcon) && !allProps.title

// WCAG guide: https://www.w3.org/TR/WCAG20-TECHS/G201.html
Expand Down Expand Up @@ -205,3 +204,6 @@ export function pickIcon(icon) {
})
: null
}

export const opensNewTab = (target: string, href: string): boolean =>
target === '_blank' && !/^(mailto|tel|sms)/.test(href)
8 changes: 2 additions & 6 deletions packages/dnb-eufemia/src/components/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { pickFormElementProps } from '../../shared/helpers/filterValidProps'
import IconPrimary from '../icon-primary/IconPrimary'
import FormStatus from '../form-status/FormStatus'
import Anchor, { pickIcon } from '../anchor/Anchor'
import Anchor, { pickIcon, opensNewTab } from '../anchor/Anchor'
import { launch } from '../../icons'
import Tooltip from '../tooltip/Tooltip'

Expand Down Expand Up @@ -182,11 +182,7 @@ export default class Button extends React.PureComponent {
: 'button'
if (Element === Anchor) {
attributes.omitClass = true
if (
props.target === '_blank' &&
!/^(mailto|tel|sms)/.test(props.href) &&
!icon
) {
if (opensNewTab(props.target, props.href) && !icon) {
icon = launch
}
}
Expand Down

0 comments on commit 127c242

Please sign in to comment.