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

[TextField] Fix running click event on disabled #36892

Merged
merged 3 commits into from Apr 25, 2023

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Apr 15, 2023

closes #36867

before : https://codesandbox.io/s/zen-meadow-lr2flp?file=/demo.tsx
after : https://codesandbox.io/s/beautiful-panka-24o4h2?file=/demo.tsx

Actual issue lies in TextField component not in Autocomplete. Right now onClick event of TextField runs even if TextField is disabled. This PR fixes it.

@sai6855 sai6855 changed the title fix [TextField] fix running click event on disabled Apr 15, 2023
@sai6855 sai6855 added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Apr 15, 2023
@mui-bot
Copy link

mui-bot commented Apr 15, 2023

Netlify deploy preview

https://deploy-preview-36892--material-ui.netlify.app/

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 7854792

@sai6855 sai6855 marked this pull request as draft April 15, 2023 11:15
@sai6855 sai6855 marked this pull request as ready for review April 16, 2023 05:27
@sai6855 sai6855 requested review from mj12albert and removed request for michaldudak April 21, 2023 10:27
Copy link
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks, sorry I didn't get to this before this week's release 🙏 @sai6855

@sai6855
Copy link
Contributor Author

sai6855 commented Apr 25, 2023

@mj12albert no problem :)

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect #36867 should be fixed in the Autocomplete, hence this PR is not going in the right direction: #36892 (comment).

Comment on lines -443 to +442
if (onClick) {
if (onClick && !fcs.disabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? It's not clear if it's the desired behavior:

export default function App() {
  return (
    <div
      onClick={() => {
        console.log("root");
      }}
    >
      <input
        disabled
        onClick={() => {
          console.log("input");
        }}
      />
    </div>
  );
}

https://codesandbox.io/s/amazing-banzai-xc225m?file=/src/App.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 This looked ok to me as a plain <input> doesn't fire onClick when it's disabled: https://codesandbox.io/s/async-https-n9x4y3-onclick-disabled-n9x4y3 @oliviertassinari

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there can be startAdornment, endAdornment, and renderSuffix. IMHO, we shouldn't try to make InputBase behave like an input because it's not: it's a root > input like structure. Instead, if we were to stay close to the normal DOM behavior we would avoid surprises for people that are familiar with the platform behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't try to make InputBase behave like an input because it's not

OK this makes sense 👌 will try to find a fix within Autocomplete

@oliviertassinari oliviertassinari changed the title [TextField] fix running click event on disabled [TextField] Fix running click event on disabled Aug 14, 2023
mj12albert added a commit to mj12albert/material-ui that referenced this pull request Aug 14, 2023
mj12albert added a commit to mj12albert/material-ui that referenced this pull request Aug 15, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 16, 2023

To complement, #36892 (comment).

I didn't realize this also changed <TextField onClick> behavior mui/mui-x#9386 (comment). For this, one, it's a lot clearer (the InputBase can be subjective), no, props should be spread on the root element, unless they absolutely should be on a lower element, which is not the case here. It's even more true if we don't document the behavior, which we didn't with @ignore.

A clear example:

import * as React from "react";
import TextField from "@mui/material/TextField";

export default function BasicTextFields() {
  return (
    <TextField
      onClick={() => {
        console.log("textField");
      }}
      helperText="hello"
    />
  );
}

https://codesandbox.io/s/autumn-http-cn5nrc?file=/Demo.tsx:0-257 clicking on the helper text doesn't trigger the onClick listener anymore ❌.

mj12albert added a commit to mj12albert/material-ui that referenced this pull request Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Autocomplete][material-ui] Disabled is not working properly
6 participants