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
Comments
@oliviertassinari is this issue good to take? I would like to give It a try! |
@AGPX There is a feature for this, but it's barely documented: <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? |
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. |
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. |
FYI, |
The TextField top padding is wrong when variant is 'filled' and no label is specified.
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
The issue is in the classes: '.MuiFilledInput-input' (and '.MuiFilledInput-inputMarginDense' for the small size).
Context 馃敠
Your Environment 馃寧
The text was updated successfully, but these errors were encountered: