Skip to content

Commit 711d276

Browse files
committed
[OutlinedInput] Fix offscreen label strikethrough
1 parent 9a538bc commit 711d276

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

docs/src/pages/components/tabs/SimpleTabs.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { makeStyles } from '@material-ui/core/styles';
44
import AppBar from '@material-ui/core/AppBar';
55
import Tabs from '@material-ui/core/Tabs';
66
import Tab from '@material-ui/core/Tab';
7+
import TextField from '@material-ui/core/TextField';
78
import Typography from '@material-ui/core/Typography';
89
import Box from '@material-ui/core/Box';
910

@@ -62,13 +63,13 @@ export default function SimpleTabs() {
6263
</Tabs>
6364
</AppBar>
6465
<TabPanel value={value} index={0}>
65-
Item One
66+
<TextField label="dummy input" variant="outlined" />
6667
</TabPanel>
6768
<TabPanel value={value} index={1}>
6869
Item Two
6970
</TabPanel>
7071
<TabPanel value={value} index={2}>
71-
Item Three
72+
<TextField label="dummy input" variant="outlined" />
7273
</TabPanel>
7374
</div>
7475
);

docs/src/pages/components/text-fields/OutlinedTextFields.js

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export default function OutlinedTextFields() {
6767
<TextField
6868
id="outlined-uncontrolled"
6969
label="Uncontrolled"
70-
defaultValue="foo"
7170
className={classes.textField}
7271
margin="normal"
7372
variant="outlined"

packages/material-ui/src/OutlinedInput/NotchedOutline.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ export const styles = theme => {
3333
textAlign: 'left',
3434
padding: 0,
3535
lineHeight: '11px',
36-
transition: theme.transitions.create('width', {
36+
fontSize: '0.75rem',
37+
maxWidth: 0,
38+
transition: theme.transitions.create('max-width', {
3739
duration: theme.transitions.duration.shorter,
3840
easing: theme.transitions.easing.easeOut,
3941
}),
42+
visibility: 'hidden',
43+
'& span': {
44+
paddingLeft: 4,
45+
paddingRight: 6,
46+
},
4047
},
4148
};
4249
};
@@ -49,6 +56,7 @@ const NotchedOutline = React.forwardRef(function NotchedOutline(props, ref) {
4956
children,
5057
classes,
5158
className,
59+
label = '\u200B',
5260
labelWidth: labelWidthProp,
5361
notched,
5462
style,
@@ -62,25 +70,17 @@ const NotchedOutline = React.forwardRef(function NotchedOutline(props, ref) {
6270
<fieldset
6371
aria-hidden
6472
style={{
65-
[`padding${capitalize(align)}`]: 8 + (notched ? 0 : labelWidth / 2),
73+
[`padding${capitalize(align)}`]: 8,
6674
...style,
6775
}}
6876
className={clsx(classes.root, className)}
6977
ref={ref}
7078
{...other}
7179
>
72-
<legend
73-
className={classes.legend}
74-
style={{
75-
// IE 11: fieldset with legend does not render
76-
// a border radius. This maintains consistency
77-
// by always having a legend rendered
78-
width: notched ? labelWidth : 0.01,
79-
}}
80-
>
80+
<legend className={classes.legend} style={{ maxWidth: notched ? '150px' : '0px' }}>
8181
{/* Use the nominal use case of the legend, avoid rendering artefacts. */}
8282
{/* eslint-disable-next-line react/no-danger */}
83-
<span dangerouslySetInnerHTML={{ __html: '&#8203;' }} />
83+
<span>{label}</span>
8484
</legend>
8585
</fieldset>
8686
);

packages/material-ui/src/OutlinedInput/OutlinedInput.js

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const OutlinedInput = React.forwardRef(function OutlinedInput(props, ref) {
9595
classes,
9696
fullWidth = false,
9797
inputComponent = 'input',
98+
label,
9899
labelWidth = 0,
99100
multiline = false,
100101
notched,
@@ -107,6 +108,7 @@ const OutlinedInput = React.forwardRef(function OutlinedInput(props, ref) {
107108
renderSuffix={state => (
108109
<NotchedOutline
109110
className={classes.notchedOutline}
111+
label={label}
110112
labelWidth={labelWidth}
111113
notched={
112114
typeof notched !== 'undefined'

packages/material-ui/src/TextField/TextField.js

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const TextField = React.forwardRef(function TextField(props, ref) {
116116
InputMore.notched = InputLabelProps.shrink;
117117
}
118118

119+
InputMore.label = `${label}${required ? ' *' : ''}`;
119120
InputMore.labelWidth = labelWidth;
120121
}
121122

0 commit comments

Comments
 (0)