Skip to content

EuiBadge should allow for href #2831

Description

@cchaos

Currently it only accepts onClick but badges can also link to other pages as well. It should accept href similar to EuiButton.

Activity

  1. cchaos commented on Feb 19, 2020

    @cchaos
    ContributorAuthor

    Hi @aryamanpuri , yes please do! Essentially the component needs to accept an href prop and then output the right html element.

    • If the consumer passes an href the component should render as link tag <a>
    • If the consumer passes an onClick the component should render as a button tag <button>

    You can essentially look at how EuiButton handles the render:

    // <a> elements don't respect the `disabled` attribute. So if we're disabled, we'll just pretend
    // this is a button and piggyback off its disabled styles.
    if (href && !isDisabled) {
    const secureRel = getSecureRelForTarget({ href, target, rel });
    return (
    <a
    className={classes}
    href={href}
    target={target}
    rel={secureRel}
    ref={buttonRef as Ref<HTMLAnchorElement>}
    {...rest as AnchorHTMLAttributes<HTMLAnchorElement>}>
    {innerNode}
    </a>
    );
    }
    let buttonType: ButtonHTMLAttributes<HTMLButtonElement>['type'];
    return (
    <button
    disabled={isDisabled}
    className={classes}
    type={type as typeof buttonType}
    ref={buttonRef as Ref<HTMLButtonElement>}
    {...rest as ButtonHTMLAttributes<HTMLButtonElement>}>
    {innerNode}
    </button>

    And we have two helper services for the TS types you can reuse similar to EuiButton here:

    type EuiButtonPropsForAnchor = PropsForAnchor<
    EuiButtonProps,
    {
    buttonRef?: Ref<HTMLAnchorElement>;
    }
    >;
    type EuiButtonPropsForButton = PropsForButton<
    EuiButtonProps,
    {
    buttonRef?: Ref<HTMLButtonElement>;
    }
    >;
    export type Props = ExclusiveUnion<
    EuiButtonPropsForAnchor,
    EuiButtonPropsForButton
    >;

    Be sure to check the whole file as not everything was captured in those permalinks.

    Thanks!

  2. shakti97 commented on Feb 21, 2020

    @shakti97

    may I work on this?

  3. shakti97 commented on Feb 21, 2020

    @shakti97

    I checked the code, button component is already sufficient to handle render of anchor or button based on the href prop, so just I need to add the optional href in the badge prop and add it to the button .
    @cchaos please correct me if I m going wrong.

  4. cchaos commented on Feb 21, 2020

    @cchaos
    ContributorAuthor

    The EuiButton component does correclty handle this situation, but we essentially need to translate that same type of code to EuiBadge to handle it as well since EuiBadge does not extend EuiButton.

  5. RisingGeek commented on Feb 21, 2020

    @RisingGeek

    Hi @cchaos , I was looking at the EuiButton component and was wondering what does exclusive union does?
    export type Props = ExclusiveUnion<EuiButtonPropsForAnchor,EuiButtonPropsForButton>;

  6. thompsongl commented on Feb 21, 2020

    @thompsongl
    Contributor

    @RisingGeek There's a good, full description of ExclusiveUnion in the code comments. (And another for the specific case you mention)

    The idea is that we needed a way for a component with multiple potential element targets to ensure that the attributes for those discrete elements don't get mixed. For instance, a simple union of HTMLAnchorElement | HTMLButtonElement might allow for anhref attribute to be passed to a <button />, which is invalid and something we want to avoid. ExclusiveUnion is our method of requiring that consumers pass props from either HTMLAnchorElement or HTMLButtonElement, but not a combination of the two.

  7. shakti97 commented on Feb 21, 2020

    @shakti97

    The EuiButton component does correclty handle this situation, but we essentially need to translate that same type of code to EuiBadge to handle it as well since EuiBadge does not extend EuiButton.

    okay will try to do that

  8. RisingGeek commented on Feb 21, 2020

    @RisingGeek

    @RisingGeek There's a good, full description of ExclusiveUnion in the code comments. (And another for the specific case you mention)

    The idea is that we needed a way for a component with multiple potential element targets to ensure that the attributes for those discrete elements don't get mixed. For instance, a simple union of HTMLAnchorElement | HTMLButtonElement might allow for anhref attribute to be passed to a <button />, which is invalid and something we want to avoid. ExclusiveUnion is our method of requiring that consumers pass props from either HTMLAnchorElement or HTMLButtonElement, but not a combination of the two.

    Got it. Thanks

  9. Mallik813 commented on Feb 22, 2020

    @Mallik813

    @cchaos
    Is this issue not closed yet? It's been 16 days since it was open? If it is not closed yet, can I take up this issue?
    Thanks

  10. shakti97 commented on Feb 22, 2020

    @shakti97

    Hi @Mallik813 , I'm currently working on this. Could you please check some other issue

  11. Mallik813 commented on Feb 22, 2020

    @Mallik813

    @shakti97 sure!

  12. anishagg17 commented on Feb 27, 2020

    @anishagg17
    Contributor

    @shakti97 May I take over this issue?

  13. anishagg17 commented on Feb 28, 2020

    @anishagg17
    Contributor

    @chandlerprall may i take this issue now?

  14. chandlerprall commented on Feb 29, 2020

    @chandlerprall
    Contributor

    @anishagg17 Go ahead

  15. cchaos commented on Mar 2, 2020

    @cchaos
    ContributorAuthor

    #2954 Cleaned up EuiButton code nicely, but it didn't address this issue. EuiBadge is a completely separate component that needs the same implementation as EuiButton. It does not re-use EuiButton or logic.

  16. reopened this on Mar 2, 2020
  17. anishagg17 commented on Mar 2, 2020

    @anishagg17
    Contributor

    @cchaos can I go for cleaning badge groups too??

  18. cchaos commented on Mar 2, 2020

    @cchaos
    ContributorAuthor

    EuiBadgeGroup doesn't actually contain any EuiBadge's. Only EuiBadge needs to be addressed by this issue.

  19. anishagg17 commented on Mar 2, 2020

    @anishagg17
    Contributor

    OKay , I would like to work on it @cchaos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions