Skip to content
New issue

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

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

Already on GitHub? # to your account

[docs][TextField] Add suffix shrink demo #44744

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions docs/data/material/components/text-fields/InputSuffixShrink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { filledInputClasses } from '@mui/material/FilledInput';
import { inputBaseClasses } from '@mui/material/InputBase';
import TextField from '@mui/material/TextField';
import InputAdornment from '@mui/material/InputAdornment';

export default function InputSuffixShrink() {
return (
<Box
component="form"
sx={{ '& > :not(style)': { m: 1, width: '25ch' } }}
noValidate
autoComplete="off"
>
<TextField
id="outlined-suffix-shrink"
label="Outlined"
variant="outlined"
slotProps={{
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
opacity: 0,
pointerEvents: 'none',
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
lbs
</InputAdornment>
),
},
}}
/>
<TextField
id="filled-suffix-shrink"
label="Filled"
variant="filled"
slotProps={{
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
alignSelf: 'flex-end',
opacity: 0,
pointerEvents: 'none',
[`.${filledInputClasses.root} &`]: {
marginBottom: '7.5px',
},
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
days
</InputAdornment>
),
},
}}
/>
<TextField
id="standard-suffix-shrink"
label="Standard"
variant="standard"
slotProps={{
htmlInput: {
sx: { textAlign: 'right' },
},
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
alignSelf: 'flex-end',
margin: 0,
marginBottom: '5px',
opacity: 0,
pointerEvents: 'none',
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
@gmail.com
</InputAdornment>
),
},
}}
/>
</Box>
);
}
97 changes: 97 additions & 0 deletions docs/data/material/components/text-fields/InputSuffixShrink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { filledInputClasses } from '@mui/material/FilledInput';
import { inputBaseClasses } from '@mui/material/InputBase';
import TextField from '@mui/material/TextField';
import InputAdornment from '@mui/material/InputAdornment';

export default function InputSuffixShrink() {
return (
<Box
component="form"
sx={{ '& > :not(style)': { m: 1, width: '25ch' } }}
noValidate
autoComplete="off"
>
<TextField
id="outlined-suffix-shrink"
label="Outlined"
variant="outlined"
slotProps={{
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
opacity: 0,
pointerEvents: 'none',
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
lbs
</InputAdornment>
),
},
}}
/>
<TextField
id="filled-suffix-shrink"
label="Filled"
variant="filled"
slotProps={{
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
alignSelf: 'flex-end',
opacity: 0,
pointerEvents: 'none',
[`.${filledInputClasses.root} &`]: {
marginBottom: '7.5px',
},
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
days
</InputAdornment>
),
},
}}
/>
<TextField
id="standard-suffix-shrink"
label="Standard"
variant="standard"
slotProps={{
htmlInput: {
sx: { textAlign: 'right' },
},
input: {
endAdornment: (
<InputAdornment
position="end"
sx={{
alignSelf: 'flex-end',
margin: 0,
marginBottom: '5px',
opacity: 0,
pointerEvents: 'none',
[`[data-shrink=true] ~ .${inputBaseClasses.root} > &`]: {
opacity: 1,
},
}}
>
@gmail.com
</InputAdornment>
),
},
}}
/>
</Box>
);
}
7 changes: 7 additions & 0 deletions docs/data/material/components/text-fields/text-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ For instance, you can use an icon button to hide or reveal the password.

{{"demo": "InputAdornments.js"}}

#### Customizing adornments

You can apply custom styles to adornments, and trigger changes to one based on attributes from another.
For example, the demo below uses the label's `[data-shrink=true]` attribute to make the suffix visible (via opacity) when the label is in its shrunken state.

{{"demo": "InputSuffixShrink.js"}}

## Sizes

Fancy smaller inputs? Use the `size` prop.
Expand Down
Loading