Skip to content

Commit 022897f

Browse files
committed
dcc.Location props fix for callbacks (plotly#774)
* Added conditionally set props * Updated changelog. * Added integration test to check callbacks
1 parent f8d3d93 commit 022897f

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

packages/dash-core-components/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
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.
1010
- [#767](https://github.com/plotly/dash-core-components/pull/767) Updated dcc.Link to respond to click modifiers, and added a target prop.
11+
- [#774](https://github.com/plotly/dash-core-components/pull/774) Fixed dcc.Location firing callbacks for wrong property.
1112

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

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

+16-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,22 @@ export default class Location extends Component {
8686

8787
onLocationChange() {
8888
const {setProps} = this.props;
89-
setProps({
90-
pathname: window.location.pathname,
91-
href: window.location.href,
92-
hash: window.location.hash,
93-
search: window.location.search,
94-
});
89+
const propsToChange = {};
90+
91+
if (this.props.pathname !== window.location.pathname) {
92+
propsToChange.pathname = window.location.pathname;
93+
}
94+
if (this.props.href !== window.location.href) {
95+
propsToChange.href = window.location.href;
96+
}
97+
if (this.props.hash !== window.location.hash) {
98+
propsToChange.hash = window.location.hash;
99+
}
100+
if (this.props.search !== window.location.search) {
101+
propsToChange.search = window.location.search;
102+
}
103+
104+
setProps(propsToChange);
95105

96106
History.dispatchChangeEvent();
97107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
import dash
3+
from dash.dependencies import Input, Output
4+
import dash_core_components as dcc
5+
import dash_html_components as html
6+
7+
8+
@pytest.mark.DCC774
9+
def test_loca001_callbacks(dash_dcc):
10+
app = dash.Dash(__name__)
11+
app.layout = html.Div([
12+
dcc.Location(
13+
id='location',
14+
refresh=False
15+
),
16+
html.A('Anchor Link 1', href='#div'),
17+
html.Div(id='div')
18+
])
19+
20+
@app.callback(Output('div', 'children'), [Input('location', 'pathname')])
21+
def update_path(path):
22+
return path
23+
24+
dash_dcc.start_server(app)
25+
26+
dash_dcc.wait_for_text_to_equal('#div', '/')

0 commit comments

Comments
 (0)