Ad

How To Get The Label In The Material-ui Text Field To The Right?

I'm using material-ui and typescript for my react project (rtl layout) and i don't know how to get the label of text field to the right?

enter image description here

Ad

Answer

You need jss-rtl to support rtl for css. This library provides its Provider to support rtl in any library.

import React from "react";
import { create } from "jss";
import rtl from "jss-rtl";
import JssProvider from "react-jss/lib/JssProvider";
import { createGenerateClassName, jssPreset } from "@material-ui/core/styles";

// Configure JSS
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });

// Custom Material-UI class name generator.
const generateClassName = createGenerateClassName();

function RTL(props) {
  return (
    <JssProvider jss={jss} generateClassName={generateClassName}>
      {props.children}
    </JssProvider>
  );
}

export default RTL;

Then in your main app use this provider.

ReactDOM.render(
  <RTL>
    <Demo />
  </RTL>,
  document.querySelector("#root")
);

Working demo here

Ad
source: stackoverflow.com
Ad