如何在Material-UI React中的Switch组件内添加文本? [英] How to add text inside a Switch Component in Material-UI React?

查看:130
本文介绍了如何在Material-UI React中的Switch组件内添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在Material-UI的Switch组件内添加文本?我正在尝试在开关组件"中添加是"和否"文本.

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".

推荐答案

您是否尝试过动态处理标签值和位置?

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"}
        />

这篇关于如何在Material-UI React中的Switch组件内添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