If you check right below the props table on the page defining the Typography component API, you'll see that it says
Any other props supplied will be provided to the root element (native element).
So for example, if you have
<Typography onClick={myFunction} paragraph component="span" color="primary" variant="body1">
{f('changeUnitsToCentimeters')}
</Typography>
Then myFunction
will be applied as a click event directly on the span
.
That said, you shouldn't not use a button simply because it will mess up your styles. Putting a click listener on a non-interactive element like a span
is not accessible, and making it accessible isn't that straightforward. Here's a list of things to consider that probably isn't even exhaustive:
- does your span exist in the tab index?
- do assistive technologies recognize it as a button?
- can it be clicked via the enter key and space bar?
- does it automatically submit forms in the proper circumstances?
Native button elements take care of all that stuff for you automatically, so instead of making a span accessible, the far simpler solution is to style your button to look how you want with CSS.
For Material UI, you can look into the ButtonBase component as a wrapper for your Typography
component since ButtonBase has all that functionality and more, without all the opinionated styles of the regular Material UI Button component. Or you can not bother with a component for the button and just use a regular <button>
with custom styles. Here's an article from CSS Tricks on the topic of overriding default button styles.