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: p-button executing methods on click when disabled #12495

Closed
cosmin19 opened this issue Jan 13, 2023 · 6 comments · Fixed by #12704
Closed

Button: p-button executing methods on click when disabled #12495

cosmin19 opened this issue Jan 13, 2023 · 6 comments · Fixed by #12704
Labels
LTS-PORTABLE Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@cosmin19
Copy link

Describe the bug

Code:

<p-button label="Not OK" disabled="true" (click)="foo()"></p-button>

Bug: foo method is executed on click even though the button is disabled. This happens only when using p-button.

If I'm using

<button pButton label="OK" disabled="true" (click)="foo()"></button>

the foo method is not executed.

Environment

Angular 15.0.4
PrimeNG 15.0.1
Tested in Chrome Version 108.0.5359.124 (Official Build) (64-bit)

Reproducer

No response

Angular version

15.0.4

PrimeNG version

15.0.1

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.12.1

Browser(s)

No response

Steps to reproduce the behavior

  1. Create a foo method in .ts file
foo() { console.log('Hello world') }
  1. Add button in .html file
<p-button label="Not OK" disabled="true" (click)="foo()"></p-button>
  1. Click on button
  2. Observe how method foo is executed

Expected behavior

Disabled buttons should not execute methods on click.

@cosmin19 cosmin19 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 13, 2023
@cosmin19 cosmin19 changed the title Component: p-button executing methods on click when disabled Button: p-button executing methods on click when disabled Jan 13, 2023
@critchie
Copy link

critchie commented Jan 14, 2023

When using p-button you have to use (onClick)="foo()". When using onClick with p-button the click event will not fire when the button is disabled. I struggled with this too until I found the following deep in the documentation.

Events
Events are defined using standard notation in pButton and with on* prefix at p-button.

<button pButton type="button" label="Click" (click)="handleClick($event)">
<p-button label="Click" (onClick)="handleClick($event)">

@jucasoft
Copy link

jucasoft commented Mar 3, 2023

PrimeNg developers need to be notified :) , this problem also occurs in components that themselves use p-buttons, such as fileupload

I saw that there are very old issues about this problem.

I have an idea that it is not easy to fix it, it depends on how chromium intercepts the (click) event

@jucasoft
Copy link

jucasoft commented Mar 4, 2023

@volvachev
I looked at your implementation but I believe it doesn't solve the problem. I suspect the problem is with how chromium catches the "click" event.

@cosmin19 explained the problem very well, it doesn't depend on the graphic style.

@volvachev
Copy link
Contributor

@volvachev I looked at your implementation but I believe it doesn't solve the problem. I suspect the problem is with how chromium catches the "click" event.

@cosmin19 explained the problem very well, it doesn't depend on the graphic style.

Hi, this class addspointer-events: none that block an event such as click.

@jucasoft
Copy link

@volvachev I looked at your implementation but I believe it doesn't solve the problem. I suspect the problem is with how chromium catches the "click" event.
@cosmin19 explained the problem very well, it doesn't depend on the graphic style.

Hi, this class addspointer-events: none that block an event such as click.

I have to pay you for a coffee. do cats like coffee?

thank you.

@volvachev
Copy link
Contributor

I have to pay you for a coffee. do cats like coffee?

thank you.

Cats like coffee only with milk 😉. What about dogs?
You're welcome

@mertsincan mertsincan added this to the 16.2.1 milestone Aug 18, 2023
@mertsincan mertsincan added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTS-PORTABLE Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants