Skip to content

Commit e46e106

Browse files
authored
Allow target to be set on Button with href (#781)
1 parent 9606086 commit e46e106

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/components/button/Button.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ const Button = props => {
4444
const useLink = href && !disabled;
4545
otherProps[useLink ? 'preOnClick' : 'onClick'] = onClick || incrementClicks;
4646

47+
if (useLink) {
48+
// react-bootstrap strips out target prop if tag isn't an anchor element,
49+
// so we pass it through under a different name
50+
otherProps['linkTarget'] = target;
51+
}
52+
4753
return (
4854
<RBButton
4955
as={useLink ? Link : 'button'}
5056
variant={outline ? `outline-${color}` : color}
51-
type={useLink ? null : type}
52-
target={useLink ? target : null}
53-
href={disabled ? null : href}
57+
type={useLink ? undefined : type}
58+
href={disabled ? undefined : href}
5459
disabled={disabled}
55-
download={useLink ? download : null}
56-
name={useLink ? null : name}
57-
value={useLink ? null : value}
60+
download={useLink ? download : undefined}
61+
name={useLink ? undefined : name}
62+
value={useLink ? undefined : value}
5863
className={class_name || className}
5964
{...omit(['n_clicks_timestamp'], otherProps)}
6065
data-dash-is-loading={

src/private/Link.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Link extends Component {
6767
external_link,
6868
preOnClick,
6969
target,
70+
linkTarget,
7071
href,
7172
download,
7273
...otherProps
@@ -80,8 +81,8 @@ class Link extends Component {
8081
return (
8182
<a
8283
href={href}
83-
target={linkIsExternal ? target : null}
84-
download={download && linkIsExternal ? download : null}
84+
target={linkIsExternal ? target || linkTarget : undefined}
85+
download={download && linkIsExternal ? download : undefined}
8586
{...otherProps}
8687
onClick={e => this.updateLocation(e)}
8788
>

0 commit comments

Comments
 (0)