From c9569901dca906b41e41c2a6dab293105856437e Mon Sep 17 00:00:00 2001 From: HammadTheOne <30986043+HammadTheOne@users.noreply.github.com> Date: Fri, 6 Mar 2020 16:13:19 -0500 Subject: [PATCH 01/11] Added `ctrlKey` conditional --- src/components/Link.react.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index 6839bc2b9..cef8fc49b 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -43,6 +43,9 @@ export default class Link extends Component { // prevent anchor from updating location e.preventDefault(); const {href, refresh} = this.props; + if (e.ctrlKey) { + window.open(href, '_blank'); + } if (refresh) { window.location.pathname = href; } else { From 7eab20154791b8b780f577b09e9b26cd1b555bb1 Mon Sep 17 00:00:00 2001 From: HammadTheOne <30986043+HammadTheOne@users.noreply.github.com> Date: Fri, 6 Mar 2020 16:46:08 -0500 Subject: [PATCH 02/11] Added other modifiers. --- src/components/Link.react.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index cef8fc49b..c9b75d5bf 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -40,12 +40,17 @@ export default class Link extends Component { } updateLocation(e) { + const hasModifiers = ( + e.metaKey || + e.shiftKey || + e.altKey || + e.ctrlKey + ); + + if (hasModifiers || e.button !== 1) {return}; // prevent anchor from updating location e.preventDefault(); const {href, refresh} = this.props; - if (e.ctrlKey) { - window.open(href, '_blank'); - } if (refresh) { window.location.pathname = href; } else { From 977cf28b56b308c5407da338547559f6ad5a3588 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Sun, 15 Mar 2020 01:42:13 -0400 Subject: [PATCH 03/11] Fixed formatting --- src/components/Link.react.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index c9b75d5bf..ac5674384 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -40,14 +40,11 @@ export default class Link extends Component { } updateLocation(e) { - const hasModifiers = ( - e.metaKey || - e.shiftKey || - e.altKey || - e.ctrlKey - ); + const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey; - if (hasModifiers || e.button !== 1) {return}; + if (hasModifiers || e.button !== 1) { + return; + } // prevent anchor from updating location e.preventDefault(); const {href, refresh} = this.props; From 0e4ac7f560fd7af969556e68305f0c50cfc4b657 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Sun, 15 Mar 2020 01:44:35 -0400 Subject: [PATCH 04/11] Added changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c48cd564e..556d756bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Changed - [#766](https://github.com/plotly/dash-core-components/pull/766) Update from React 16.8.6 to 16.13.0 - +- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers. ## [1.8.1] -2020-02-27 ### Added From d5f0b3893c541348555d53634fe920c5efa3f7f1 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Mon, 16 Mar 2020 18:41:27 -0400 Subject: [PATCH 05/11] Updated changelog message --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 556d756bd..c6e1814a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Changed - [#766](https://github.com/plotly/dash-core-components/pull/766) Update from React 16.8.6 to 16.13.0 -- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers. +- [#767](https://github.com/plotly/dash-core-components/pull/767) Update dcc.Link to respond to click modifiers. ## [1.8.1] -2020-02-27 ### Added From af01beb66ef5df599d42506c8f2250e3ce75f442 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Tue, 17 Mar 2020 13:32:53 -0400 Subject: [PATCH 06/11] Noise commit --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6e1814a3..556d756bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Changed - [#766](https://github.com/plotly/dash-core-components/pull/766) Update from React 16.8.6 to 16.13.0 -- [#767](https://github.com/plotly/dash-core-components/pull/767) Update dcc.Link to respond to click modifiers. +- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers. ## [1.8.1] -2020-02-27 ### Added From ec0b49c602b528fc368371c9bec2d1516adf3701 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Tue, 17 Mar 2020 22:01:04 -0400 Subject: [PATCH 07/11] Added external prop --- src/components/Link.react.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index 77414cf2a..052f68687 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -69,6 +69,7 @@ export default class Link extends Component { loading_state, children, title, + external, } = this.props; /* * ideally, we would use cloneElement however @@ -86,6 +87,7 @@ export default class Link extends Component { href={href} onClick={e => this.updateLocation(e)} title={title} + target={external ? '_blank' : '_self'} > {isNil(children) ? href : children} @@ -121,6 +123,10 @@ Link.propTypes = { * information. */ title: PropTypes.string, + /** + * Opens the link in a new tab. + */ + external: PropTypes.bool, /** * The children of this component */ @@ -146,4 +152,5 @@ Link.propTypes = { Link.defaultProps = { refresh: false, + external: false, }; From 6514c8350823c4827ef0f1a17277e70c23fec64b Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Tue, 17 Mar 2020 22:36:58 -0400 Subject: [PATCH 08/11] Changed external to target --- src/components/Link.react.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index 052f68687..9a13185b8 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -44,7 +44,7 @@ export default class Link extends Component { updateLocation(e) { const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey; - if (hasModifiers || e.button !== 1) { + if (hasModifiers || event.button !== 1) { return; } // prevent anchor from updating location @@ -69,7 +69,7 @@ export default class Link extends Component { loading_state, children, title, - external, + target, } = this.props; /* * ideally, we would use cloneElement however @@ -87,7 +87,7 @@ export default class Link extends Component { href={href} onClick={e => this.updateLocation(e)} title={title} - target={external ? '_blank' : '_self'} + target={target} > {isNil(children) ? href : children} @@ -124,9 +124,9 @@ Link.propTypes = { */ title: PropTypes.string, /** - * Opens the link in a new tab. + * Specifies where to open the link reference. */ - external: PropTypes.bool, + target: PropTypes.string, /** * The children of this component */ @@ -152,5 +152,4 @@ Link.propTypes = { Link.defaultProps = { refresh: false, - external: false, }; From ec1cae4ec9a95fba41217d67ece71ad5a0ce8d6c Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Tue, 17 Mar 2020 23:30:05 -0400 Subject: [PATCH 09/11] Change conditional for tests --- src/components/Link.react.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index 9a13185b8..b99630cfb 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -44,7 +44,7 @@ export default class Link extends Component { updateLocation(e) { const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey; - if (hasModifiers || event.button !== 1) { + if (hasModifiers) { return; } // prevent anchor from updating location From 7beb7d92b8da9188411b63b49a099fdc9b5b3d31 Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Wed, 18 Mar 2020 21:19:12 -0400 Subject: [PATCH 10/11] Fixed target prop --- src/components/Link.react.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Link.react.js b/src/components/Link.react.js index b99630cfb..72fe2f1c2 100644 --- a/src/components/Link.react.js +++ b/src/components/Link.react.js @@ -43,13 +43,16 @@ export default class Link extends Component { updateLocation(e) { const hasModifiers = e.metaKey || e.shiftKey || e.altKey || e.ctrlKey; + const {href, refresh, target} = this.props; if (hasModifiers) { return; } + if (target !== '_self' && !isNil(target)) { + return; + } // prevent anchor from updating location e.preventDefault(); - const {href, refresh} = this.props; if (refresh) { window.location.pathname = href; } else { From 8434ddafd97348cdeb8f2f99912b892df7af69eb Mon Sep 17 00:00:00 2001 From: hammadtheone Date: Wed, 18 Mar 2020 21:49:32 -0400 Subject: [PATCH 11/11] Updated changelog, flaky test run --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 062172b60..13195ebe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - [#766](https://github.com/plotly/dash-core-components/pull/766) Update from React 16.8.6 to 16.13.0 - [#768](https://github.com/plotly/dash-core-components/pull/768) Added title property to dcc.Link - [#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. -- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers. +- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers, and added a target prop. ## [1.8.1] -2020-02-27 ### Added