diff --git a/docs/src/pages/components/selects/NativeSelects.js b/docs/src/pages/components/selects/NativeSelects.js
index 550e6d4e23ba46..d3945d59fe3056 100644
--- a/docs/src/pages/components/selects/NativeSelects.js
+++ b/docs/src/pages/components/selects/NativeSelects.js
@@ -23,12 +23,6 @@ export default function NativeSelects() {
name: 'hai',
});
- const inputLabel = React.useRef(null);
- const [labelWidth, setLabelWidth] = React.useState(0);
- React.useEffect(() => {
- setLabelWidth(inputLabel.current.offsetWidth);
- }, []);
-
const handleChange = name => event => {
setState({
...state,
@@ -200,14 +194,12 @@ export default function NativeSelects() {
Required
-
- Age
-
+ Age
-
+
Age
-
- Age
-
+ Age
-
+
Age
-
- Name
-
-
+ Name
+
Name
diff --git a/docs/src/pages/components/text-fields/ComposedTextField.tsx b/docs/src/pages/components/text-fields/ComposedTextField.tsx
index 7b15ceed818170..ea00f8b113424d 100644
--- a/docs/src/pages/components/text-fields/ComposedTextField.tsx
+++ b/docs/src/pages/components/text-fields/ComposedTextField.tsx
@@ -20,15 +20,9 @@ const useStyles = makeStyles((theme: Theme) =>
);
export default function ComposedTextField() {
- const [labelWidth, setLabelWidth] = React.useState(0);
const [name, setName] = React.useState('Composed TextField');
- const labelRef = React.useRef(null);
const classes = useStyles();
- React.useEffect(() => {
- setLabelWidth(labelRef.current!.offsetWidth);
- }, []);
-
const handleChange = (event: React.ChangeEvent) => {
setName(event.target.value);
};
@@ -65,14 +59,14 @@ export default function ComposedTextField() {
Error
-
+
Name
diff --git a/docs/src/pages/components/text-fields/InputAdornments.js b/docs/src/pages/components/text-fields/InputAdornments.js
index f8efb3efe2f838..435a341ce85fcb 100644
--- a/docs/src/pages/components/text-fields/InputAdornments.js
+++ b/docs/src/pages/components/text-fields/InputAdornments.js
@@ -178,7 +178,6 @@ export default function InputAdornments() {
inputProps={{
'aria-label': 'weight',
}}
- labelWidth={0}
/>
Weight
@@ -200,7 +199,7 @@ export default function InputAdornments() {
}
- labelWidth={70}
+ label="Password"
/>
@@ -210,7 +209,7 @@ export default function InputAdornments() {
value={values.amount}
onChange={handleChange('amount')}
startAdornment={$}
- labelWidth={60}
+ labelWidth="Amount"
/>
diff --git a/docs/src/pages/components/text-fields/InputAdornments.tsx b/docs/src/pages/components/text-fields/InputAdornments.tsx
index 3a828a9380ddc7..d3890fb7d89e84 100644
--- a/docs/src/pages/components/text-fields/InputAdornments.tsx
+++ b/docs/src/pages/components/text-fields/InputAdornments.tsx
@@ -188,7 +188,6 @@ export default function InputAdornments() {
inputProps={{
'aria-label': 'weight',
}}
- labelWidth={0}
/>
Weight
@@ -210,7 +209,7 @@ export default function InputAdornments() {
}
- labelWidth={70}
+ label="Password"
/>
@@ -220,7 +219,7 @@ export default function InputAdornments() {
value={values.amount}
onChange={handleChange('amount')}
startAdornment={$}
- labelWidth={60}
+ labelWidth="Amount"
/>
diff --git a/packages/material-ui/src/OutlinedInput/NotchedOutline.d.ts b/packages/material-ui/src/OutlinedInput/NotchedOutline.d.ts
index 8d72fa235ef81d..ddb163e30db876 100644
--- a/packages/material-ui/src/OutlinedInput/NotchedOutline.d.ts
+++ b/packages/material-ui/src/OutlinedInput/NotchedOutline.d.ts
@@ -6,7 +6,7 @@ export interface NotchedOutlineProps
disabled?: boolean;
error?: boolean;
focused?: boolean;
- labelWidth: number;
+ label?: React.ReactNode;
notched: boolean;
}
diff --git a/packages/material-ui/src/OutlinedInput/NotchedOutline.js b/packages/material-ui/src/OutlinedInput/NotchedOutline.js
index 4f9881539d892f..d63483cd3467d8 100644
--- a/packages/material-ui/src/OutlinedInput/NotchedOutline.js
+++ b/packages/material-ui/src/OutlinedInput/NotchedOutline.js
@@ -3,50 +3,53 @@ import PropTypes from 'prop-types';
import clsx from 'clsx';
import withStyles from '../styles/withStyles';
import useTheme from '../styles/useTheme';
-import capitalize from '../utils/capitalize';
-export const styles = theme => {
- const align = theme.direction === 'rtl' ? 'right' : 'left';
-
- return {
- /* Styles applied to the root element. */
- root: {
- position: 'absolute',
- bottom: 0,
- right: 0,
- top: -5,
- left: 0,
- margin: 0,
- padding: 0,
- pointerEvents: 'none',
- borderRadius: 'inherit',
- borderStyle: 'solid',
- borderWidth: 1,
- // Match the Input Label
- transition: theme.transitions.create([`padding-${align}`, 'border-color', 'border-width'], {
- duration: theme.transitions.duration.shorter,
- easing: theme.transitions.easing.easeOut,
- }),
- },
- /* Styles applied to the legend element. */
- legend: {
- textAlign: 'left',
- padding: 0,
- lineHeight: '11px',
- fontSize: '0.75rem',
- maxWidth: 0,
- transition: theme.transitions.create('max-width', {
- duration: theme.transitions.duration.shorter,
- easing: theme.transitions.easing.easeOut,
- }),
- visibility: 'hidden',
- '& span': {
- paddingLeft: 4,
- paddingRight: 6,
- },
+export const styles = theme => ({
+ /* Styles applied to the root element. */
+ root: {
+ position: 'absolute',
+ bottom: 0,
+ right: 0,
+ top: -5,
+ left: 0,
+ margin: 0,
+ padding: 0,
+ paddingLeft: 8,
+ pointerEvents: 'none',
+ borderRadius: 'inherit',
+ borderStyle: 'solid',
+ borderWidth: 1,
+ // Match the Input Label
+ transition: theme.transitions.create(['border-color', 'border-width'], {
+ duration: theme.transitions.duration.shorter,
+ easing: theme.transitions.easing.easeOut,
+ }),
+ },
+ /* Styles applied to the legend element. */
+ legend: {
+ textAlign: 'left',
+ padding: 0,
+ lineHeight: '11px',
+ fontSize: '0.75rem',
+ visibility: 'hidden',
+ maxWidth: 0,
+ transition: theme.transitions.create('max-width', {
+ duration: 50,
+ delay: 0,
+ }),
+ '& span': {
+ paddingLeft: 4,
+ paddingRight: 6,
},
- };
-};
+ },
+ legendNotched: {
+ maxWidth: 1000,
+ transition: theme.transitions.create('max-width', {
+ duration: 100,
+ delay: 60,
+ }),
+ },
+});
/**
* @ignore - internal component.
@@ -56,31 +59,22 @@ const NotchedOutline = React.forwardRef(function NotchedOutline(props, ref) {
children,
classes,
className,
- label = '\u200B',
- labelWidth: labelWidthProp,
+ label,
notched,
style,
...other
} = props;
- const theme = useTheme();
- const align = theme.direction === 'rtl' ? 'right' : 'left';
- const labelWidth = labelWidthProp > 0 ? labelWidthProp * 0.75 + 8 : 0;
return (
-