Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[epic] TextField #5

Open
soroushm opened this issue Dec 23, 2022 · 0 comments
Open

[epic] TextField #5

soroushm opened this issue Dec 23, 2022 · 0 comments
Labels
component: input This is the name of the generic UI component epic This is the beginning

Comments

@soroushm
Copy link
Member

soroushm commented Dec 23, 2022

Issue description

Text fields allow users to enter text into a UI. They typically appear in forms and dialogs.

Import

import TextField from '@mnui/material/TextField;
// or
import { TextField } from '@mnui/material';

TextField is a convenience wrapper for the most common cases (80%). It cannot be all things to all people, otherwise, the API would grow out of control.

Components

TextField is composed of smaller components ( FormControl, Input, FilledInput, OutlinedInput, and FormHelperText ) 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.

If you wish to alter the props applied to the input element, you can do so as follows:

const inputProps = {
  step: 300,
};

return <TextField id="time" type="time" inputProps={inputProps} />;

For advanced cases, please look at the source of TextField by clicking on the "Edit this page" button above. Consider either:

using the upper case props for passing values directly to the components
using the underlying components directly as shown in the demos

Props

Props of the native componenta and FormControl are also available.

Name Type Default Description
autoComplete string This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about it following the specification.
autoFocus bool false If true, the input element is focused during the first mount.
color 'primary',
'secondary',
'error',
'info',
'success',
'warning',
string
'primary' The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization.
defaultValue any The default value. Use when the component is not controlled.
disabled bool false If true, the component is disabled.
error bool false If true, the label is displayed in an error state.
FormHelperTextProps object Props applied to the FormHelperText element.
fullWidth bool false If true, the input will take up the full width of its container.
helperText node The helper text content.
id string The id of the input element. Use this prop to make label and helperText accessible for screen readers.
InputLabelProps object Props applied to the InputLabel element. Pointer events like onPress are enabled if and only if shrink is true.
InputProps object Props applied to the Input element. It will be a FilledInput, OutlinedInput or Input component depending on the variant prop value.
inputRef ref Pass a ref to the input element.
label node The label content.
margin 'dense',
'none',
'normal'
'none' If dense or normal, will adjust vertical spacing of this and contained components.
maxRows number,
string
Maximum number of rows to display when multiline option is set to true.
minRows number,
string
Minimum number of rows to display when multiline option is set to true.
multiline bool false If true, a textarea element is rendered instead of an input.
onChange func Callback fired when the value is changed.

Signature:
function({ nativeEvent: { eventCount, target, text} }) => void
event: The event source of the callback. You can pull out the new value by accessing event.target.value (string).
placeholder string The short hint displayed in the input before the user enters a value.
required bool false If true, the label is displayed as required and the input element is required.
rows number, Number of rows to display when multiline option is set to true. only applied to text type. limitation
size 'medium',
'small',
string
The size of the component.
sx Array<func,
object,
bool>,
func,
object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` epic for more details.
type 'number',
'text',
'password'
Type of the textInput element..
value any The value of the input element, required for a controlled component.
variant 'filled',
'outlined',
'standard'
'outlined' The variant to use.

The ref is forwarded to the root element.

@soroushm soroushm added component: input This is the name of the generic UI component epic This is the beginning labels Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: input This is the name of the generic UI component epic This is the beginning
Projects
None yet
Development

No branches or pull requests

1 participant