reactjs 如何给选中MUIReact切换按钮添加复选图标?

z4bn682m  于 2023-02-04  发布在  React
关注(0)|答案(1)|浏览(107)

我的问题很简单,如何添加检查图标内选定的ToggleButton?堆栈流不会让我张贴它,我只是没有其他解释pleaseee

export default function TableBusiness() {
  const [alignment, setAlignment] = React.useState('web');

  const handleChange = (event, newAlignment) => {
    setAlignment(newAlignment);
  };
  return (
    <Box
      sx={{
        p: 2,
        display: 'flex',
        flexWrap: 'wrap',
        '& > :not(style)': {

          width: "100%",
          height: 1000,

        },
      }}
    >
        <Box
          display="flex"
          
          justifyContent="space-around"
        >

          <ToggleButtonGroup
            color="primary"
            sx={{ borderRadius: '40px !important', backgroundColor: grey[50]}}
            value={alignment}
            exclusive
            onChange={handleChange}
            aria-label="Platform"
            

          >
            <ToggleButton sx={{borderBottomLeftRadius:20 , borderTopLeftRadius:20}} value="one">از ابتدای تاسیس</ToggleButton>
            <ToggleButton borderRadius= '30px' value="two">یکسال گذشته</ToggleButton>
            <ToggleButton value="three">یکماه گذشته</ToggleButton>
            <ToggleButton sx={{borderBottomRightRadius:20 , borderTopRightRadius:20}} value="four">جدیدترین</ToggleButton>
          </ToggleButtonGroup>
        </Box>

  );
}

我希望在每个选定ToggleButton左侧看到复选标记

6jjcrrmo

6jjcrrmo1#

只需检查ToggleButton的值是否与“alignment”中选择的值相对应。类似于:

<ToggleButton sx={{borderBottomLeftRadius:20 , borderTopLeftRadius:20}} value="one">
{alignment==='one'&&<CheckIcon/>}از ابتدای تاسیس
</ToggleButton>

相关问题