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

Commit c0ec446

Browse files
authored
772 set href as a required prop and as the default value for children (#776)
* Conditionally set children as href * 773 - Make href a required prop * Updated changelog * Added basic integration test
1 parent eb4c98e commit c0ec446

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
66
### Changed
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
9-
9+
- [#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

1111
## [1.8.1] -2020-02-27
1212
### Added

src/components/Link.react.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
44

55
import React, {Component} from 'react';
66

7+
import {isNil} from 'ramda';
8+
79
/*
810
* event polyfill for IE
911
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
@@ -54,7 +56,15 @@ export default class Link extends Component {
5456
}
5557

5658
render() {
57-
const {className, style, id, href, title, loading_state} = this.props;
59+
const {
60+
className,
61+
style,
62+
id,
63+
href,
64+
loading_state,
65+
children,
66+
title,
67+
} = this.props;
5868
/*
5969
* ideally, we would use cloneElement however
6070
* that doesn't work with dash's recursive
@@ -72,7 +82,7 @@ export default class Link extends Component {
7282
onClick={e => this.updateLocation(e)}
7383
title={title}
7484
>
75-
{this.props.children}
85+
{isNil(children) ? href : children}
7686
</a>
7787
);
7888
}
@@ -88,7 +98,7 @@ Link.propTypes = {
8898
/**
8999
* The URL of a linked resource.
90100
*/
91-
href: PropTypes.string,
101+
href: PropTypes.string.isRequired,
92102
/**
93103
* Controls whether or not the page will refresh when the link is clicked
94104
*/
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.DCC776
9+
def test_lich001_default(dash_dcc):
10+
app = dash.Dash(__name__)
11+
app.layout = html.Div(
12+
[
13+
dcc.Link(id="link1", href="/page-1"),
14+
dcc.Location(id="url", refresh=False),
15+
html.Div(id="content")
16+
]
17+
)
18+
dash_dcc.start_server(app)
19+
20+
dash_dcc.wait_for_text_to_equal("#link1", "/page-1")
21+
22+
23+
@pytest.mark.DCC776
24+
def test_lich002_children(dash_dcc):
25+
app = dash.Dash(__name__)
26+
app.layout = html.Div(
27+
[
28+
dcc.Link(children='test children', id="link1", href="/page-1"),
29+
dcc.Location(id="url", refresh=False),
30+
html.Div(id="content")
31+
]
32+
)
33+
@app.callback(Output("content", "children"), [Input("link1", "children")])
34+
def display_children(children):
35+
return children
36+
37+
dash_dcc.start_server(app)
38+
39+
dash_dcc.wait_for_text_to_equal("#content", "test children")

0 commit comments

Comments
 (0)