Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OutlinedInput] Fix offscreen label strikethrough #17680

Merged

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Oct 3, 2019

Disclaimer: Not tested cross-browser, yet.

new version
old version

Currently the notch in the outlined input is calculated based on the layout used by the label. This approach does not work if the input is rendered without layout (display: none).

The approach in this PR does not rely on layout computation with JS but purely on css (apart from flipping the notched state). The label is moved inside the legend and always part of the layout (but visibly hidden to avoid visual duplication). Since we can't transition width we transition max-width. This comes with the caveat that open transition does not look like it has a fixed length (since we always transition from 0 to a hardcoded value). Closing looks better though.

Closes #17355
Closes #17305
Closes #16774
Closes #15713
Closes #16465
Closes #17680
Closes #19213

@eps1lon eps1lon added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels Oct 3, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented Oct 3, 2019

@material-ui/core: parsed: +0.19% , gzip: +0.09%

Details of bundle changes.

Comparing: f1080b6...3aa7f32

bundle Size Change Size Gzip Change Gzip
TablePagination ▲ +837 B (+0.59% ) 144 kB ▲ +191 B (+0.46% ) 42 kB
Select ▲ +837 B (+0.72% ) 117 kB ▲ +150 B (+0.44% ) 34.6 kB
OutlinedInput ▲ +811 B (+1.09% ) 75 kB ▲ +144 B (+0.62% ) 23.3 kB
TextField ▲ +679 B (+0.54% ) 126 kB ▲ +122 B (+0.33% ) 36.6 kB
@material-ui/core ▲ +679 B (+0.19% ) 361 kB ▲ +91 B (+0.09% ) 98.8 kB
@material-ui/core[umd] ▲ +659 B (+0.21% ) 318 kB ▲ +111 B (+0.12% ) 92 kB
AppBar -- 64.1 kB ▼ -57 B (-0.28% ) 20 kB
SpeedDialIcon -- 64.7 kB ▼ -57 B (-0.28% ) 20.3 kB
StepButton -- 82.5 kB ▲ +11 B (+0.04% ) 26.1 kB
Rating -- 70.6 kB ▲ +8 B (+0.04% ) 22.7 kB
BottomNavigationAction -- 75.7 kB ▲ +6 B (+0.03% ) 23.9 kB
CardActionArea -- 75.3 kB ▲ +5 B (+0.02% ) 23.7 kB
Alert -- 83.9 kB ▼ -4 B (-0.02% ) 26.3 kB
BottomNavigation -- 62.5 kB ▲ +4 B (+0.02% ) 19.6 kB
ButtonGroup -- 83.4 kB ▲ +4 B (+0.02% ) 25.5 kB
Container -- 63.4 kB ▲ +3 B (+0.02% ) 19.8 kB
Snackbar -- 75.5 kB ▲ +3 B (+0.01% ) 23.6 kB
@material-ui/lab -- 185 kB ▲ +2 B (0.00% ) 55.2 kB
Autocomplete -- 132 kB ▲ +2 B (0.00% ) 41.3 kB
ButtonBase -- 74.2 kB ▲ +2 B (+0.01% ) 23.3 kB
CardContent -- 62.1 kB ▲ +2 B (+0.01% ) 19.4 kB
CardMedia -- 62.5 kB ▲ +2 B (+0.01% ) 19.7 kB
Chip -- 82.8 kB ▲ +2 B (+0.01% ) 25.4 kB
CssBaseline -- 57.7 kB ▲ +2 B (+0.01% ) 18.1 kB
Dialog -- 83.2 kB ▲ +2 B (+0.01% ) 25.9 kB
DialogContent -- 62.3 kB ▲ +2 B (+0.01% ) 19.5 kB
GridList -- 62.6 kB ▲ +2 B (+0.01% ) 19.7 kB
IconButton -- 76.3 kB ▲ +2 B (+0.01% ) 23.8 kB
Input -- 72.6 kB ▲ +2 B (+0.01% ) 22.7 kB
InputBase -- 70.8 kB ▲ +2 B (+0.01% ) 22.2 kB
ListItem -- 77.3 kB ▲ +2 B (+0.01% ) 24.2 kB
SpeedDial -- 86.4 kB ▲ +2 B (+0.01% ) 27.2 kB
SpeedDialAction -- 118 kB ▲ +2 B (+0.01% ) 37.5 kB
SvgIcon -- 63.2 kB ▼ -2 B (-0.01% ) 19.8 kB
TableSortLabel -- 77.6 kB ▲ +2 B (+0.01% ) 24.4 kB
Tabs -- 85.8 kB ▲ +2 B (+0.01% ) 27.2 kB
ToggleButton -- 76.3 kB ▲ +2 B (+0.01% ) 24.2 kB
AlertTitle -- 64.3 kB ▲ +1 B (0.00% ) 20.2 kB
Avatar -- 65.4 kB ▲ +1 B (0.00% ) 20.6 kB
AvatarGroup -- 62.4 kB ▲ +1 B (+0.01% ) 19.6 kB
Backdrop -- 68 kB ▲ +1 B (0.00% ) 21 kB
Badge -- 65.4 kB ▲ +1 B (0.00% ) 20.4 kB
Box -- 71 kB ▼ -1 B (-0.00% ) 21.7 kB
Breadcrumbs -- 67.9 kB ▲ +1 B (0.00% ) 21.3 kB
Button -- 79.9 kB ▲ +1 B (0.00% ) 24.5 kB
Card -- 63 kB ▲ +1 B (+0.01% ) 19.7 kB
CardHeader -- 65.2 kB ▲ +1 B (0.00% ) 20.5 kB
Checkbox -- 83.2 kB ▲ +1 B (0.00% ) 26.3 kB
Collapse -- 68.2 kB ▼ -1 B (-0.00% ) 21.1 kB
DialogActions -- 62.2 kB ▼ -1 B (-0.01% ) 19.5 kB
DialogTitle -- 64.4 kB ▲ +1 B (0.00% ) 20.2 kB
Divider -- 62.7 kB ▲ +1 B (+0.01% ) 19.7 kB
Drawer -- 85 kB ▲ +1 B (0.00% ) 25.8 kB
ExpansionPanel -- 72.5 kB ▲ +1 B (0.00% ) 22.7 kB
ExpansionPanelActions -- 62.2 kB ▲ +1 B (+0.01% ) 19.5 kB
ExpansionPanelDetails -- 62.1 kB ▲ +1 B (+0.01% ) 19.4 kB
ExpansionPanelSummary -- 78.3 kB ▲ +1 B (0.00% ) 24.7 kB
Fab -- 77 kB ▲ +1 B (0.00% ) 24 kB
Fade -- 23.6 kB ▲ +1 B (+0.01% ) 8 kB
FilledInput -- 73.7 kB ▲ +1 B (0.00% ) 22.9 kB
FormControlLabel -- 65.6 kB ▲ +1 B (0.00% ) 20.6 kB
FormHelperText -- 63.5 kB ▲ +1 B (+0.01% ) 20 kB
FormLabel -- 63.6 kB ▼ -1 B (-0.01% ) 19.7 kB
Grid -- 65.2 kB ▲ +1 B (0.00% ) 20.4 kB
GridListTileBar -- 63.3 kB ▲ +1 B (+0.01% ) 19.9 kB
Grow -- 24.2 kB ▼ -1 B (-0.01% ) 8.21 kB
InputAdornment -- 65.2 kB ▲ +1 B (0.00% ) 20.5 kB
InputLabel -- 65.5 kB ▼ -1 B (-0.00% ) 20.2 kB
LinearProgress -- 65.4 kB ▲ +1 B (0.00% ) 20.5 kB
List -- 62.5 kB ▼ -1 B (-0.01% ) 19.5 kB
ListItemAvatar -- 62.2 kB ▲ +1 B (+0.01% ) 19.5 kB
ListItemIcon -- 62.3 kB ▲ +1 B (+0.01% ) 19.5 kB
ListItemText -- 65.1 kB ▲ +1 B (0.00% ) 20.4 kB
ListSubheader -- 62.9 kB ▲ +1 B (+0.01% ) 19.8 kB
Menu -- 88.9 kB ▲ +1 B (0.00% ) 27.4 kB
MenuItem -- 78.4 kB ▲ +1 B (0.00% ) 24.5 kB
MenuList -- 66.2 kB ▲ +1 B (0.00% ) 20.7 kB
MobileStepper -- 68 kB ▲ +1 B (0.00% ) 21.3 kB
Paper -- 62.5 kB ▼ -1 B (-0.01% ) 19.5 kB
Popover -- 83.3 kB ▲ +1 B (0.00% ) 25.8 kB
Popper -- 28.8 kB ▲ +1 B (+0.01% ) 10.3 kB
Radio -- 84.3 kB ▲ +1 B (0.00% ) 26.6 kB
RadioGroup -- 64.6 kB ▲ +1 B (0.00% ) 20 kB
Slider -- 76.8 kB ▲ +1 B (0.00% ) 24.3 kB
SnackbarContent -- 63.7 kB ▲ +1 B (0.00% ) 20.1 kB
Step -- 62.8 kB ▲ +1 B (+0.01% ) 19.7 kB
StepConnector -- 62.8 kB ▲ +1 B (+0.01% ) 19.8 kB
StepIcon -- 64.8 kB ▼ -1 B (-0.00% ) 20.2 kB
StepLabel -- 68.7 kB ▲ +1 B (0.00% ) 21.7 kB
Stepper -- 65 kB ▲ +1 B (0.00% ) 20.5 kB
SwipeableDrawer -- 92.4 kB ▲ +1 B (0.00% ) 28.9 kB
Switch -- 82.4 kB ▲ +1 B (0.00% ) 26 kB
Tab -- 76.5 kB ▲ +1 B (0.00% ) 24.2 kB
Table -- 62.7 kB ▲ +1 B (+0.01% ) 19.7 kB
TableBody -- 62.2 kB ▲ +1 B (+0.01% ) 19.5 kB
TableCell -- 64.2 kB ▲ +1 B (0.00% ) 20.2 kB
TableContainer -- 62.1 kB ▲ +1 B (+0.01% ) 19.4 kB
TableFooter -- 62.2 kB ▲ +1 B (+0.01% ) 19.5 kB
TableHead -- 62.2 kB ▲ +1 B (+0.01% ) 19.5 kB
Toolbar -- 62.5 kB ▲ +1 B (+0.01% ) 19.6 kB
TreeItem -- 74.1 kB ▼ -1 B (-0.00% ) 23.5 kB
TreeView -- 66.8 kB ▲ +1 B (0.00% ) 21 kB
Typography -- 63.8 kB ▼ -1 B (-0.01% ) 20 kB
@material-ui/styles -- 51.2 kB -- 15.4 kB
@material-ui/system -- 14.8 kB -- 4.07 kB
CardActions -- 62.2 kB -- 19.5 kB
CircularProgress -- 64.2 kB -- 20.3 kB
ClickAwayListener -- 3.91 kB -- 1.55 kB
colorManipulator -- 3.88 kB -- 1.52 kB
DialogContentText -- 64.2 kB -- 20.2 kB
docs.landing -- 51 kB -- 13.5 kB
docs.main -- 617 kB -- 196 kB
FormControl -- 64.5 kB -- 20.1 kB
FormGroup -- 62.1 kB -- 19.5 kB
GridListTile -- 63.9 kB -- 20 kB
Hidden -- 66.1 kB -- 20.7 kB
Icon -- 62.9 kB -- 19.7 kB
Link -- 66.7 kB -- 21.1 kB
ListItemSecondaryAction -- 62.1 kB -- 19.5 kB
Modal -- 14.5 kB -- 5.05 kB
NativeSelect -- 77 kB -- 24.3 kB
NoSsr -- 2.19 kB -- 1.04 kB
Portal -- 2.92 kB -- 1.3 kB
RootRef -- 4.24 kB -- 1.64 kB
Skeleton -- 63 kB -- 19.9 kB
Slide -- 25.6 kB -- 8.73 kB
StepContent -- 69.3 kB -- 21.7 kB
styles/createMuiTheme -- 16.6 kB -- 5.83 kB
TableRow -- 62.6 kB -- 19.6 kB
TextareaAutosize -- 5.12 kB -- 2.14 kB
ToggleButtonGroup -- 63.3 kB -- 19.9 kB
Tooltip -- 102 kB -- 32.3 kB
useAutocomplete -- 14.5 kB -- 5.25 kB
useMediaQuery -- 2.51 kB -- 1.06 kB
Zoom -- 23.6 kB -- 8.12 kB

