Skip to content

Commit f8d3d93

Browse files
committed
Added click modifiers, target prop (plotly#767)
* Added `ctrlKey` conditional * Added other modifiers. * Added target prop.
1 parent def09fd commit f8d3d93

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/dash-core-components/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
- [#766](https://github.com/plotly/dash-core-components/pull/766) Update from React 16.8.6 to 16.13.0
88
- [#768](https://github.com/plotly/dash-core-components/pull/768) Added title property to dcc.Link
99
- [#776](https://github.com/plotly/dash-core-components/pull/776) Update dcc.Link to set href as children if children not defined. Makes href a required prop as well.
10+
- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers, and added a target prop.
1011

1112
## [1.8.1] -2020-02-27
1213
### Added

packages/dash-core-components/src/components/Link.react.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ export default class Link extends Component {
4242
}
4343

4444
updateLocation(e) {
45+
const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey;
46+
const {href, refresh, target} = this.props;
47+
48+
if (hasModifiers) {
49+
return;
50+
}
51+
if (target !== '_self' && !isNil(target)) {
52+
return;
53+
}
4554
// prevent anchor from updating location
4655
e.preventDefault();
47-
const {href, refresh} = this.props;
4856
if (refresh) {
4957
window.location.pathname = href;
5058
} else {
@@ -64,6 +72,7 @@ export default class Link extends Component {
6472
loading_state,
6573
children,
6674
title,
75+
target,
6776
} = this.props;
6877
/*
6978
* ideally, we would use cloneElement however
@@ -81,6 +90,7 @@ export default class Link extends Component {
8190
href={href}
8291
onClick={e => this.updateLocation(e)}
8392
title={title}
93+
target={target}
8494
>
8595
{isNil(children) ? href : children}
8696
</a>
@@ -116,6 +126,10 @@ Link.propTypes = {
116126
* information.
117127
*/
118128
title: PropTypes.string,
129+
/**
130+
* Specifies where to open the link reference.
131+
*/
132+
target: PropTypes.string,
119133
/**
120134
* The children of this component
121135
*/

0 commit comments

Comments
 (0)