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

[Doc] Fix Inputs doc is too concise #7856

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 283 additions & 34 deletions docs/Inputs.md

Large diffs are not rendered by default.

37 changes: 26 additions & 11 deletions docs/TextInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ title: "The TextInput Component"

# `<TextInput>`

`<TextInput>` is the most common input. It is used for texts, emails, URL or passwords. In translates to an HTML `<input>` tag.
`<TextInput>` is the most common input. It is used for texts, emails, URL or passwords. In translates into [an MUI `<TextField>`](https://mui.com/material-ui/react-text-field/), and renders as `<input type="text">` in HTML.

![TextInput](./img/text-input.gif)

```jsx
import { TextInput } from 'react-admin';
## Usage

<TextInput source="title" />
```jsx
import { Edit, SimpleForm, TextInput, required } from 'react-admin';

export const PostEdit = () => (
<Edit title={<PostTitle />}>
<SimpleForm>
<TextInput source="title" validate={[required()]} fullWidth />
<TextInput source="teaser" validate={[required()]} defaultValue="Lorem Ipsum" multiline fullWidth />
</SimpleForm>
</Edit>
);
```

## Properties
## Props

| Prop | Required | Type | Default | Description |
| ------------ | -------- | --------- | ------- | -------------------------------------------------------------------- |
Expand All @@ -25,20 +34,18 @@ import { TextInput } from 'react-admin';

`<TextInput>` also accepts the [common input props](./Inputs.md#common-input-props).

## Usage
Additional props are passed down to the underlying MUI [`<TextField>`](https://mui.com/material-ui/react-text-field/) component.

You can choose a specific input type using the `type` attribute, for instance `text` (the default), `email`, `url`, or `password`:

```jsx
<TextInput label="Email Address" source="email" type="email" />
```
## `multiline`

You can make the `<TextInput>` expandable using the `multiline` prop for multiline text values. It renders as an auto expandable textarea.

```jsx
<TextInput multiline source="body" />
```

## `resettable`

You can make the `<TextInput>` component resettable using the `resettable` prop. This will add a reset button which will be displayed only when the field has a value and is focused.

```jsx
Expand All @@ -49,4 +56,12 @@ import { TextInput } from 'react-admin';

![resettable TextInput](./img/resettable-text-input.gif)

## `type`

You can choose a specific input type using the `type` attribute, for instance `text` (the default), `email`, `url`, or `password`:

```jsx
<TextInput label="Email Address" source="email" type="email" />
```

**Warning**: Do not use `type="number"`, or you'll receive a string as value (this is a [known React bug](https://github.com/facebook/react/issues/1425)). Instead, use [`<NumberInput>`](./NumberInput.md).
Binary file added docs/img/input-full-width.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/input-helper-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/inputs.webp
Binary file not shown.
3 changes: 3 additions & 0 deletions packages/ra-ui-materialui/src/field/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface PublicFieldProps {
className?: string;
cellClassName?: string;
headerClassName?: string;
/*
* @deprecated this property is not used anymore
*/
formClassName?: string;
textAlign?: TextAlign;
emptyText?: string;
Expand Down
3 changes: 3 additions & 0 deletions packages/ra-ui-materialui/src/input/CommonInputProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { InputProps } from 'ra-core';

export type CommonInputProps = InputProps & {
cellClassName?: string;
/*
* @deprecated this property is not used anymore
*/
formClassName?: string;
fullWidth?: boolean;
headerCellClassName?: string;
Expand Down