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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

IconButton with onClick typescript issues #16327

Closed
2 tasks done
lookfirst opened this issue Jun 21, 2019 · 9 comments
Closed
2 tasks done

IconButton with onClick typescript issues #16327

lookfirst opened this issue Jun 21, 2019 · 9 comments
Labels
support: Stack Overflow Please ask the community on Stack Overflow

Comments

@lookfirst
Copy link
Contributor

lookfirst commented Jun 21, 2019

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃

No warnings in my IDE. I don't need to add the href= attribute because my onClick handler deals with things for me.

Current Behavior 馃槸

Catch 22 error. If I don't have href, I get a warning about not having href. If I have href, then I get an error. I suspect I'm doing something stupid.

Steps to Reproduce 馃暪

<IconButton edge="end" aria-label="Delete" onClick={(event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => handleDelete(event)}>
    <DeleteIcon />
</IconButton>

Context 馃敠

image

Error after adding href={''}

image

image

Your Environment 馃寧

Tech Version
Material-UI v4.1.1
React v16.8.20
Browser Chrome latest
TypeScript 3.5.2
Intellij 2019.2 EAP latest
@eps1lon eps1lon added the support: Stack Overflow Please ask the community on Stack Overflow label Jun 21, 2019
@support
Copy link

support bot commented Jun 21, 2019

馃憢 Thanks for using Material-UI!

We use the issue tracker exclusively for bug reports and feature requests, however,
this issue appears to be a support request or question. Please ask on StackOverflow where the
community will do their best to help. There is a "material-ui" tag that you can use to tag your
question.

If you would like to link from here to your question on SO, it will help others find it.
If your issues is confirmed as a bug, you are welcome to reopen the issue using the issue template.

@support support bot closed this as completed Jun 21, 2019
@eps1lon
Copy link
Member

eps1lon commented Jun 21, 2019

If you add an href you will render an anchor not a button i.e. HTMLButtonElement wont be true at runtime. You should use HTMLAnchorElement.

@lookfirst
Copy link
Contributor Author

I think you're missing the point though. Without the href=, the IDE gives a warning that it is missing. This is something wrong with the type definitions. href isn't a required attribute.

@eps1lon
Copy link
Member

eps1lon commented Jun 21, 2019

Without the href=, the IDE gives a warning that it is missing.

As with #16328 we don't offer support for every IDE setup. The actual build error after you added the href attribute is expected.

@chrisparton1991
Copy link

chrisparton1991 commented Jul 10, 2019

@eps1lon This looks like an issue with the type definitions. IconButton extends from ExtendButtonBase, which has { href: string } as its prop type.

Should the prop type be { href?: string }?. I'm not sure what the repercussions of this change would be, but making href optional fixes the warning and seems sensible to me.

@rob-glas
Copy link

rob-glas commented Sep 6, 2020

Looks like this still has not been addressed.

@oliviertassinari
Copy link
Member

@rob-glas Do you have a reproduction with v5-alpha.8?

@xuhdev
Copy link
Contributor

xuhdev commented Jan 30, 2024

I can still reproduce this. While the generated page uses a button element, the typescript compiler insists that the element is HTMLAnchorElement.

@xuhdev
Copy link
Contributor

xuhdev commented Jan 30, 2024

OK, I found that I misplaced a variant field to IconButton. After removing variant, it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

6 participants