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

[Chip] clickable={false} option still executes onClick method #24611

Closed
2 tasks done
asjustis opened this issue Jan 25, 2021 · 4 comments · Fixed by #24645
Closed
2 tasks done

[Chip] clickable={false} option still executes onClick method #24611

asjustis opened this issue Jan 25, 2021 · 4 comments · Fixed by #24645
Labels
component: chip This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@asjustis
Copy link

Hi,

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

I am trying to conditionally render my Chip component to be clickable or read-only. When I set clickable={false}, it still executes onClick when pressed.

Expected Behavior 🤔

I would naturally expect that both UI and the method execution would be disabled by the clickable={false} option.

Steps to Reproduce 🕹

I added a quick sandbox example here to reproduce: https://codesandbox.io/s/vigilant-water-2yygy?file=/src/App.js

Steps:

  1. add onClick method
  2. add clickable={false} line
  3. click on the tag in the UI
  4. it still executes the onClick() method

Your Environment 🌎

Using latest 4.11.3 core version:

    OS: macOS Mojave 10.14.5
  Binaries:
    Node: 10.21.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 88.0.4324.96
    Edge: Not Found
    Firefox: 83.0
    Safari: 12.1.1
  npmPackages:
    @material-ui/core: ^4.11.3 => 4.11.3 
    @material-ui/icons: ^4.5.1 => 4.5.1 
    @material-ui/lab: ^4.0.0-alpha.38 => 4.0.0-alpha.38 
    @material-ui/styles:  4.11.3 
    @material-ui/system:  4.11.3 
    @material-ui/types:  5.1.0 
    @material-ui/utils:  4.7.1 
    @types/react:  16.9.11 
    react: ^16.9.0 => 16.9.0 
    react-dom: ^16.9.0 => 16.9.0 
@asjustis asjustis added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 25, 2021
@oliviertassinari oliviertassinari added the component: chip This is the name of the generic UI component, not the React module! label Jan 25, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 25, 2021

@asjustis Interesting, the clickable prop has the following description:

If true, the chip will appear clickable, and will raise when pressed, even if the onClick prop is not defined. If false, the chip will not be clickable, even if onClick prop is defined. This can be used, for example, along with the component prop to indicate an anchor Chip is clickable.

I don't think that we should implement the behavior proposed because clickable is meant to change the UI, not the behavior. I would also be worried about the breaking change without any easy workaround (as you have now). I vote for "won't fix".

@oliviertassinari oliviertassinari removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 25, 2021
@asjustis
Copy link
Author

asjustis commented Jan 25, 2021

@oliviertassinari ah, I see, agreed that it would most likely be a breaking change. The name clickable suggests it controls the Chip component itself, rather than the UI.

If false, the chip will not be clickable, even if onClick prop is defined

It seems, this part in documentation might be misleading. Maybe a note in documentation would help to clarify this? Note: this controls the UI and does not affect the onClick event

diff --git a/packages/material-ui/src/Chip/Chip.d.ts b/packages/material-ui/src/Chip/Chip.d.ts
index cab738ff63..d9a6b2b480 100644
--- a/packages/material-ui/src/Chip/Chip.d.ts
+++ b/packages/material-ui/src/Chip/Chip.d.ts
@@ -89,9 +89,10 @@ export interface ChipTypeMap<P = {}, D extends React.ElementType = 'div'> {
     /**
      * If `true`, the chip will appear clickable, and will raise when pressed,
      * even if the onClick prop is not defined.
-     * If false, the chip will not be clickable, even if onClick prop is defined.
+     * If `false`, the chip will not be clickable, even if onClick prop is defined.
      * This can be used, for example,
      * along with the component prop to indicate an anchor Chip is clickable.
+     * Note: this controls the UI and does not affect the onClick event.
      */
     clickable?: boolean;
     /**

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Jan 25, 2021
@oliviertassinari
Copy link
Member

This clarification sounds great, do you want to update the docs in next?

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Jan 25, 2021
@asjustis
Copy link
Author

@oliviertassinari Ah didn't get back in time. Thanks for closing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: chip This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants