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

772 set href as a required prop and as the default value for children #776

Merged
merged 18 commits into from
Mar 17, 2020

Conversation

HammadTheOne
Copy link
Collaborator

This PR addresses #772 and #773. The href prop is marked as required, and if no children prop is defined, the href is set as the children by default. As @Marc-Andre-Rivet pointed out, this will simplify usage, and makes more sense for the dcc.Link component as a whole.

  • Updated changelog
  • Added a basic integration test

Any suggestions on how to better structure the conditional are welcome, would it perhaps be better to set the children directly in the return function (maybe as a ternary operator) instead of as a separate named function?

Closes #772
Closes #773

'''
return document.getElementById("link1").text;
'''
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dash_dcc.wait_for_text_to_equal("#link1", "/page-1")

Copy link
Collaborator Author

@HammadTheOne HammadTheOne Mar 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 4537402.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That statement replaces the whole href_as_children = ... and assert href_as_children == ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that method acts as a wrapper of sorts to check the text? Interesting. Updated in da999d5.

{this.props.children}
{isNil(this.props.children)
? this.props.href
: this.props.children}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're golfing - add children to the destructuring of this.props above (href is already there) and this collapses to just {isNil(children) ? href : children}

That's a nicer pattern anyway, as it shows up front what props get used during the render.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, destructuring does look cleaner. Updated in 065c462.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful! 💃

html.Div(id="content")
]
)
@app.callback(Output("content", "children"), [Input("link1", "children")])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this callback and content Div do anything in this test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another simple test checking that children are indeed children when defined

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 5eac66e.

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question about the test and suggested addition for completeness.

html.Div(id="content")
]
)
@app.callback(Output("content", "children"), [Input("link1", "children")])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another simple test checking that children are indeed children when defined

@HammadTheOne HammadTheOne merged commit c0ec446 into dev Mar 17, 2020
@HammadTheOne HammadTheOne deleted the 772-link-default-children branch March 17, 2020 21:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark dcc.Link href prop as required dcc.Link: Use href as children if no children are defined
3 participants