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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TextField] Document how to hide label in FilledInput #23738

Closed
2 tasks done
AGPX opened this issue Nov 26, 2020 · 6 comments 路 Fixed by #23915
Closed
2 tasks done

[TextField] Document how to hide label in FilledInput #23738

AGPX opened this issue Nov 26, 2020 · 6 comments 路 Fixed by #23915
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@AGPX
Copy link

AGPX commented Nov 26, 2020

The TextField top padding is wrong when variant is 'filled' and no label is specified.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

When variant = 'filled' and no label is used, the top padding of the TextField seems to still consider the label space (when variant = 'standard', you haven't this issue).

Expected Behavior 馃

When variant = 'filled' and no label is used, the top padding of the TextField must be reduced like the one used when variant = 'standard'.

Steps to Reproduce 馃暪

Steps:

Example at the link: https://codesandbox.io/s/material-ui-issue-forked-p9bx3

  1. Create a TextField.
  2. Set the variant attribute to 'filled'.

The issue is in the classes: '.MuiFilledInput-input' (and '.MuiFilledInput-inputMarginDense' for the small size).

Context 馃敠

Your Environment 馃寧

Tech Version
Material-UI v4.11.1
React
Browser
TypeScript
etc.
@AGPX AGPX added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 26, 2020
@oliviertassinari oliviertassinari added the component: text field This is the name of the generic UI component, not the React module! label Nov 27, 2020
@marthaerm
Copy link
Contributor

@oliviertassinari is this issue good to take? I would like to give It a try!

@oliviertassinari
Copy link
Member

@AGPX There is a feature for this, but it's barely documented:

Before
Capture d鈥檈虂cran 2020-11-27 a虁 16 48 56

After
Capture d鈥檈虂cran 2020-11-27 a虁 16 49 06

      <TextField
        hiddenLabel
        id="standard-start-adornment"
        size="small"
        variant="filled"
        InputProps={{
          startAdornment: <InputAdornment position="start">Kg</InputAdornment>
        }}
      />

How about we add a new demo under https://next.material-ui.com/components/text-fields/#sizes?

@oliviertassinari
Copy link
Member

Maybe something like this?

diff --git a/docs/src/pages/components/text-fields/TextFieldHiddenLabel.tsx b/docs/src/pages/components/text-fields/TextFieldHiddenLabel.tsx
new file mode 100644
index 0000000000..456953127e
--- /dev/null
+++ b/docs/src/pages/components/text-fields/TextFieldHiddenLabel.tsx
@@ -0,0 +1,43 @@
+import * as React from 'react';
+import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
+import TextField from '@material-ui/core/TextField';
+import Box from '@material-ui/core/Box';
+
+const useStyles = makeStyles((theme: Theme) =>
+  createStyles({
+    root: {
+      '& .MuiTextField-root': {
+        margin: theme.spacing(1),
+        width: 200,
+      },
+    },
+  }),
+);
+
+export default function TextFieldHiddenLabel() {
+  const classes = useStyles();
+
+  return (
+    <form className={classes.root} noValidate autoComplete="off">
+      <Box sx={{ display: 'flex', alignItems: 'center' }}>
+        <label htmlFor="filled-hidden-label-small">Hidden label</label>
+        <TextField
+          hiddenLabel
+          id="filled-hidden-label-small"
+          defaultValue="Small"
+          variant="filled"
+          size="small"
+        />
+      </Box>
+      <Box sx={{ display: 'flex', alignItems: 'center' }}>
+        <label htmlFor="filled-hidden-label-normal">Hidden label</label>
+        <TextField
+          hiddenLabel
+          id="filled-hidden-label-normal"
+          defaultValue="Normal"
+          variant="filled"
+        />
+      </Box>
+    </form>
+  );
+}
diff --git a/docs/src/pages/components/text-fields/text-fields.md b/docs/src/pages/components/text-fields/text-fields.md
index 6db59637be..b9c2669f6a 100644
--- a/docs/src/pages/components/text-fields/text-fields.md
+++ b/docs/src/pages/components/text-fields/text-fields.md
@@ -71,6 +71,10 @@ Fancy smaller inputs? Use the `size` prop.

 {{"demo": "pages/components/text-fields/TextFieldSizes.js"}}

+The `filled` variant input height can be further reduced by rendering the label outside of it.
+
+{{"demo": "pages/components/text-fields/TextFieldHiddenLabel.js"}}
+
 ## Layout

 `margin` prop can be used to alter the vertical spacing of inputs.

Capture d鈥檈虂cran 2020-11-27 a虁 20 57 42

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 27, 2020
@oliviertassinari oliviertassinari changed the title TextField: wrong top padding. [TextField] Document how to hide label in FilledInput Nov 27, 2020
@AGPX
Copy link
Author

AGPX commented Nov 27, 2020

Excuse me, but if a label is not specified, why do I have to explicitly hide it? The current one is not an expected behavior.
However, with the hiddenLabel, it works and this definitely need to be documented and/or an example added. Thanks for the quick support.

@oliviertassinari
Copy link
Member

@AGPX You are right, the prop was introduced in #16671, we can polish it more. For instance, Textfield should likely set the prop automatically.

frederic-lang added a commit to frederic-lang/material-ui that referenced this issue Dec 9, 2020
@smajl
Copy link

smajl commented Jul 20, 2021

FYI, hiddenLabel doesn't work correctly for multiline filled inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: text field This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants