index
int64
0
0
repo_id
stringlengths
16
181
file_path
stringlengths
28
270
content
stringlengths
1
11.6M
__index_level_0__
int64
0
10k
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/LayoutTextFields.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; function RedBar() { return ( <Box sx={{ height: 20, backgroundColor: (theme) => theme.palette.mode === 'light' ? 'rgba(255, 0, 0, 0.1)' : 'rgb(255 132 132 / 25%)', }} /> ); } export default function LayoutTextFields() { return ( <Box sx={{ display: 'flex', flexDirection: 'column', '& .MuiTextField-root': { width: '25ch' }, }} > <RedBar /> <TextField label={'margin="none"'} id="margin-none" /> <RedBar /> <TextField label={'margin="dense"'} id="margin-dense" margin="dense" /> <RedBar /> <TextField label={'margin="normal"'} id="margin-normal" margin="normal" /> <RedBar /> </Box> ); }
3,200
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/LayoutTextFields.tsx.preview
<RedBar /> <TextField label={'margin="none"'} id="margin-none" /> <RedBar /> <TextField label={'margin="dense"'} id="margin-dense" margin="dense" /> <RedBar /> <TextField label={'margin="normal"'} id="margin-normal" margin="normal" /> <RedBar />
3,201
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/MultilineTextFields.js
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function MultilineTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField id="outlined-multiline-flexible" label="Multiline" multiline maxRows={4} /> <TextField id="outlined-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline /> <TextField id="outlined-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" /> </div> <div> <TextField id="filled-multiline-flexible" label="Multiline" multiline maxRows={4} variant="filled" /> <TextField id="filled-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline variant="filled" /> <TextField id="filled-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" variant="filled" /> </div> <div> <TextField id="standard-multiline-flexible" label="Multiline" multiline maxRows={4} variant="standard" /> <TextField id="standard-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline variant="standard" /> <TextField id="standard-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" variant="standard" /> </div> </Box> ); }
3,202
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/MultilineTextFields.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function MultilineTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField id="outlined-multiline-flexible" label="Multiline" multiline maxRows={4} /> <TextField id="outlined-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline /> <TextField id="outlined-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" /> </div> <div> <TextField id="filled-multiline-flexible" label="Multiline" multiline maxRows={4} variant="filled" /> <TextField id="filled-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline variant="filled" /> <TextField id="filled-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" variant="filled" /> </div> <div> <TextField id="standard-multiline-flexible" label="Multiline" multiline maxRows={4} variant="standard" /> <TextField id="standard-textarea" label="Multiline Placeholder" placeholder="Placeholder" multiline variant="standard" /> <TextField id="standard-multiline-static" label="Multiline" multiline rows={4} defaultValue="Default Value" variant="standard" /> </div> </Box> ); }
3,203
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/SelectTextFields.js
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; import MenuItem from '@mui/material/MenuItem'; const currencies = [ { value: 'USD', label: '$', }, { value: 'EUR', label: '€', }, { value: 'BTC', label: '฿', }, { value: 'JPY', label: '¥', }, ]; export default function SelectTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField id="outlined-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="outlined-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> <div> <TextField id="filled-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" variant="filled" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="filled-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" variant="filled" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> <div> <TextField id="standard-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" variant="standard" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="standard-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" variant="standard" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> </Box> ); }
3,204
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/SelectTextFields.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; import MenuItem from '@mui/material/MenuItem'; const currencies = [ { value: 'USD', label: '$', }, { value: 'EUR', label: '€', }, { value: 'BTC', label: '฿', }, { value: 'JPY', label: '¥', }, ]; export default function SelectTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField id="outlined-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="outlined-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> <div> <TextField id="filled-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" variant="filled" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="filled-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" variant="filled" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> <div> <TextField id="standard-select-currency" select label="Select" defaultValue="EUR" helperText="Please select your currency" variant="standard" > {currencies.map((option) => ( <MenuItem key={option.value} value={option.value}> {option.label} </MenuItem> ))} </TextField> <TextField id="standard-select-currency-native" select label="Native select" defaultValue="EUR" SelectProps={{ native: true, }} helperText="Please select your currency" variant="standard" > {currencies.map((option) => ( <option key={option.value} value={option.value}> {option.label} </option> ))} </TextField> </div> </Box> ); }
3,205
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/StateTextFields.js
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function StateTextFields() { const [name, setName] = React.useState('Cat in the Hat'); return ( <Box component="form" sx={{ '& > :not(style)': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <TextField id="outlined-controlled" label="Controlled" value={name} onChange={(event) => { setName(event.target.value); }} /> <TextField id="outlined-uncontrolled" label="Uncontrolled" defaultValue="foo" /> </Box> ); }
3,206
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/StateTextFields.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function StateTextFields() { const [name, setName] = React.useState('Cat in the Hat'); return ( <Box component="form" sx={{ '& > :not(style)': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <TextField id="outlined-controlled" label="Controlled" value={name} onChange={(event: React.ChangeEvent<HTMLInputElement>) => { setName(event.target.value); }} /> <TextField id="outlined-uncontrolled" label="Uncontrolled" defaultValue="foo" /> </Box> ); }
3,207
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/StateTextFields.tsx.preview
<TextField id="outlined-controlled" label="Controlled" value={name} onChange={(event: React.ChangeEvent<HTMLInputElement>) => { setName(event.target.value); }} /> <TextField id="outlined-uncontrolled" label="Uncontrolled" defaultValue="foo" />
3,208
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/TextFieldHiddenLabel.js
import * as React from 'react'; import Stack from '@mui/material/Stack'; import TextField from '@mui/material/TextField'; export default function TextFieldHiddenLabel() { return ( <Stack component="form" sx={{ width: '25ch', }} spacing={2} noValidate autoComplete="off" > <TextField hiddenLabel id="filled-hidden-label-small" defaultValue="Small" variant="filled" size="small" /> <TextField hiddenLabel id="filled-hidden-label-normal" defaultValue="Normal" variant="filled" /> </Stack> ); }
3,209
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/TextFieldHiddenLabel.tsx
import * as React from 'react'; import Stack from '@mui/material/Stack'; import TextField from '@mui/material/TextField'; export default function TextFieldHiddenLabel() { return ( <Stack component="form" sx={{ width: '25ch', }} spacing={2} noValidate autoComplete="off" > <TextField hiddenLabel id="filled-hidden-label-small" defaultValue="Small" variant="filled" size="small" /> <TextField hiddenLabel id="filled-hidden-label-normal" defaultValue="Normal" variant="filled" /> </Stack> ); }
3,210
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/TextFieldHiddenLabel.tsx.preview
<TextField hiddenLabel id="filled-hidden-label-small" defaultValue="Small" variant="filled" size="small" /> <TextField hiddenLabel id="filled-hidden-label-normal" defaultValue="Normal" variant="filled" />
3,211
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/TextFieldSizes.js
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function TextFieldSizes() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField label="Size" id="outlined-size-small" defaultValue="Small" size="small" /> <TextField label="Size" id="outlined-size-normal" defaultValue="Normal" /> </div> <div> <TextField label="Size" id="filled-size-small" defaultValue="Small" variant="filled" size="small" /> <TextField label="Size" id="filled-size-normal" defaultValue="Normal" variant="filled" /> </div> <div> <TextField label="Size" id="standard-size-small" defaultValue="Small" size="small" variant="standard" /> <TextField label="Size" id="standard-size-normal" defaultValue="Normal" variant="standard" /> </div> </Box> ); }
3,212
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/TextFieldSizes.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function TextFieldSizes() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField label="Size" id="outlined-size-small" defaultValue="Small" size="small" /> <TextField label="Size" id="outlined-size-normal" defaultValue="Normal" /> </div> <div> <TextField label="Size" id="filled-size-small" defaultValue="Small" variant="filled" size="small" /> <TextField label="Size" id="filled-size-normal" defaultValue="Normal" variant="filled" /> </div> <div> <TextField label="Size" id="standard-size-small" defaultValue="Small" size="small" variant="standard" /> <TextField label="Size" id="standard-size-normal" defaultValue="Normal" variant="standard" /> </div> </Box> ); }
3,213
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/UseFormControl.js
import * as React from 'react'; import FormControl, { useFormControl } from '@mui/material/FormControl'; import OutlinedInput from '@mui/material/OutlinedInput'; import FormHelperText from '@mui/material/FormHelperText'; function MyFormHelperText() { const { focused } = useFormControl() || {}; const helperText = React.useMemo(() => { if (focused) { return 'This field is being focused'; } return 'Helper text'; }, [focused]); return <FormHelperText>{helperText}</FormHelperText>; } export default function UseFormControl() { return ( <form noValidate autoComplete="off"> <FormControl sx={{ width: '25ch' }}> <OutlinedInput placeholder="Please enter text" /> <MyFormHelperText /> </FormControl> </form> ); }
3,214
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/UseFormControl.tsx
import * as React from 'react'; import FormControl, { useFormControl } from '@mui/material/FormControl'; import OutlinedInput from '@mui/material/OutlinedInput'; import FormHelperText from '@mui/material/FormHelperText'; function MyFormHelperText() { const { focused } = useFormControl() || {}; const helperText = React.useMemo(() => { if (focused) { return 'This field is being focused'; } return 'Helper text'; }, [focused]); return <FormHelperText>{helperText}</FormHelperText>; } export default function UseFormControl() { return ( <form noValidate autoComplete="off"> <FormControl sx={{ width: '25ch' }}> <OutlinedInput placeholder="Please enter text" /> <MyFormHelperText /> </FormControl> </form> ); }
3,215
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/UseFormControl.tsx.preview
<form noValidate autoComplete="off"> <FormControl sx={{ width: '25ch' }}> <OutlinedInput placeholder="Please enter text" /> <MyFormHelperText /> </FormControl> </form>
3,216
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ValidationTextFields.js
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function ValidationTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField error id="outlined-error" label="Error" defaultValue="Hello World" /> <TextField error id="outlined-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." /> </div> <div> <TextField error id="filled-error" label="Error" defaultValue="Hello World" variant="filled" /> <TextField error id="filled-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." variant="filled" /> </div> <div> <TextField error id="standard-error" label="Error" defaultValue="Hello World" variant="standard" /> <TextField error id="standard-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." variant="standard" /> </div> </Box> ); }
3,217
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/ValidationTextFields.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import TextField from '@mui/material/TextField'; export default function ValidationTextFields() { return ( <Box component="form" sx={{ '& .MuiTextField-root': { m: 1, width: '25ch' }, }} noValidate autoComplete="off" > <div> <TextField error id="outlined-error" label="Error" defaultValue="Hello World" /> <TextField error id="outlined-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." /> </div> <div> <TextField error id="filled-error" label="Error" defaultValue="Hello World" variant="filled" /> <TextField error id="filled-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." variant="filled" /> </div> <div> <TextField error id="standard-error" label="Error" defaultValue="Hello World" variant="standard" /> <TextField error id="standard-error-helper-text" label="Error" defaultValue="Hello World" helperText="Incorrect entry." variant="standard" /> </div> </Box> ); }
3,218
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/text-fields/text-fields.md
--- productId: material-ui title: React Text Field component components: FilledInput, FormControl, FormHelperText, Input, InputAdornment, InputBase, InputLabel, OutlinedInput, TextField githubLabel: 'component: text field' materialDesign: https://m2.material.io/components/text-fields unstyled: /base-ui/react-input/ --- # Text Field <p class="description">Text Fields let users enter and edit text.</p> Text fields allow users to enter text into a UI. They typically appear in forms and dialogs. {{"component": "modules/components/ComponentLinkHeader.js"}} ## Basic TextField The `TextField` wrapper component is a complete form control including a label, input, and help text. It comes with three variants: outlined (default), filled, and standard. {{"demo": "BasicTextFields.js"}} :::info The standard variant of the Text Field is no longer documented in the [Material Design guidelines](https://m2.material.io/) ([this article explains why](https://medium.com/google-design/the-evolution-of-material-designs-text-fields-603688b3fe03)), but Material UI will continue to support it. ::: ## Form props Standard form attributes are supported e.g. `required`, `disabled`, `type`, etc. as well as a `helperText` which is used to give context about a field's input, such as how the input will be used. {{"demo": "FormPropsTextFields.js"}} ## Validation The `error` prop toggles the error state. The `helperText` prop can then be used to provide feedback to the user about the error. {{"demo": "ValidationTextFields.js"}} ## Multiline The `multiline` prop transforms the text field into a [TextareaAutosize](/material-ui/react-textarea-autosize/) element. Unless the `rows` prop is set, the height of the text field dynamically matches its content (using [TextareaAutosize](/material-ui/react-textarea-autosize/)). You can use the `minRows` and `maxRows` props to bound it. {{"demo": "MultilineTextFields.js"}} ## Select The `select` prop makes the text field use the [Select](/material-ui/react-select/) component internally. {{"demo": "SelectTextFields.js"}} ## Icons There are multiple ways to display an icon with a text field. {{"demo": "InputWithIcon.js"}} ### Input Adornments The main way is with an `InputAdornment`. This can be used to add a prefix, a suffix, or an action to an input. For instance, you can use an icon button to hide or reveal the password. {{"demo": "InputAdornments.js"}} ## Sizes Fancy smaller inputs? Use the `size` prop. {{"demo": "TextFieldSizes.js"}} The `filled` variant input height can be further reduced by rendering the label outside of it. {{"demo": "TextFieldHiddenLabel.js"}} ## Margin The `margin` prop can be used to alter the vertical spacing of the text field. Using `none` (default) doesn't apply margins to the `FormControl` whereas `dense` and `normal` do. {{"demo": "LayoutTextFields.js"}} ## Full width `fullWidth` can be used to make the input take up the full width of its container. {{"demo": "FullWidthTextField.js"}} ## Uncontrolled vs. Controlled The component can be controlled or uncontrolled. :::info - A component is **controlled** when it's managed by its parent using props. - A component is **uncontrolled** when it's managed by its own local state. Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). ::: {{"demo": "StateTextFields.js"}} ## Components `TextField` is composed of smaller components ( [`FormControl`](/material-ui/api/form-control/), [`Input`](/material-ui/api/input/), [`FilledInput`](/material-ui/api/filled-input/), [`InputLabel`](/material-ui/api/input-label/), [`OutlinedInput`](/material-ui/api/outlined-input/), and [`FormHelperText`](/material-ui/api/form-helper-text/) ) that you can leverage directly to significantly customize your form inputs. You might also have noticed that some native HTML input properties are missing from the `TextField` component. This is on purpose. The component takes care of the most used properties. Then, it's up to the user to use the underlying component shown in the following demo. Still, you can use `inputProps` (and `InputProps`, `InputLabelProps` properties) if you want to avoid some boilerplate. {{"demo": "ComposedTextField.js"}} ## Inputs {{"demo": "Inputs.js"}} ## Color The `color` prop changes the highlight color of the text field when focused. {{"demo": "ColorTextFields.js"}} ## Customization Here are some examples of customizing the component. You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/). ### Using the styled API {{"demo": "CustomizedInputsStyled.js"}} ### Using the theme style overrides API Use the `styleOverrides` key to change any style injected by Material UI into the DOM. See the [theme style overrides](/material-ui/customization/theme-components/#theme-style-overrides) documentation for further details. {{"demo": "CustomizedInputsStyleOverrides.js"}} Customization does not stop at CSS. You can use composition to build custom components and give your app a unique feel. Below is an example using the [`InputBase`](/material-ui/api/input-base/) component, inspired by Google Maps. {{"demo": "CustomizedInputBase.js", "bg": true}} 🎨 If you are looking for inspiration, you can check [MUI Treasury's customization examples](https://mui-treasury.com/styles/text-field/). ## `useFormControl` For advanced customization use cases, a `useFormControl()` hook is exposed. This hook returns the context value of the parent `FormControl` component. **API** ```jsx import { useFormControl } from '@mui/material/FormControl'; ``` **Returns** `value` (_object_): - `value.adornedStart` (_bool_): Indicate whether the child `Input` or `Select` component has a start adornment. - `value.setAdornedStart` (_func_): Setter function for `adornedStart` state value. - `value.color` (_string_): The theme color is being used, inherited from `FormControl` `color` prop . - `value.disabled` (_bool_): Indicate whether the component is being displayed in a disabled state, inherited from `FormControl` `disabled` prop. - `value.error` (_bool_): Indicate whether the component is being displayed in an error state, inherited from `FormControl` `error` prop - `value.filled` (_bool_): Indicate whether input is filled - `value.focused` (_bool_): Indicate whether the component and its children are being displayed in a focused state - `value.fullWidth` (_bool_): Indicate whether the component is taking up the full width of its container, inherited from `FormControl` `fullWidth` prop - `value.hiddenLabel` (_bool_): Indicate whether the label is being hidden, inherited from `FormControl` `hiddenLabel` prop - `value.required` (_bool_): Indicate whether the label is indicating that the input is required input, inherited from the `FormControl` `required` prop - `value.size` (_string_): The size of the component, inherited from the `FormControl` `size` prop - `value.variant` (_string_): The variant is being used by the `FormControl` component and its children, inherited from `FormControl` `variant` prop - `value.onBlur` (_func_): Should be called when the input is blurred - `value.onFocus` (_func_): Should be called when the input is focused - `value.onEmpty` (_func_): Should be called when the input is emptied - `value.onFilled` (_func_): Should be called when the input is filled **Example** {{"demo": "UseFormControl.js"}} ## Limitations ### Shrink The input label "shrink" state isn't always correct. The input label is supposed to shrink as soon as the input is displaying something. In some circumstances, we can't determine the "shrink" state (number input, datetime input, Stripe input). You might notice an overlap. ![shrink](/static/images/text-fields/shrink.png) To workaround the issue, you can force the "shrink" state of the label. ```jsx <TextField InputLabelProps={{ shrink: true }} /> ``` or ```jsx <InputLabel shrink>Count</InputLabel> ``` ### Floating label The floating label is absolutely positioned. It won't impact the layout of the page. Make sure that the input is larger than the label to display correctly. ### type="number" :::warning We do not recommend using `type="number"` with a Text Field due to potential usability issues: - it allows certain non-numeric characters ('e', '+', '-', '.') and silently discards others - the functionality of scrolling to increment/decrement the number can cause accidental and hard-to-notice changes - and more—see [Why the GOV.UK Design System team changed the input type for numbers](https://technology.blog.gov.uk/2020/02/24/why-the-gov-uk-design-system-team-changed-the-input-type-for-numbers/) for a more detailed explanation of the limitations of `<input type="number">` ::: If you need a text field with number validation, you can use Base UI's [Number Input](/base-ui/react-number-input/) instead. You can follow [this GitHub issue](https://github.com/mui/material-ui/issues/19154) to track the progress of introducing the Number Input component to Material UI. ### Helper text The helper text prop affects the height of the text field. If two text fields are placed side by side, one with a helper text and one without, they will have different heights. For example: {{"demo": "HelperTextMisaligned.js"}} This can be fixed by passing a space character to the `helperText` prop: {{"demo": "HelperTextAligned.js"}} ## Integration with 3rd party input libraries You can use third-party libraries to format an input. You have to provide a custom implementation of the `<input>` element with the `inputComponent` property. The following demo uses the [react-imask](https://github.com/uNmAnNeR/imaskjs) and [react-number-format](https://github.com/s-yadav/react-number-format) libraries. The same concept could be applied to [e.g. react-stripe-element](https://github.com/mui/material-ui/issues/16037). {{"demo": "FormattedInputs.js"}} The provided input component should expose a ref with a value that implements the following interface: ```ts interface InputElement { focus(): void; value?: string; } ``` ```jsx const MyInputComponent = React.forwardRef((props, ref) => { const { component: Component, ...other } = props; // implement `InputElement` interface React.useImperativeHandle(ref, () => ({ focus: () => { // logic to focus the rendered component from 3rd party belongs here }, // hiding the value e.g. react-stripe-elements })); // `Component` will be your `SomeThirdPartyComponent` from below return <Component {...other} />; }); // usage <TextField InputProps={{ inputComponent: MyInputComponent, inputProps: { component: SomeThirdPartyComponent, }, }} />; ``` ## Accessibility In order for the text field to be accessible, **the input should be linked to the label and the helper text**. The underlying DOM nodes should have this structure: ```jsx <div class="form-control"> <label for="my-input">Email address</label> <input id="my-input" aria-describedby="my-helper-text" /> <span id="my-helper-text">We'll never share your email.</span> </div> ``` - If you are using the `TextField` component, you just have to provide a unique `id` unless you're using the `TextField` only client side. Until the UI is hydrated `TextField` without an explicit `id` will not have associated labels. - If you are composing the component: ```jsx <FormControl> <InputLabel htmlFor="my-input">Email address</InputLabel> <Input id="my-input" aria-describedby="my-helper-text" /> <FormHelperText id="my-helper-text">We'll never share your email.</FormHelperText> </FormControl> ``` ## Complementary projects For more advanced use cases, you might be able to take advantage of: - [react-hook-form](https://react-hook-form.com/): React hook for form validation. - [react-hook-form-mui](https://github.com/dohomi/react-hook-form-mui): Material UI and react-hook-form combined. - [formik-material-ui](https://github.com/stackworx/formik-mui): Bindings for using Material UI with [formik](https://formik.org/). - [redux-form-material-ui](https://github.com/erikras/redux-form-material-ui): Bindings for using Material UI with [Redux Form](https://redux-form.com/). - [mui-rff](https://github.com/lookfirst/mui-rff): Bindings for using Material UI with [React Final Form](https://final-form.org/react). - [@ui-schema/ds-material](https://www.npmjs.com/package/@ui-schema/ds-material) Bindings for using Material UI with [UI Schema](https://github.com/ui-schema/ui-schema). JSON Schema compatible. - [@data-driven-forms/mui-component-mapper](https://www.data-driven-forms.org/provided-mappers/mui-component-mapper): Bindings for using Material UI with [Data Driven Forms](https://github.com/data-driven-forms/react-forms).
3,219
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/EmptyTextarea.js
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function EmptyTextarea() { return ( <TextareaAutosize aria-label="empty textarea" placeholder="Empty" style={{ width: 200 }} /> ); }
3,220
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/EmptyTextarea.tsx
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function EmptyTextarea() { return ( <TextareaAutosize aria-label="empty textarea" placeholder="Empty" style={{ width: 200 }} /> ); }
3,221
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/EmptyTextarea.tsx.preview
<TextareaAutosize aria-label="empty textarea" placeholder="Empty" style={{ width: 200 }} />
3,222
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MaxHeightTextarea.js
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function MaxHeightTextarea() { return ( <TextareaAutosize maxRows={4} aria-label="maximum height" placeholder="Maximum 4 rows" defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." style={{ width: 200 }} /> ); }
3,223
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MaxHeightTextarea.tsx
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function MaxHeightTextarea() { return ( <TextareaAutosize maxRows={4} aria-label="maximum height" placeholder="Maximum 4 rows" defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." style={{ width: 200 }} /> ); }
3,224
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MaxHeightTextarea.tsx.preview
<TextareaAutosize maxRows={4} aria-label="maximum height" placeholder="Maximum 4 rows" defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." style={{ width: 200 }} />
3,225
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MinHeightTextarea.js
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function MinHeightTextarea() { return ( <TextareaAutosize aria-label="minimum height" minRows={3} placeholder="Minimum 3 rows" style={{ width: 200 }} /> ); }
3,226
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MinHeightTextarea.tsx
import * as React from 'react'; import TextareaAutosize from '@mui/material/TextareaAutosize'; export default function MinHeightTextarea() { return ( <TextareaAutosize aria-label="minimum height" minRows={3} placeholder="Minimum 3 rows" style={{ width: 200 }} /> ); }
3,227
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/MinHeightTextarea.tsx.preview
<TextareaAutosize aria-label="minimum height" minRows={3} placeholder="Minimum 3 rows" style={{ width: 200 }} />
3,228
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/textarea-autosize/textarea-autosize.md
--- productId: material-ui title: Textarea Autosize React component components: TextareaAutosize githubLabel: 'component: TextareaAutosize' --- # Textarea Autosize <p class="description">The Textarea Autosize component gives you a textarea HTML element that automatically adjusts its height to match the length of the content within.</p> ## This document has moved :::warning Please refer to the [Textarea Autosize](/base-ui/react-textarea-autosize/) component page in the Base UI docs for demos and details on usage. Textarea Autosize is a part of the standalone [Base UI](/base-ui/) component library. It is currently re-exported from `@mui/material` for your convenience, but it will be removed from this package in a future major version, after `@mui/base` gets a stable release. :::
3,229
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/AlternateReverseTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function AlternateReverseTimeline() { return ( <Timeline position="alternate-reverse"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,230
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/AlternateReverseTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function AlternateReverseTimeline() { return ( <Timeline position="alternate-reverse"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,231
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/AlternateTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function AlternateTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,232
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/AlternateTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function AlternateTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,233
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/BasicTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function BasicTimeline() { return ( <Timeline> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> </Timeline> ); }
3,234
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/BasicTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function BasicTimeline() { return ( <Timeline> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> </Timeline> ); }
3,235
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/ColorsTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function ColorsTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot color="secondary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Secondary</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot color="success" /> </TimelineSeparator> <TimelineContent>Success</TimelineContent> </TimelineItem> </Timeline> ); }
3,236
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/ColorsTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function ColorsTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot color="secondary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Secondary</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot color="success" /> </TimelineSeparator> <TimelineContent>Success</TimelineContent> </TimelineItem> </Timeline> ); }
3,237
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/ColorsTimeline.tsx.preview
<Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot color="secondary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Secondary</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot color="success" /> </TimelineSeparator> <TimelineContent>Success</TimelineContent> </TimelineItem> </Timeline>
3,238
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/CustomizedTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; import TimelineDot from '@mui/lab/TimelineDot'; import FastfoodIcon from '@mui/icons-material/Fastfood'; import LaptopMacIcon from '@mui/icons-material/LaptopMac'; import HotelIcon from '@mui/icons-material/Hotel'; import RepeatIcon from '@mui/icons-material/Repeat'; import Typography from '@mui/material/Typography'; export default function CustomizedTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineOppositeContent sx={{ m: 'auto 0' }} align="right" variant="body2" color="text.secondary" > 9:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineConnector /> <TimelineDot> <FastfoodIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Eat </Typography> <Typography>Because you need strength</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent sx={{ m: 'auto 0' }} variant="body2" color="text.secondary" > 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineConnector /> <TimelineDot color="primary"> <LaptopMacIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Code </Typography> <Typography>Because it&apos;s awesome!</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineConnector /> <TimelineDot color="primary" variant="outlined"> <HotelIcon /> </TimelineDot> <TimelineConnector sx={{ bgcolor: 'secondary.main' }} /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Sleep </Typography> <Typography>Because you need rest</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineConnector sx={{ bgcolor: 'secondary.main' }} /> <TimelineDot color="secondary"> <RepeatIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Repeat </Typography> <Typography>Because this is the life you love!</Typography> </TimelineContent> </TimelineItem> </Timeline> ); }
3,239
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/CustomizedTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; import TimelineDot from '@mui/lab/TimelineDot'; import FastfoodIcon from '@mui/icons-material/Fastfood'; import LaptopMacIcon from '@mui/icons-material/LaptopMac'; import HotelIcon from '@mui/icons-material/Hotel'; import RepeatIcon from '@mui/icons-material/Repeat'; import Typography from '@mui/material/Typography'; export default function CustomizedTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineOppositeContent sx={{ m: 'auto 0' }} align="right" variant="body2" color="text.secondary" > 9:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineConnector /> <TimelineDot> <FastfoodIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Eat </Typography> <Typography>Because you need strength</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent sx={{ m: 'auto 0' }} variant="body2" color="text.secondary" > 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineConnector /> <TimelineDot color="primary"> <LaptopMacIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Code </Typography> <Typography>Because it&apos;s awesome!</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineConnector /> <TimelineDot color="primary" variant="outlined"> <HotelIcon /> </TimelineDot> <TimelineConnector sx={{ bgcolor: 'secondary.main' }} /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Sleep </Typography> <Typography>Because you need rest</Typography> </TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineConnector sx={{ bgcolor: 'secondary.main' }} /> <TimelineDot color="secondary"> <RepeatIcon /> </TimelineDot> <TimelineConnector /> </TimelineSeparator> <TimelineContent sx={{ py: '12px', px: 2 }}> <Typography variant="h6" component="span"> Repeat </Typography> <Typography>Because this is the life you love!</Typography> </TimelineContent> </TimelineItem> </Timeline> ); }
3,240
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/LeftAlignedTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent, { timelineOppositeContentClasses, } from '@mui/lab/TimelineOppositeContent'; export default function LeftAlignedTimeline() { return ( <Timeline sx={{ [`& .${timelineOppositeContentClasses.root}`]: { flex: 0.2, }, }} > <TimelineItem> <TimelineOppositeContent color="textSecondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="textSecondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,241
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/LeftAlignedTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent, { timelineOppositeContentClasses, } from '@mui/lab/TimelineOppositeContent'; export default function LeftAlignedTimeline() { return ( <Timeline sx={{ [`& .${timelineOppositeContentClasses.root}`]: { flex: 0.2, }, }} > <TimelineItem> <TimelineOppositeContent color="textSecondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="textSecondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,242
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/LeftPositionedTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function LeftPositionedTimeline() { return ( <Timeline position="left"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,243
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/LeftPositionedTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function LeftPositionedTimeline() { return ( <Timeline position="left"> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,244
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/NoOppositeContent.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem, { timelineItemClasses } from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function NoOppositeContent() { return ( <Timeline sx={{ [`& .${timelineItemClasses.root}:before`]: { flex: 0, padding: 0, }, }} > <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,245
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/NoOppositeContent.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem, { timelineItemClasses } from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function NoOppositeContent() { return ( <Timeline sx={{ [`& .${timelineItemClasses.root}:before`]: { flex: 0, padding: 0, }, }} > <TimelineItem> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,246
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/OppositeContentTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; export default function OppositeContentTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 12:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 9:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,247
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/OppositeContentTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; export default function OppositeContentTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 12:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="text.secondary"> 9:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,248
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/OutlinedTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function OutlinedTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" color="primary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" color="secondary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,249
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/OutlinedTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; export default function OutlinedTimeline() { return ( <Timeline position="alternate"> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" color="primary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" color="secondary" /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Sleep</TimelineContent> </TimelineItem> <TimelineItem> <TimelineSeparator> <TimelineDot variant="outlined" /> </TimelineSeparator> <TimelineContent>Repeat</TimelineContent> </TimelineItem> </Timeline> ); }
3,250
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/RightAlignedTimeline.js
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent, { timelineContentClasses } from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; export default function RightAlignedTimeline() { return ( <Timeline sx={{ [`& .${timelineContentClasses.root}`]: { flex: 0.2, }, }} > <TimelineItem> <TimelineOppositeContent color="textSecondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="textSecondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,251
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/RightAlignedTimeline.tsx
import * as React from 'react'; import Timeline from '@mui/lab/Timeline'; import TimelineItem from '@mui/lab/TimelineItem'; import TimelineSeparator from '@mui/lab/TimelineSeparator'; import TimelineConnector from '@mui/lab/TimelineConnector'; import TimelineContent, { timelineContentClasses } from '@mui/lab/TimelineContent'; import TimelineDot from '@mui/lab/TimelineDot'; import TimelineOppositeContent from '@mui/lab/TimelineOppositeContent'; export default function RightAlignedTimeline() { return ( <Timeline sx={{ [`& .${timelineContentClasses.root}`]: { flex: 0.2, }, }} > <TimelineItem> <TimelineOppositeContent color="textSecondary"> 09:30 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> <TimelineConnector /> </TimelineSeparator> <TimelineContent>Eat</TimelineContent> </TimelineItem> <TimelineItem> <TimelineOppositeContent color="textSecondary"> 10:00 am </TimelineOppositeContent> <TimelineSeparator> <TimelineDot /> </TimelineSeparator> <TimelineContent>Code</TimelineContent> </TimelineItem> </Timeline> ); }
3,252
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/timeline/timeline.md
--- productId: material-ui title: React Timeline component components: Timeline, TimelineItem, TimelineSeparator, TimelineDot, TimelineConnector, TimelineContent, TimelineOppositeContent githubLabel: 'component: timeline' packageName: '@mui/lab' --- # Timeline <p class="description">The timeline displays a list of events in chronological order.</p> :::info This component is not documented in the [Material Design guidelines](https://m2.material.io/), but it is available in Material UI. ::: {{"component": "modules/components/ComponentLinkHeader.js"}} ## Basic timeline A basic timeline showing list of events. {{"demo": "BasicTimeline.js"}} ## Left-positioned timeline The main content of the timeline can be positioned on the left side relative to the time axis. {{"demo": "LeftPositionedTimeline.js"}} ## Alternating timeline The timeline can display the events on alternating sides. {{"demo": "AlternateTimeline.js"}} ## Reverse Alternating timeline The timeline can display the events on alternating sides in reverse order. {{"demo": "AlternateReverseTimeline.js"}} ## Color The `TimelineDot` can appear in different colors from theme palette. {{"demo": "ColorsTimeline.js"}} ## Outlined {{"demo": "OutlinedTimeline.js"}} ## Opposite content The timeline can display content on opposite sides. {{"demo": "OppositeContentTimeline.js"}} ## Customization Here is an example of customizing the component. You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/). {{"demo": "CustomizedTimeline.js"}} ## Alignment There are different ways in which a Timeline can be placed within the container. You can do it by overriding the styles. A Timeline centers itself in the container by default. The demos below show how to adjust the relative width of the left and right sides of a Timeline: ### Left-aligned {{"demo": "LeftAlignedTimeline.js"}} ### Right-aligned {{"demo": "RightAlignedTimeline.js"}} ### Left-aligned with no opposite content {{"demo": "NoOppositeContent.js"}}
3,253
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ColorToggleButton.js
import * as React from 'react'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ColorToggleButton() { const [alignment, setAlignment] = React.useState('web'); const handleChange = (event, newAlignment) => { setAlignment(newAlignment); }; return ( <ToggleButtonGroup color="primary" value={alignment} exclusive onChange={handleChange} aria-label="Platform" > <ToggleButton value="web">Web</ToggleButton> <ToggleButton value="android">Android</ToggleButton> <ToggleButton value="ios">iOS</ToggleButton> </ToggleButtonGroup> ); }
3,254
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ColorToggleButton.tsx
import * as React from 'react'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ColorToggleButton() { const [alignment, setAlignment] = React.useState('web'); const handleChange = ( event: React.MouseEvent<HTMLElement>, newAlignment: string, ) => { setAlignment(newAlignment); }; return ( <ToggleButtonGroup color="primary" value={alignment} exclusive onChange={handleChange} aria-label="Platform" > <ToggleButton value="web">Web</ToggleButton> <ToggleButton value="android">Android</ToggleButton> <ToggleButton value="ios">iOS</ToggleButton> </ToggleButtonGroup> ); }
3,255
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ColorToggleButton.tsx.preview
<ToggleButtonGroup color="primary" value={alignment} exclusive onChange={handleChange} aria-label="Platform" > <ToggleButton value="web">Web</ToggleButton> <ToggleButton value="android">Android</ToggleButton> <ToggleButton value="ios">iOS</ToggleButton> </ToggleButtonGroup>
3,256
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/CustomizedDividers.js
import * as React from 'react'; import { styled } from '@mui/material/styles'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import FormatBoldIcon from '@mui/icons-material/FormatBold'; import FormatItalicIcon from '@mui/icons-material/FormatItalic'; import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; import FormatColorFillIcon from '@mui/icons-material/FormatColorFill'; import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import Divider from '@mui/material/Divider'; import Paper from '@mui/material/Paper'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; const StyledToggleButtonGroup = styled(ToggleButtonGroup)(({ theme }) => ({ '& .MuiToggleButtonGroup-grouped': { margin: theme.spacing(0.5), border: 0, '&.Mui-disabled': { border: 0, }, '&:not(:first-of-type)': { borderRadius: theme.shape.borderRadius, }, '&:first-of-type': { borderRadius: theme.shape.borderRadius, }, }, })); export default function CustomizedDividers() { const [alignment, setAlignment] = React.useState('left'); const [formats, setFormats] = React.useState(() => ['italic']); const handleFormat = (event, newFormats) => { setFormats(newFormats); }; const handleAlignment = (event, newAlignment) => { setAlignment(newAlignment); }; return ( <div> <Paper elevation={0} sx={{ display: 'flex', border: (theme) => `1px solid ${theme.palette.divider}`, flexWrap: 'wrap', }} > <StyledToggleButtonGroup size="small" value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> <ToggleButton value="justify" aria-label="justified" disabled> <FormatAlignJustifyIcon /> </ToggleButton> </StyledToggleButtonGroup> <Divider flexItem orientation="vertical" sx={{ mx: 0.5, my: 1 }} /> <StyledToggleButtonGroup size="small" value={formats} onChange={handleFormat} aria-label="text formatting" > <ToggleButton value="bold" aria-label="bold"> <FormatBoldIcon /> </ToggleButton> <ToggleButton value="italic" aria-label="italic"> <FormatItalicIcon /> </ToggleButton> <ToggleButton value="underlined" aria-label="underlined"> <FormatUnderlinedIcon /> </ToggleButton> <ToggleButton value="color" aria-label="color" disabled> <FormatColorFillIcon /> <ArrowDropDownIcon /> </ToggleButton> </StyledToggleButtonGroup> </Paper> </div> ); }
3,257
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/CustomizedDividers.tsx
import * as React from 'react'; import { styled } from '@mui/material/styles'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import FormatBoldIcon from '@mui/icons-material/FormatBold'; import FormatItalicIcon from '@mui/icons-material/FormatItalic'; import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; import FormatColorFillIcon from '@mui/icons-material/FormatColorFill'; import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import Divider from '@mui/material/Divider'; import Paper from '@mui/material/Paper'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; const StyledToggleButtonGroup = styled(ToggleButtonGroup)(({ theme }) => ({ '& .MuiToggleButtonGroup-grouped': { margin: theme.spacing(0.5), border: 0, '&.Mui-disabled': { border: 0, }, '&:not(:first-of-type)': { borderRadius: theme.shape.borderRadius, }, '&:first-of-type': { borderRadius: theme.shape.borderRadius, }, }, })); export default function CustomizedDividers() { const [alignment, setAlignment] = React.useState('left'); const [formats, setFormats] = React.useState(() => ['italic']); const handleFormat = ( event: React.MouseEvent<HTMLElement>, newFormats: string[], ) => { setFormats(newFormats); }; const handleAlignment = ( event: React.MouseEvent<HTMLElement>, newAlignment: string, ) => { setAlignment(newAlignment); }; return ( <div> <Paper elevation={0} sx={{ display: 'flex', border: (theme) => `1px solid ${theme.palette.divider}`, flexWrap: 'wrap', }} > <StyledToggleButtonGroup size="small" value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> <ToggleButton value="justify" aria-label="justified" disabled> <FormatAlignJustifyIcon /> </ToggleButton> </StyledToggleButtonGroup> <Divider flexItem orientation="vertical" sx={{ mx: 0.5, my: 1 }} /> <StyledToggleButtonGroup size="small" value={formats} onChange={handleFormat} aria-label="text formatting" > <ToggleButton value="bold" aria-label="bold"> <FormatBoldIcon /> </ToggleButton> <ToggleButton value="italic" aria-label="italic"> <FormatItalicIcon /> </ToggleButton> <ToggleButton value="underlined" aria-label="underlined"> <FormatUnderlinedIcon /> </ToggleButton> <ToggleButton value="color" aria-label="color" disabled> <FormatColorFillIcon /> <ArrowDropDownIcon /> </ToggleButton> </StyledToggleButtonGroup> </Paper> </div> ); }
3,258
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/StandaloneToggleButton.js
import * as React from 'react'; import CheckIcon from '@mui/icons-material/Check'; import ToggleButton from '@mui/material/ToggleButton'; export default function StandaloneToggleButton() { const [selected, setSelected] = React.useState(false); return ( <ToggleButton value="check" selected={selected} onChange={() => { setSelected(!selected); }} > <CheckIcon /> </ToggleButton> ); }
3,259
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/StandaloneToggleButton.tsx
import * as React from 'react'; import CheckIcon from '@mui/icons-material/Check'; import ToggleButton from '@mui/material/ToggleButton'; export default function StandaloneToggleButton() { const [selected, setSelected] = React.useState(false); return ( <ToggleButton value="check" selected={selected} onChange={() => { setSelected(!selected); }} > <CheckIcon /> </ToggleButton> ); }
3,260
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/StandaloneToggleButton.tsx.preview
<ToggleButton value="check" selected={selected} onChange={() => { setSelected(!selected); }} > <CheckIcon /> </ToggleButton>
3,261
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonNotEmpty.js
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import LaptopIcon from '@mui/icons-material/Laptop'; import TvIcon from '@mui/icons-material/Tv'; import PhoneAndroidIcon from '@mui/icons-material/PhoneAndroid'; import Stack from '@mui/material/Stack'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonNotEmpty() { const [alignment, setAlignment] = React.useState('left'); const [devices, setDevices] = React.useState(() => ['phone']); const handleAlignment = (event, newAlignment) => { if (newAlignment !== null) { setAlignment(newAlignment); } }; const handleDevices = (event, newDevices) => { if (newDevices.length) { setDevices(newDevices); } }; return ( <Stack direction="row" spacing={4}> <ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> </ToggleButtonGroup> <ToggleButtonGroup value={devices} onChange={handleDevices} aria-label="device" > <ToggleButton value="laptop" aria-label="laptop"> <LaptopIcon /> </ToggleButton> <ToggleButton value="tv" aria-label="tv"> <TvIcon /> </ToggleButton> <ToggleButton value="phone" aria-label="phone"> <PhoneAndroidIcon /> </ToggleButton> </ToggleButtonGroup> </Stack> ); }
3,262
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonNotEmpty.tsx
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import LaptopIcon from '@mui/icons-material/Laptop'; import TvIcon from '@mui/icons-material/Tv'; import PhoneAndroidIcon from '@mui/icons-material/PhoneAndroid'; import Stack from '@mui/material/Stack'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonNotEmpty() { const [alignment, setAlignment] = React.useState('left'); const [devices, setDevices] = React.useState(() => ['phone']); const handleAlignment = ( event: React.MouseEvent<HTMLElement>, newAlignment: string | null, ) => { if (newAlignment !== null) { setAlignment(newAlignment); } }; const handleDevices = ( event: React.MouseEvent<HTMLElement>, newDevices: string[], ) => { if (newDevices.length) { setDevices(newDevices); } }; return ( <Stack direction="row" spacing={4}> <ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> </ToggleButtonGroup> <ToggleButtonGroup value={devices} onChange={handleDevices} aria-label="device" > <ToggleButton value="laptop" aria-label="laptop"> <LaptopIcon /> </ToggleButton> <ToggleButton value="tv" aria-label="tv"> <TvIcon /> </ToggleButton> <ToggleButton value="phone" aria-label="phone"> <PhoneAndroidIcon /> </ToggleButton> </ToggleButtonGroup> </Stack> ); }
3,263
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonSizes.js
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import Stack from '@mui/material/Stack'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonSizes() { const [alignment, setAlignment] = React.useState('left'); const handleChange = (event, newAlignment) => { setAlignment(newAlignment); }; const children = [ <ToggleButton value="left" key="left"> <FormatAlignLeftIcon /> </ToggleButton>, <ToggleButton value="center" key="center"> <FormatAlignCenterIcon /> </ToggleButton>, <ToggleButton value="right" key="right"> <FormatAlignRightIcon /> </ToggleButton>, <ToggleButton value="justify" key="justify"> <FormatAlignJustifyIcon /> </ToggleButton>, ]; const control = { value: alignment, onChange: handleChange, exclusive: true, }; return ( <Stack spacing={2} alignItems="center"> <ToggleButtonGroup size="small" {...control} aria-label="Small sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup {...control} aria-label="Medium sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup size="large" {...control} aria-label="Large sizes"> {children} </ToggleButtonGroup> </Stack> ); }
3,264
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonSizes.tsx
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import Stack from '@mui/material/Stack'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonSizes() { const [alignment, setAlignment] = React.useState('left'); const handleChange = ( event: React.MouseEvent<HTMLElement>, newAlignment: string, ) => { setAlignment(newAlignment); }; const children = [ <ToggleButton value="left" key="left"> <FormatAlignLeftIcon /> </ToggleButton>, <ToggleButton value="center" key="center"> <FormatAlignCenterIcon /> </ToggleButton>, <ToggleButton value="right" key="right"> <FormatAlignRightIcon /> </ToggleButton>, <ToggleButton value="justify" key="justify"> <FormatAlignJustifyIcon /> </ToggleButton>, ]; const control = { value: alignment, onChange: handleChange, exclusive: true, }; return ( <Stack spacing={2} alignItems="center"> <ToggleButtonGroup size="small" {...control} aria-label="Small sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup {...control} aria-label="Medium sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup size="large" {...control} aria-label="Large sizes"> {children} </ToggleButtonGroup> </Stack> ); }
3,265
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonSizes.tsx.preview
<ToggleButtonGroup size="small" {...control} aria-label="Small sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup {...control} aria-label="Medium sizes"> {children} </ToggleButtonGroup> <ToggleButtonGroup size="large" {...control} aria-label="Large sizes"> {children} </ToggleButtonGroup>
3,266
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtons.js
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtons() { const [alignment, setAlignment] = React.useState('left'); const handleAlignment = (event, newAlignment) => { setAlignment(newAlignment); }; return ( <ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> <ToggleButton value="justify" aria-label="justified" disabled> <FormatAlignJustifyIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,267
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtons.tsx
import * as React from 'react'; import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft'; import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter'; import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight'; import FormatAlignJustifyIcon from '@mui/icons-material/FormatAlignJustify'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtons() { const [alignment, setAlignment] = React.useState<string | null>('left'); const handleAlignment = ( event: React.MouseEvent<HTMLElement>, newAlignment: string | null, ) => { setAlignment(newAlignment); }; return ( <ToggleButtonGroup value={alignment} exclusive onChange={handleAlignment} aria-label="text alignment" > <ToggleButton value="left" aria-label="left aligned"> <FormatAlignLeftIcon /> </ToggleButton> <ToggleButton value="center" aria-label="centered"> <FormatAlignCenterIcon /> </ToggleButton> <ToggleButton value="right" aria-label="right aligned"> <FormatAlignRightIcon /> </ToggleButton> <ToggleButton value="justify" aria-label="justified" disabled> <FormatAlignJustifyIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,268
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonsMultiple.js
import * as React from 'react'; import FormatBoldIcon from '@mui/icons-material/FormatBold'; import FormatItalicIcon from '@mui/icons-material/FormatItalic'; import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; import FormatColorFillIcon from '@mui/icons-material/FormatColorFill'; import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonsMultiple() { const [formats, setFormats] = React.useState(() => ['bold', 'italic']); const handleFormat = (event, newFormats) => { setFormats(newFormats); }; return ( <ToggleButtonGroup value={formats} onChange={handleFormat} aria-label="text formatting" > <ToggleButton value="bold" aria-label="bold"> <FormatBoldIcon /> </ToggleButton> <ToggleButton value="italic" aria-label="italic"> <FormatItalicIcon /> </ToggleButton> <ToggleButton value="underlined" aria-label="underlined"> <FormatUnderlinedIcon /> </ToggleButton> <ToggleButton value="color" aria-label="color" disabled> <FormatColorFillIcon /> <ArrowDropDownIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,269
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/ToggleButtonsMultiple.tsx
import * as React from 'react'; import FormatBoldIcon from '@mui/icons-material/FormatBold'; import FormatItalicIcon from '@mui/icons-material/FormatItalic'; import FormatUnderlinedIcon from '@mui/icons-material/FormatUnderlined'; import FormatColorFillIcon from '@mui/icons-material/FormatColorFill'; import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function ToggleButtonsMultiple() { const [formats, setFormats] = React.useState(() => ['bold', 'italic']); const handleFormat = ( event: React.MouseEvent<HTMLElement>, newFormats: string[], ) => { setFormats(newFormats); }; return ( <ToggleButtonGroup value={formats} onChange={handleFormat} aria-label="text formatting" > <ToggleButton value="bold" aria-label="bold"> <FormatBoldIcon /> </ToggleButton> <ToggleButton value="italic" aria-label="italic"> <FormatItalicIcon /> </ToggleButton> <ToggleButton value="underlined" aria-label="underlined"> <FormatUnderlinedIcon /> </ToggleButton> <ToggleButton value="color" aria-label="color" disabled> <FormatColorFillIcon /> <ArrowDropDownIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,270
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/VerticalToggleButtons.js
import * as React from 'react'; import ViewListIcon from '@mui/icons-material/ViewList'; import ViewModuleIcon from '@mui/icons-material/ViewModule'; import ViewQuiltIcon from '@mui/icons-material/ViewQuilt'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function VerticalToggleButtons() { const [view, setView] = React.useState('list'); const handleChange = (event, nextView) => { setView(nextView); }; return ( <ToggleButtonGroup orientation="vertical" value={view} exclusive onChange={handleChange} > <ToggleButton value="list" aria-label="list"> <ViewListIcon /> </ToggleButton> <ToggleButton value="module" aria-label="module"> <ViewModuleIcon /> </ToggleButton> <ToggleButton value="quilt" aria-label="quilt"> <ViewQuiltIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,271
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/VerticalToggleButtons.tsx
import * as React from 'react'; import ViewListIcon from '@mui/icons-material/ViewList'; import ViewModuleIcon from '@mui/icons-material/ViewModule'; import ViewQuiltIcon from '@mui/icons-material/ViewQuilt'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; export default function VerticalToggleButtons() { const [view, setView] = React.useState('list'); const handleChange = (event: React.MouseEvent<HTMLElement>, nextView: string) => { setView(nextView); }; return ( <ToggleButtonGroup orientation="vertical" value={view} exclusive onChange={handleChange} > <ToggleButton value="list" aria-label="list"> <ViewListIcon /> </ToggleButton> <ToggleButton value="module" aria-label="module"> <ViewModuleIcon /> </ToggleButton> <ToggleButton value="quilt" aria-label="quilt"> <ViewQuiltIcon /> </ToggleButton> </ToggleButtonGroup> ); }
3,272
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/VerticalToggleButtons.tsx.preview
<ToggleButtonGroup orientation="vertical" value={view} exclusive onChange={handleChange} > <ToggleButton value="list" aria-label="list"> <ViewListIcon /> </ToggleButton> <ToggleButton value="module" aria-label="module"> <ViewModuleIcon /> </ToggleButton> <ToggleButton value="quilt" aria-label="quilt"> <ViewQuiltIcon /> </ToggleButton> </ToggleButtonGroup>
3,273
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/toggle-button/toggle-button.md
--- productId: material-ui title: Toggle Button React component components: ToggleButton, ToggleButtonGroup githubLabel: 'component: toggle button' materialDesign: https://m2.material.io/components/buttons#toggle-button --- # Toggle Button <p class="description">A Toggle Button can be used to group related options.</p> To emphasize groups of related Toggle buttons, a group should share a common container. The `ToggleButtonGroup` controls the selected state of its child buttons when given its own `value` prop. {{"component": "modules/components/ComponentLinkHeader.js"}} ## Exclusive selection With exclusive selection, selecting one option deselects any other. In this example, text justification toggle buttons present options for left, center, right, and fully justified text (disabled), with only one item available for selection at a time. **Note**: Exclusive selection does not enforce that a button must be active. For that effect see [enforce value set](#enforce-value-set). {{"demo": "ToggleButtons.js"}} ## Multiple selection Multiple selection allows for logically-grouped options, like bold, italic, and underline, to have multiple options selected. {{"demo": "ToggleButtonsMultiple.js"}} ## Size For larger or smaller buttons, use the `size` prop. {{"demo": "ToggleButtonSizes.js"}} ## Color {{"demo": "ColorToggleButton.js"}} ## Vertical buttons The buttons can be stacked vertically with the `orientation` prop set to "vertical". {{"demo": "VerticalToggleButtons.js"}} ## Enforce value set If you want to enforce that at least one button must be active, you can adapt your handleChange function. ```jsx const handleAlignment = (event, newAlignment) => { if (newAlignment !== null) { setAlignment(newAlignment); } }; const handleDevices = (event, newDevices) => { if (newDevices.length) { setDevices(newDevices); } }; ``` {{"demo": "ToggleButtonNotEmpty.js"}} ## Standalone toggle button {{"demo": "StandaloneToggleButton.js"}} ## Customization Here is an example of customizing the component. You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/). {{"demo": "CustomizedDividers.js", "bg": true}} ## Accessibility ### ARIA - ToggleButtonGroup has `role="group"`. You should provide an accessible label with `aria-label="label"`, `aria-labelledby="id"` or `<label>`. - ToggleButton sets `aria-pressed="<bool>"` according to the button state. You should label each button with `aria-label`. ### Keyboard At present, toggle buttons are in DOM order. Navigate between them with the tab key. The button behavior follows standard keyboard semantics.
3,274
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/AccessibilityTooltips.js
import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import Button from '@mui/material/Button'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; export default function AccessibilityTooltips() { return ( <div> <Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip> <Tooltip describeChild title="Does not add if it already exists."> <Button>Add</Button> </Tooltip> </div> ); }
3,275
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/AccessibilityTooltips.tsx
import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import Button from '@mui/material/Button'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; export default function AccessibilityTooltips() { return ( <div> <Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip> <Tooltip describeChild title="Does not add if it already exists."> <Button>Add</Button> </Tooltip> </div> ); }
3,276
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/AccessibilityTooltips.tsx.preview
<Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip> <Tooltip describeChild title="Does not add if it already exists."> <Button>Add</Button> </Tooltip>
3,277
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/AnchorElTooltips.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Tooltip from '@mui/material/Tooltip'; export default function AnchorElTooltips() { const positionRef = React.useRef({ x: 0, y: 0, }); const popperRef = React.useRef(null); const areaRef = React.useRef(null); const handleMouseMove = (event) => { positionRef.current = { x: event.clientX, y: event.clientY }; if (popperRef.current != null) { popperRef.current.update(); } }; return ( <Tooltip title="Add" placement="top" arrow PopperProps={{ popperRef, anchorEl: { getBoundingClientRect: () => { return new DOMRect( positionRef.current.x, areaRef.current.getBoundingClientRect().y, 0, 0, ); }, }, }} > <Box ref={areaRef} onMouseMove={handleMouseMove} sx={{ bgcolor: 'primary.main', color: 'primary.contrastText', p: 2, }} > Hover </Box> </Tooltip> ); }
3,278
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/AnchorElTooltips.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Tooltip from '@mui/material/Tooltip'; import { Instance } from '@popperjs/core'; export default function AnchorElTooltips() { const positionRef = React.useRef<{ x: number; y: number }>({ x: 0, y: 0, }); const popperRef = React.useRef<Instance>(null); const areaRef = React.useRef<HTMLDivElement>(null); const handleMouseMove = (event: React.MouseEvent) => { positionRef.current = { x: event.clientX, y: event.clientY }; if (popperRef.current != null) { popperRef.current.update(); } }; return ( <Tooltip title="Add" placement="top" arrow PopperProps={{ popperRef, anchorEl: { getBoundingClientRect: () => { return new DOMRect( positionRef.current.x, areaRef.current!.getBoundingClientRect().y, 0, 0, ); }, }, }} > <Box ref={areaRef} onMouseMove={handleMouseMove} sx={{ bgcolor: 'primary.main', color: 'primary.contrastText', p: 2, }} > Hover </Box> </Tooltip> ); }
3,279
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ArrowTooltips.js
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function ArrowTooltips() { return ( <Tooltip title="Add" arrow> <Button>Arrow</Button> </Tooltip> ); }
3,280
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ArrowTooltips.tsx
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function ArrowTooltips() { return ( <Tooltip title="Add" arrow> <Button>Arrow</Button> </Tooltip> ); }
3,281
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ArrowTooltips.tsx.preview
<Tooltip title="Add" arrow> <Button>Arrow</Button> </Tooltip>
3,282
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/BasicTooltip.js
import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; export default function BasicTooltip() { return ( <Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip> ); }
3,283
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/BasicTooltip.tsx
import * as React from 'react'; import DeleteIcon from '@mui/icons-material/Delete'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; export default function BasicTooltip() { return ( <Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip> ); }
3,284
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/BasicTooltip.tsx.preview
<Tooltip title="Delete"> <IconButton> <DeleteIcon /> </IconButton> </Tooltip>
3,285
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ControlledTooltips.js
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function ControlledTooltips() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const handleOpen = () => { setOpen(true); }; return ( <Tooltip open={open} onClose={handleClose} onOpen={handleOpen} title="Add"> <Button>Controlled</Button> </Tooltip> ); }
3,286
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ControlledTooltips.tsx
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function ControlledTooltips() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const handleOpen = () => { setOpen(true); }; return ( <Tooltip open={open} onClose={handleClose} onOpen={handleOpen} title="Add"> <Button>Controlled</Button> </Tooltip> ); }
3,287
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/ControlledTooltips.tsx.preview
<Tooltip open={open} onClose={handleClose} onOpen={handleOpen} title="Add"> <Button>Controlled</Button> </Tooltip>
3,288
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/CustomizedTooltips.js
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Button from '@mui/material/Button'; import Tooltip, { tooltipClasses } from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; const LightTooltip = styled(({ className, ...props }) => ( <Tooltip {...props} classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.tooltip}`]: { backgroundColor: theme.palette.common.white, color: 'rgba(0, 0, 0, 0.87)', boxShadow: theme.shadows[1], fontSize: 11, }, })); const BootstrapTooltip = styled(({ className, ...props }) => ( <Tooltip {...props} arrow classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.arrow}`]: { color: theme.palette.common.black, }, [`& .${tooltipClasses.tooltip}`]: { backgroundColor: theme.palette.common.black, }, })); const HtmlTooltip = styled(({ className, ...props }) => ( <Tooltip {...props} classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.tooltip}`]: { backgroundColor: '#f5f5f9', color: 'rgba(0, 0, 0, 0.87)', maxWidth: 220, fontSize: theme.typography.pxToRem(12), border: '1px solid #dadde9', }, })); export default function CustomizedTooltips() { return ( <div> <LightTooltip title="Add"> <Button>Light</Button> </LightTooltip> <BootstrapTooltip title="Add"> <Button>Bootstrap</Button> </BootstrapTooltip> <HtmlTooltip title={ <React.Fragment> <Typography color="inherit">Tooltip with HTML</Typography> <em>{"And here's"}</em> <b>{'some'}</b> <u>{'amazing content'}</u>.{' '} {"It's very engaging. Right?"} </React.Fragment> } > <Button>HTML</Button> </HtmlTooltip> </div> ); }
3,289
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/CustomizedTooltips.tsx
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Button from '@mui/material/Button'; import Tooltip, { TooltipProps, tooltipClasses } from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; const LightTooltip = styled(({ className, ...props }: TooltipProps) => ( <Tooltip {...props} classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.tooltip}`]: { backgroundColor: theme.palette.common.white, color: 'rgba(0, 0, 0, 0.87)', boxShadow: theme.shadows[1], fontSize: 11, }, })); const BootstrapTooltip = styled(({ className, ...props }: TooltipProps) => ( <Tooltip {...props} arrow classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.arrow}`]: { color: theme.palette.common.black, }, [`& .${tooltipClasses.tooltip}`]: { backgroundColor: theme.palette.common.black, }, })); const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => ( <Tooltip {...props} classes={{ popper: className }} /> ))(({ theme }) => ({ [`& .${tooltipClasses.tooltip}`]: { backgroundColor: '#f5f5f9', color: 'rgba(0, 0, 0, 0.87)', maxWidth: 220, fontSize: theme.typography.pxToRem(12), border: '1px solid #dadde9', }, })); export default function CustomizedTooltips() { return ( <div> <LightTooltip title="Add"> <Button>Light</Button> </LightTooltip> <BootstrapTooltip title="Add"> <Button>Bootstrap</Button> </BootstrapTooltip> <HtmlTooltip title={ <React.Fragment> <Typography color="inherit">Tooltip with HTML</Typography> <em>{"And here's"}</em> <b>{'some'}</b> <u>{'amazing content'}</u>.{' '} {"It's very engaging. Right?"} </React.Fragment> } > <Button>HTML</Button> </HtmlTooltip> </div> ); }
3,290
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DelayTooltips.js
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function DelayTooltips() { return ( <Tooltip title="Add" enterDelay={500} leaveDelay={200}> <Button>[500ms, 200ms]</Button> </Tooltip> ); }
3,291
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DelayTooltips.tsx
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function DelayTooltips() { return ( <Tooltip title="Add" enterDelay={500} leaveDelay={200}> <Button>[500ms, 200ms]</Button> </Tooltip> ); }
3,292
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DelayTooltips.tsx.preview
<Tooltip title="Add" enterDelay={500} leaveDelay={200}> <Button>[500ms, 200ms]</Button> </Tooltip>
3,293
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DisabledTooltips.js
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function DisabledTooltips() { return ( <Tooltip title="You don't have permission to do this"> <span> <Button disabled>A Disabled Button</Button> </span> </Tooltip> ); }
3,294
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DisabledTooltips.tsx
import * as React from 'react'; import Button from '@mui/material/Button'; import Tooltip from '@mui/material/Tooltip'; export default function DisabledTooltips() { return ( <Tooltip title="You don't have permission to do this"> <span> <Button disabled>A Disabled Button</Button> </span> </Tooltip> ); }
3,295
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/DisabledTooltips.tsx.preview
<Tooltip title="You don't have permission to do this"> <span> <Button disabled>A Disabled Button</Button> </span> </Tooltip>
3,296
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/FollowCursorTooltips.js
import * as React from 'react'; import Box from '@mui/material/Box'; import Tooltip from '@mui/material/Tooltip'; export default function FollowCursorTooltips() { return ( <Tooltip title="You don't have permission to do this" followCursor> <Box sx={{ bgcolor: 'text.disabled', color: 'background.paper', p: 2 }}> Disabled Action </Box> </Tooltip> ); }
3,297
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/FollowCursorTooltips.tsx
import * as React from 'react'; import Box from '@mui/material/Box'; import Tooltip from '@mui/material/Tooltip'; export default function FollowCursorTooltips() { return ( <Tooltip title="You don't have permission to do this" followCursor> <Box sx={{ bgcolor: 'text.disabled', color: 'background.paper', p: 2 }}> Disabled Action </Box> </Tooltip> ); }
3,298
0
petrpan-code/mui/material-ui/docs/data/material/components
petrpan-code/mui/material-ui/docs/data/material/components/tooltips/FollowCursorTooltips.tsx.preview
<Tooltip title="You don't have permission to do this" followCursor> <Box sx={{ bgcolor: 'text.disabled', color: 'background.paper', p: 2 }}> Disabled Action </Box> </Tooltip>
3,299