Generated by 🚫 dangerJS against 3aa7f32

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 3, 2019

I find the idea interesting, relying on CSS purely sounds better. Sacrificing a bit on the animation probably worth it. In our case, maybe we can accelerate the close animation? Does it still work with a long label?

@eps1lon
Copy link
Member Author

eps1lon commented Oct 3, 2019

In our case, maybe we can accelerate the close animation?

I'll have to check what the spec says anyway. I didn't think about accelerating the animation.

Does it still work with a long label?

Seems like (check "Multiline Placeholder"). Though there's currently an issue with the height (it changes between shrunk states for non dense inputs).

@FabianL1
Copy link

FabianL1 commented Oct 8, 2019

Hey - I would be willing to help you on this since this is also important for us. What can I do?

@mbrookes
Copy link
Member

mbrookes commented Oct 8, 2019

@eps1lon The new version no longer animates the opening from the center. Was that intentional, or yet to be addressed with the new approach?

@eps1lon
Copy link
Member Author

eps1lon commented Oct 8, 2019

Yep, I tried to explain that in the pr description

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 23, 2019

@eps1lon I have tried to push this effort one step further. @mbrookes What do you think of this end result?
animation

I have tried to reproduce how Google handles the problem in : https://accounts.google.com/signin/v2/identifier.

