Skip to content

Commit

Permalink
[docs] Add HTML input section to TextField page (#45439)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Mar 10, 2025
1 parent 2d8d082 commit 93f3d9c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/data/material/components/text-fields/text-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,31 @@ Standard form attributes are supported, for example `required`, `disabled`, `typ

{{"demo": "FormPropsTextFields.js"}}

## Controlling the HTML input

Use `slotProps.htmlInput` to pass attributes to the underlying `<input>` element.

```jsx
<TextField slotProps={{ htmlInput: { 'data-testid': '' } }} />
```

The rendered HTML input will look like this:

```html
<input
aria-invalid="false"
class="MuiInputBase-input MuiOutlinedInput-input"
type="text"
data-testid=""
/>
```

:::warning
`slotProps.htmlInput` is not the same as `slotProps.input`.
`slotProps.input` refers to the React `<Input />` component that's rendered based on the specified variant prop.
`slotProps.htmlInput` refers to the HTML `<input>` element rendered within that Input component, regardless of the variant.
:::

## Validation

The `error` prop toggles the error state.
Expand Down

0 comments on commit 93f3d9c

Please sign in to comment.