Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

dcc.Location props fix for callbacks #774

Merged
merged 11 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- [#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, and added a target prop.
- [#774](https://github.com/plotly/dash-core-components/pull/774) Fixed dcc.Location firing callbacks for wrong property.

## [1.8.1] -2020-02-27
### Added
Expand Down
22 changes: 16 additions & 6 deletions src/components/Location.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ export default class Location extends Component {

onLocationChange() {
const {setProps} = this.props;
setProps({
pathname: window.location.pathname,
href: window.location.href,
hash: window.location.hash,
search: window.location.search,
});
const propsToChange = {};

if (this.props.pathname !== window.location.pathname) {
propsToChange.pathname = window.location.pathname;
}
if (this.props.href !== window.location.href) {
propsToChange.href = window.location.href;
}
if (this.props.hash !== window.location.hash) {
propsToChange.hash = window.location.hash;
}
if (this.props.search !== window.location.search) {
propsToChange.search = window.location.search;
}

setProps(propsToChange);

History.dispatchChangeEvent();
}
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/location/test_location_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html


@pytest.mark.DCC774
def test_loca001_callbacks(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Location(
id='location',
refresh=False
),
html.A('Anchor Link 1', href='#div'),
html.Div(id='div')
])

@app.callback(Output('div', 'children'), [Input('location', 'pathname')])
def update_path(path):
return path

dash_dcc.start_server(app)

dash_dcc.wait_for_text_to_equal('#div', '/')