【问题标题】:material ui textfield wont be right aligned and right to left材质 ui 文本字段不会右对齐和从右到左
【发布时间】:2021-02-08 23:45:19
【问题描述】:

我在 react 中使用材料 ui 创建了一个表单,我希望标签从右到左和右对齐我尝试了 textAlign 和 direction:"rtl" 但它们不起作用。这是我的代码:

   <Box style={{textAlign: "right", direction: "rtl"}}>
     <form style={{width: "35ch"}}>
         <Box m={2}  >
                <TextField
                    name={props.id}
                    aria-autocomplete={"list"}
                    autoComplete="true"
                    autofill="true"
                    fullWidth required={props.required}
                    id={props.id} variant="outlined" color={"primary"}
                    label={<Typography style={{display:"inline",fontFamily:"iranyekanreg",direction:"rtl"
                                          ,textAlign:"right"}}>{props.label}</Typography>}
                    inputProps={min:0,step:"1"}
                    type={String}
                    onChange={props.onchange}
                    value={props.value}
                />
        </Box>
      </form>
   </Box>

【问题讨论】:

  • 你能创建一个codesandbox吗? inputProps 应该是一个对象

标签: reactjs material-ui


【解决方案1】:

这应该会给你你想要的。

const useStyles = makeStyles(theme => ({
  labelRoot: {
    right: 0
  },
  shrink: {
    transformOrigin: "top right"
  }
}));

export default function FormPropsTextFields() {
  const classes = useStyles();

  return (
    <div>
      <TextField
        required
        style={{ direction: "rtl" }}
        id="standard-required"
        label="Required"
        defaultValue="Hello World"
        InputLabelProps={{
          classes: { root: classes.labelRoot, shrink: classes.shrink }
        }}
      />
    </div>
  );
}

【讨论】:

  • 有没有办法同时保留两者?例如,一个标签放在右边,另一个放在左边?
猜你喜欢
  • 1970-01-01
  • 2020-06-22
  • 2018-01-05
  • 2016-08-10
  • 2015-07-27
  • 1970-01-01
  • 1970-01-01
  • 2013-06-17
  • 2015-10-07
相关资源
最近更新 更多