|
1
|
--- |
|
2
|
sidebar_label: "Handle Input" |
|
3
|
--- |
|
4
|
|
|
5
|
import { TypeList } from "docs-ui" |
|
6
|
|
|
7
|
export const metadata = { |
|
8
|
title: `HandleInput - Admin Components`, |
|
9
|
} |
|
10
|
|
|
11
|
# {metadata.title} |
|
12
|
|
|
13
|
<Note> |
|
14
|
|
|
15
|
This component is available since Medusa [v2.21.0](https://github.com/medusajs/medusa/releases/tag/v2.21.0). |
|
16
|
|
|
17
|
</Note> |
|
18
|
|
|
19
|
The `HandleInput` component is a text input with a leading slash, which shows the user that the value is a URL segment. The Medusa Admin uses it in the forms of records that have a handle, such as products, collections, and categories. |
|
20
|
|
|
21
|
```tsx |
|
22
|
import { HandleInput } from "@medusajs/dashboard/components" |
|
23
|
``` |
|
24
|
|
|
25
|
--- |
|
26
|
|
|
27
|
## Example |
|
28
|
|
|
29
|
Use `HandleInput` as the control of a `Form` field, as shown in the [Forms guide](../../guides/forms/page.mdx): |
|
30
|
|
|
31
|
```tsx |
|
32
|
import { |
|
33
|
Form, |
|
34
|
HandleInput, |
|
35
|
} from "@medusajs/dashboard/components" |
|
36
|
|
|
37
|
const HandleField = ({ control }) => { |
|
38
|
return ( |
|
39
|
<Form.Field |
|
40
|
control={control} |
|
41
|
name="handle" |
|
42
|
render={({ field }) => ( |
|
43
|
<Form.Item> |
|
44
|
<Form.Label |
|
45
|
optional |
|
46
|
tooltip="Used in the brand's URL." |
|
47
|
> |
|
48
|
Handle |
|
49
|
</Form.Label> |
|
50
|
<Form.Control> |
|
51
|
<HandleInput {...field} /> |
|
52
|
</Form.Control> |
|
53
|
<Form.ErrorMessage /> |
|
54
|
</Form.Item> |
|
55
|
)} |
|
56
|
/> |
|
57
|
) |
|
58
|
} |
|
59
|
``` |
|
60
|
|
|
61
|
The slash is decorative, so the field's value doesn't include it. |
|
62
|
|
|
63
|
--- |
|
64
|
|
|
65
|
## Props |
|
66
|
|
|
67
|
`HandleInput` accepts the same props as the [Input UI component](!ui!/components/input), including the following: |
|
68
|
|
|
69
|
<TypeList |
|
70
|
types={[ |
|
71
|
{ |
|
72
|
name: "value", |
|
73
|
type: "`string`", |
|
74
|
optional: true, |
|
75
|
description: `The input's value, without the leading slash.`, |
|
76
|
}, |
|
77
|
{ |
|
78
|
name: "onChange", |
|
79
|
type: "`(event: React.ChangeEvent<HTMLInputElement>) => void`", |
|
80
|
optional: true, |
|
81
|
description: `The function to execute when the user changes the input's value.`, |
|
82
|
}, |
|
83
|
{ |
|
84
|
name: "placeholder", |
|
85
|
type: "`string`", |
|
86
|
optional: true, |
|
87
|
description: `The placeholder to show when the input is empty.`, |
|
88
|
}, |
|
89
|
{ |
|
90
|
name: "disabled", |
|
91
|
type: "`boolean`", |
|
92
|
optional: true, |
|
93
|
description: `Whether the input is disabled.`, |
|
94
|
}, |
|
95
|
]} |
|
96
|
/> |
|
97
|
|
|
98
|
`HandleInput` also accepts every other prop of the [Input component](!ui!/components/input), such as `size` and `id`, along with the attributes of a native input element. |