How to not leave button in selected state after click - fluent-ui (office ui fabric)

669 views Asked by At

Using DefaultButton currently. This remains selected when clicked, which property can be used to revoke selection once clicked.

Alternatively, is there any styling that needs to be done for selection?

1

There are 1 answers

0
Marko Savic On

You can use DefaultButton checked property for that scenario and control it with onClick event:

const [isButtonChecked, setIsButtonChecked] = React.useState(false);

<DefaultButton
  checked={isButtonChecked}
  onClick={() => {
    setIsButtonChecked(!isButtonChecked);
  }}
  styles={{
    rootChecked: {
      backgroundColor: '#f00',
      color: '#fff',
    }
  }}
>
  Default Button
</DefaultButton>

Use styles property to modify button styles when button state is checked: rootChecked, rootCheckedHovered etc.

Codepen example.