question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Button examples run a user-defined function

See original GitHub issue

This may seem totally obvious to those experienced with MUI, but to those totally new to it, it may come as a surprise that none of the Button pages (Button, ButtonBase, IconButton) mention or show an example of how to actually initiate an icon as a result of clicking a button. 😄

This is textbook example of the curse of knowledge.

There’s the implicit assumption that buttons extend the HTML button elements, so onClick should be set to a function, but for new users, that may just not be obvious. Not even the ButtonBase API page mentions anything about onClick, or extending the button element.

If the above makes sense, the examples on the Button* pages could be improved to allow a user brand new to MUI, to get started with a button performing an action. MUI may be the jQuery of building web apps, and it’s reasonable to anticipate that some developers may simply not have the necessary HTML background assumptions.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eps1loncommented, May 18, 2020

I think this is not necessarily related to #18288. The primary use case for a button is to handle a click. Not showing that in the demo can’t be excused with “the prop is implied in the docs” not even with a future “the prop is explicitly listed (among 10 other props)”.

Generally I feel our docs are lacking in displaying interactions. We oftentimes use alert which is too disruptive in my opinion. Would be nice if we could improve this (e.g. transpiling alert to internal tools such as stacking stacking snackbars) and then we have a good tool for displaying button interactions.

I’d even go as far as making onClick required but that’s for another day.

1reaction
oliviertassinaricommented, May 17, 2020

@dandv This topic has come up in the past. So far our position has been that any none documented prop is forwarded. Developers can expect the same behavior than from native elements when using the Material-UI’s components. I would be in favor of keeping the current tradeoff as the best worse alternative and move the discussion to #18288 for a better solution.

Curse of knowledge

I wish I could unlearn all I know about the framework. @dtassone I count on you to report things you found weird/hard to grasp as still relatively new to the library. For instance, you have mentioned the styles behind hard to grasp during our last meeting. It’s likely something worth diving into.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a custom button that run a function called in ...
Hi! i need to call a function in UI design only when a button ( or custom button ) is pressed. I create...
Read more >
Can I call a custom function from a button action function?
I would like to make a custom function called, say, userPermissionCheck that I can call within the custom action function for each button....
Read more >
Creating a User Defined Function (UDF) in Excel VBA ...
In this tutorial, I will show you how to create a User Defined Function (VBA) in VBA. You can use these UDFs in...
Read more >
Excel User Defined Function Examples - GoSkills
In this post, we're going to see how we can build our own custom functions in Excel with VBA, and we will look...
Read more >
Using an HTML button to call a JavaScript function
1: There's defining it in the HTML: <input id="clickMe" type="button" value="clickme" onclick="doFunction();" /> · 2: There's adding it to the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found