How to add a data attribute to Material-UI Button?

Viewed 3904

I want to add a custom data attribute to the Material-UI Button Component like described here. In my case this would look like this:

<Button
  inputProps={{ 'data-testid'='clickButton' }}
>
Click
</Button

This solution doesn't work because there is no inputProps for the Button Component. So how can I set a custom data attribute to the Material-UI Button Component?

1 Answers

You just add the prop directly to Button:

<Button data-testid="clickButton">Click</Button>

Edit Button data attribute

Related