How to add text inside a Switch Component in Material-UI React?

Viewed 2799

How do we add text inside a Switch component in Material-UI react? I am trying to add "YES" and "NO" text inside the Switch Component.

Expected: When switch button is to the right, "Yes" text should be to the left and inside the Switch Component". When switch button is to the left, "No" text should be to the right and inside the Switch Component".

2 Answers

Have you tried manipulating the label value and position dynamically?

<FormControlLabel
          value={state.checked ? "yes" : "no"}
          control={<Switch color="primary" checked={state.checked} />}
          label={state.checked ? "Yes" : "No"}
          labelPlacement={state.checked ? "start" : "end"}
        />
Related