Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

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

Closed

Description

@Marc-Andre-Rivet

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.

Activity

  1. added this to the Dash v1.10 milestone on Mar 11, 2020
  2. alexcjohnson commented on Mar 11, 2020

    @alexcjohnson
    Collaborator

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

  3. Marc-Andre-Rivet commented on Mar 11, 2020

    @Marc-Andre-Rivet
    ContributorAuthor

    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')]
        ),
    
  4. alexcjohnson commented on Mar 11, 2020

    @alexcjohnson
    Collaborator

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

  5. Marc-Andre-Rivet commented on Mar 11, 2020

    @Marc-Andre-Rivet
    ContributorAuthor

    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.

  6. alexcjohnson commented on Mar 11, 2020

    @alexcjohnson
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions