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

Button: Cannot make button as link properly #6535

Closed
Assignees
Labels
Component: Documentation Issue or pull request is related to Documentation
Milestone

Comments

@galimovkirill
Copy link

galimovkirill commented May 1, 2024

Describe the bug

Component's API offers to make tag with p-button class, but I want use properties to style this link (or for additional functionality like disabled or loading) The current showcase definitely do not look right and is displaying "Link" and "Navigate".

Reproducer

https://primereact.org/button/#link

image

PrimeReact version

10.6.4

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@galimovkirill galimovkirill added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label May 1, 2024
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels May 1, 2024
@galimovkirill
Copy link
Author

galimovkirill commented May 1, 2024

@melloware Do I understand correctly, that after this PR fix I can create a link with passed href to my <PrimeButton /> component?

@melloware
Copy link
Member

I have to study the code and see what PrimeTek original intent of this and what PrimeVue is doing. But right now this code does not look like it is doing as it was intended.

@nitrogenous
Copy link
Contributor

What specific changes or enhancements are you aiming to make to the button component in your application, particularly in terms of its appearance and functionality? The showcase seems fine to me can you be more elaborate?

melloware added a commit to melloware/primereact that referenced this issue May 2, 2024
@melloware melloware added Component: Documentation Issue or pull request is related to Documentation and removed Type: Bug Issue contains a defect related to a specific component. labels May 2, 2024
@melloware melloware assigned melloware and unassigned nitrogenous May 2, 2024
@melloware melloware added this to the 10.7.0 milestone May 2, 2024
@melloware
Copy link
Member

@galimovkirill i think this is just confusion over what you want to do and I just updated the docs. There are 3 scenarios.

Button Rendered As Link

This renders the buttons as Link and navigates you to https://react.dev on Click.

<Button label="Link" link onClick={() => window.open('https://react.dev', '_blank')} />

Link Rendered as Button

This is a normal HTML link that just is "styled" to look like a button

<a href="https://react.dev" target="_blank" rel="noopener noreferrer" className="p-button font-bold">
       Navigate
</a>

What you want is something more like this....

Button pretending to be a Link

This is a normal button with all the behaviors like "disabled" etc it just simply performs a navigation.

// open a new URL
<Button label="Open URL" link onClick={() => window.open('https://react.dev', '_blank')} />

// use NextJS Router to go to another URL
<Button label="Navigate In App" link onClick={() =>  router.push('/desired-url');} />
```

@galimovkirill
Copy link
Author

I think that current button implementation cannot provide functionality for my needs.
I meant that I need normal HTML link which looks like button without setting any additional classes.

You can see example at MUI's component: https://mui.com/material-ui/react-button/#text-button

The 3rd button is a link, but we render it with <Button/> component and can pass any prop like variant to change styling of button (which is link actually). So, just because we pass href prop, it decide itself that it should render specific HTML tag.

@melloware
Copy link
Member

melloware commented May 2, 2024

@galimovkirill yes the equivalent in PR.

MUI:

<Button href="#text-buttons">Link</Button>

PR:

<Button label="Open URL" link onClick={() => window.location.hash = "#text-buttons";} />

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