Here is what happens with the latest commit:

Nov-24-2019 00-07-12

I have used the delay and duration to leave a gap at the "right" moment.

From my perspective, it's good enough. We should be able to make the logic backward compatible and to solve #18196, #17355, #17305 and #13364.

@mbrookes
Copy link
Member

mbrookes commented Nov 23, 2019

@oliviertassinari On mobile on the train home, but from what I can tell from the gif, it looks perfect!

@oliviertassinari
Copy link
Member

@eps1lon What do you think? It seems that we can close 4 issues at once, it has potential :). Do you want to complete the effort with such an animation timing approach? I see the following missing:

  • The name of the newly introduced prop could be improved, maybe labelShadow?
  • Remove the usage of labelWidth. For backward compatibility, I think that we need to keep it working. We could deprecate it.
  • We need to have a look at the customization story.

@eps1lon
Copy link
Member Author

eps1lon commented Nov 24, 2019

I'd be willing to sacrifice some of the outline animation (the line retracting fro the middle) to have a 100% CSS solution that does not require any JS beyond adding/removing a classname depending on the filled/active state.

I'll check this out tomorrow. Solving a common footgun for such an important component would be very nice.

@EliteMasterEric
Copy link

Hopefully this pull request can be revised promptly and merged soon. The workaround referenced in #17355 (which requires removing the content of tabs when switching away) has caused more problems than it solves, due to the fact that I cannot maintain references to components within those tabs..

