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

dcc.Link: Use href as children if no children are defined #772

Closed
Marc-Andre-Rivet opened this issue Mar 11, 2020 · 5 comments · Fixed by #776
Closed

dcc.Link: Use href as children if no children are defined #772

Marc-Andre-Rivet opened this issue Mar 11, 2020 · 5 comments · Fixed by #776

Comments

@Marc-Andre-Rivet
Copy link
Contributor

With HTML anchors, users are forced to provide a displayed content for the anchor, which can be as simple as the href itself..

<a href='myurl'>myurl</a>

1:1 correspondance in dcc.Link forces users to do the same thing:

dcc.Link(
  href='myurl',
  children=['myurl']
)

Defaulting to href for inner content if no children is defined provides a default behavior that will be acceptable in certain situations and will simplify usage.

@alexcjohnson
Copy link
Collaborator

Perhaps the other way as well, use children as href - that way you can do dcc.Link(myurl) and it'll behave reasonably.

@Marc-Andre-Rivet
Copy link
Contributor Author

Marc-Andre-Rivet commented Mar 11, 2020

It's possible to use anything as a dcc.Link child and the whole thing becomes clickable, so while href is a string and can be used safely as a child, the same can't be said about children.

    dcc.Link(
        href='/sub-path',
        refresh=True,
        children=[html.Div('Hello'), html.Div('World')]
    ),

@alexcjohnson
Copy link
Collaborator

sure, but if children happens to be just a string, we might as well copy it back to href.

@Marc-Andre-Rivet
Copy link
Contributor Author

Marc-Andre-Rivet commented Mar 11, 2020

Yes. But it lends itself to a if..else.. logic that can be confusing for a user. The href being guaranteed to be there and to be a string, it does not suffer from the same limitations / branching. Not opposed per-say, just want to make sure we agree on the limitations / logic leakage if we decide to support it.

Side-note: href is not currently required. A dcc.Link without href makes no sense, I propose to mark it as isRequired / the old behavior being considered a bug, not a breaking change.

@alexcjohnson
Copy link
Collaborator

Fair enough - and it could be confusing if you start with just children and want to switch to different text/elements - you have to make two changes: move the children string into href and then provide the new children. Then we can also do #773 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants