Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A Button with only icon and external link does not show icon #181

Open
david-nathanael opened this issue Sep 6, 2023 · 6 comments
Open

Comments

@david-nathanael
Copy link

Hi, im assuming this is a bug. A button with an icon and an external link will not display the icon. It only displays the arrow indicating an external link.

     <Button
        iconId="ri-download-line"
        linkProps={{
          href: 'https://google.com',
        }}
        priority="tertiary no outline"
        title="Label button"
      />

https://stackblitz.com/edit/nextjs-ztzuot?file=pages%2Findex.tsx

Thanks

@garronej
Copy link
Collaborator

garronej commented Sep 7, 2023

Hi @david-nathanael,
Thank you for bringing this to our attention and for providing the reproduction sandbox.
This is clearly not the intended behavior. I believe it's now up to @gouvfr/dsfr to determine the appropriate course of action. External links should indeed display a small icon indicating that clicking the link will take the user away from the current website. However, when it comes to an icon button, it's unclear whether both icons should be retained or if an exception to the general rule can be made.
I'll consult the core dsfr team for guidance.

@garronej
Copy link
Collaborator

garronej commented Sep 7, 2023

Looks like the issue only arrise when using remix icons...

@david-nathanael
Copy link
Author

david-nathanael commented Sep 7, 2023

i didn't succeed even with fr icons.

if it helps, my use case is to have a download button on the end of the row in a table. the link targets the api url, thats why its external.

let me know how i can help.

@garronej
Copy link
Collaborator

garronej commented Sep 8, 2023

Sorry @david-nathanael, I got the wrong idea.

Hello @lab9fr,
The issue here isn't related to React dsfr nor the remix icons.
You can reproduce just by using target="blank" on the <a />

You can see the reproduction here: https://stackblitz.com/edit/nextjs-yffvvb?file=pages%2Findex.tsx

@david-nathanael The thing is react-dsfr automatically makes external links open in new tabs by default:

return <a href={target} target="_blank" rel="noreferrer" {...rest} />;

@garronej
Copy link
Collaborator

garronej commented Sep 8, 2023

@david-nathanael In the meantime you can sircumvent the problem by writing:

            <Button
                iconId="fr-icon-account-circle-fill"
                linkProps={{
                    href: 'https://google.com',
                    target: undefined,
                    rel: undefined,
                }}
                priority="tertiary no outline"
                title="Label buttons"
            />

This will probably make your user leave the website which isn't great.

So maybe the best is to just do:

            <Button
                iconId="fr-icon-account-circle-fill"
                onClick={()=> window.open("https://google.com", '_blank');}
                priority="tertiary no outline"
                title="Label buttons"
            />

The url won't be visibe at the bottom left of the screen when hovering the button and it won't be possible to do a right-click -> copy the link to clipboard but other thant that it will work....

@david-nathanael
Copy link
Author

thanks for the workaround. feel free to close the issue if you dont need it

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

No branches or pull requests

2 participants