@eps1lon eps1lon self-assigned this Dec 3, 2019
@eps1lon
Copy link
Member Author

eps1lon commented Dec 3, 2019

@oliviertassinari Could you explain what you tried to achieve with your commit? I can no longer see any transition which is especially confusing since @mbrookes questioned my implementation with some transition but completely agreed with a implementation without any. Seems like I'm missing some context.

Also a friendly reminder to not rebase my branches while pushing your commits. The build with my original implementation is now lost. It would've helped to have easy access to how it used to work.

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 3, 2019

In the current implementation on master, I think that we see the transition too much, meaning, the purpose of it is to allow the user to focus on what he is going to type in the field, and to not distract him with something else.
In its current form, the transition is at its minimum, leaving space for the label as late as possible, and filling space for the label as soon as possible.

My hope with the commit was that it would enable to preview the change on Netlify, without having the overhead of another pull request. However, it didn't go as expected, instead, we have lost the previous commit preview. Feel free to throw this commit away. I might have solved some conflicts with master too, I don't remember. Sorry, I hoped you wouldn't mind.

@mbrookes
Copy link
Member

mbrookes commented Dec 3, 2019

@mbrookes questioned my implementation with some transition but completely agreed with a implementation without any

Since the deploy preview failed, I was basing my comment on the gif, which, unless my eyes are deceiving me, does appear to animate. If it doesn't, then the illusion is enough to trick my brain (not that that would be hard!).

@eps1lon
Copy link
Member Author

eps1lon commented Dec 4, 2019

@mbrookes Just to clarify: So you were actually opposed to the transition in the first place? My implementation had a transition. Olivier "removed" every transition. "removed" because the smaller max-width is, the more obvious the transition. 150px was small enough to have a transition but obviously only works with small inputs. Olivier used 1000px. At that point the transition is essentially not visible but definitely less visible than before: https://ezgif.com/split/ezgif-6-bb64fd4f2a79.gif

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 4, 2019

Side note, you are right, the motivation for using 1000px was to support very long labels. I haven't much taken the transition into account in this value. We could likely use a smaller value. Maybe 600px?

@oliviertassinari
Copy link
Member

The gap can be fixed with the fragment change proposed in #17680 (comment). I think that we can handle it in a follow-up pull request.

@eps1lon
Copy link
Member Author

eps1lon commented Jan 20, 2020

The gap can be fixed with the fragment change proposed in #17680 (comment). I think that we can handle it in a follow-up pull request.

So that was that about. I was confused about mixing required in the condition. It isn't needed. Just checking for label is enough. I didn't accept the change at first because it could lead to reparenting which cause react to re-mount which might lead to confusing behavior.

@eps1lon
Copy link
Member Author

eps1lon commented Jan 20, 2020

I like codesandbox/ci: https://codesandbox.io/s/material-demo-267kg

Still: Please provide a label to your inputs.

@eps1lon eps1lon merged commit c29c8ad into mui:master Jan 21, 2020
@eps1lon eps1lon deleted the feat/OutlinedInput/notch-html-css-visibility branch January 21, 2020 08:45
@eps1lon
Copy link
Member Author

eps1lon commented Jan 21, 2020

Already looking forward to the stress tests we haven't considered 😄 If this PR caused a bug in your application please open a new issue.

@kusmierz
Copy link
Contributor

btw, shouldn't be fontSize: '0.75rem' defined as fontSize: '0.75em' instead in material-ui/src/OutlinedInput/NotchedOutline.js file? Having different htmlFontSize (ie. 10, so html#font-size is 62.5%) results to small "notch" (in the example with htmlFontSize = 10, the <legend> has fontSize equals 7.5px, but should it be 12px imho)...
image

@oliviertassinari
Copy link
Member

@kusmierz Your comment sounds accurate. Do you want to open a pull request :)?

0.75 is the label scaling factor. We were lucky that the label default font size is 16px and match the default root font-size: 16px.

@kusmierz
Copy link
Contributor

sure, with pleasure. Please, have a look at #19409

@kelly-tock
Copy link

I'm seeing a slight regression in the label notch as well on chrome:

4.8:
image

4.9:
image

does this have to do with changing the html font size?

typography: {
      fontFamily: sansRegular,
      htmlFontSize: 10,
    },

will @kusmierz PR fix this?

@kusmierz
Copy link
Contributor

it should :)

@kusmierz
Copy link
Contributor

kusmierz commented Feb 4, 2020

hey guys, 4.9.1 has been released, and now this PR is in master branch... but another issue occurred. Now the "notch" is too big. I've addressed it in PR #19558.

@kelly-tock
Copy link

When can we expect a release?

@oliviertassinari
Copy link
Member

@kelly-tock Already released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module!
Projects
None yet
9 participants