diff --git a/src/content/reference/react-dom/components/input.md b/src/content/reference/react-dom/components/input.md index 37ff14d98..5ab68554b 100644 --- a/src/content/reference/react-dom/components/input.md +++ b/src/content/reference/react-dom/components/input.md @@ -1,10 +1,17 @@ --- title: "" +translationStatus: ai-draft --- + + +Questa pagina è stata tradotta automaticamente e supervisionata da un maintainer. Un'ulteriore revisione da parte della community sarebbe comunque utile. [Migliora questa traduzione](https://github.com/reactjs/it.react.dev/edit/main/src/content/reference/react-dom/components/input.md). + + + -The [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) lets you render different kinds of form inputs. +Il [componente browser integrato ``](https://developer.mozilla.org/it/docs/Web/HTML/Element/input) ti permette di renderizzare diversi tipi di input per i form. ```js @@ -20,90 +27,90 @@ The [built-in browser `` component](https://developer.mozilla.org/en-US/d ### `` {/*input*/} -To display an input, render the [built-in browser ``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) component. +Per visualizzare un input, renderizza il [componente browser integrato ``](https://developer.mozilla.org/it/docs/Web/HTML/Element/input). ```js ``` -[See more examples below.](#usage) +[Vedi altri esempi sotto.](#usage) #### Props {/*props*/} -`` supports all [common element props.](/reference/react-dom/components/common#common-props) - -- [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): A string or function. Overrides the parent `
` for `type="submit"` and `type="image"`. When a URL is passed to `action` the form will behave like a standard HTML form. When a function is passed to `formAction` the function will handle the form submission. See [``](/reference/react-dom/components/form#props). - -You can [make an input controlled](#controlling-an-input-with-a-state-variable) by passing one of these props: - -* [`checked`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#checked): A boolean. For a checkbox input or a radio button, controls whether it is selected. -* [`value`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#value): A string. For a text input, controls its text. (For a radio button, specifies its form data.) - -When you pass either of them, you must also pass an `onChange` handler that updates the passed value. - -These `` props are only relevant for uncontrolled inputs: - -* [`defaultChecked`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#defaultChecked): A boolean. Specifies [the initial value](#providing-an-initial-value-for-an-input) for `type="checkbox"` and `type="radio"` inputs. -* [`defaultValue`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#defaultValue): A string. Specifies [the initial value](#providing-an-initial-value-for-an-input) for a text input. - -These `` props are relevant both for uncontrolled and controlled inputs: - -* [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#accept): A string. Specifies which filetypes are accepted by a `type="file"` input. -* [`alt`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#alt): A string. Specifies the alternative image text for a `type="image"` input. -* [`capture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#capture): A string. Specifies the media (microphone, video, or camera) captured by a `type="file"` input. -* [`autoComplete`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete): A string. Specifies one of the possible [autocomplete behaviors.](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values) -* [`autoFocus`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autofocus): A boolean. If `true`, React will focus the element on mount. -* [`dirname`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#dirname): A string. Specifies the form field name for the element's directionality. -* [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#disabled): A boolean. If `true`, the input will not be interactive and will appear dimmed. -* `children`: `` does not accept children. -* [`form`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#form): A string. Specifies the `id` of the `` this input belongs to. If omitted, it's the closest parent form. -* [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): A string. Overrides the parent `` for `type="submit"` and `type="image"`. -* [`formEnctype`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formenctype): A string. Overrides the parent `` for `type="submit"` and `type="image"`. -* [`formMethod`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formmethod): A string. Overrides the parent `` for `type="submit"` and `type="image"`. -* [`formNoValidate`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formnovalidate): A string. Overrides the parent `` for `type="submit"` and `type="image"`. -* [`formTarget`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formtarget): A string. Overrides the parent `` for `type="submit"` and `type="image"`. -* [`height`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#height): A string. Specifies the image height for `type="image"`. -* [`list`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#list): A string. Specifies the `id` of the `` with the autocomplete options. -* [`max`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#max): A number. Specifies the maximum value of numerical and datetime inputs. -* [`maxLength`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#maxlength): A number. Specifies the maximum length of text and other inputs. -* [`min`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#min): A number. Specifies the minimum value of numerical and datetime inputs. -* [`minLength`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#minlength): A number. Specifies the minimum length of text and other inputs. -* [`multiple`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#multiple): A boolean. Specifies whether multiple values are allowed for `` changes. React extends the `onSelect` event to also fire for empty selection and on edits (which may affect the selection). -* `onSelectCapture`: A version of `onSelect` that fires in the [capture phase.](/learn/responding-to-events#capture-phase-events) -* [`pattern`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#pattern): A string. Specifies the pattern that the `value` must match. -* [`placeholder`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#placeholder): A string. Displayed in a dimmed color when the input value is empty. -* [`readOnly`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#readonly): A boolean. If `true`, the input is not editable by the user. -* [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#required): A boolean. If `true`, the value must be provided for the form to submit. -* [`size`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#size): A number. Similar to setting width, but the unit depends on the control. -* [`src`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src): A string. Specifies the image source for a `type="image"` input. -* [`step`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#step): A positive number or an `'any'` string. Specifies the distance between valid values. -* [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#type): A string. One of the [input types.](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types) -* [`width`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#width): A string. Specifies the image width for a `type="image"` input. +`` supporta tutte le [props comuni degli elementi.](/reference/react-dom/components/common#common-props) + +- [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): Una stringa o una funzione. Sostituisce l'`` padre per `type="submit"` e `type="image"`. Quando a `action` viene passato un URL, il form si comporterà come un form HTML standard. Quando a `formAction` viene passata una funzione, la funzione gestirà l'invio del form. Vedi [``](/reference/react-dom/components/form#props). + +Puoi [controllare un input](#controlling-an-input-with-a-state-variable) passando una di queste props: + +* [`checked`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#checked): Un booleano. Per un input checkbox o un radio button, controlla se è selezionato. +* [`value`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#value): Una stringa. Per un input di testo, controlla il suo testo. (Per un radio button, specifica i suoi dati del form.) + +Quando passi una delle due, devi anche passare un gestore di eventi `onChange` che aggiorni il valore passato. + +Queste props di `` sono rilevanti solo per input non controllati: + +* [`defaultChecked`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#defaultChecked): Un booleano. Specifica [il valore iniziale](#providing-an-initial-value-for-an-input) per input `type="checkbox"` e `type="radio"`. +* [`defaultValue`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#defaultValue): Una stringa. Specifica [il valore iniziale](#providing-an-initial-value-for-an-input) per un input di testo. + +Queste props di `` sono rilevanti sia per input non controllati che controllati: + +* [`accept`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#accept): Una stringa. Specifica quali tipi di file sono accettati da un input `type="file"`. +* [`alt`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#alt): Una stringa. Specifica il testo alternativo dell'immagine per un input `type="image"`. +* [`capture`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#capture): Una stringa. Specifica il media (microfono, video o fotocamera) catturato da un input `type="file"`. +* [`autoComplete`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autocomplete): Una stringa. Specifica uno dei possibili [comportamenti di autocomplete.](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values) +* [`autoFocus`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#autofocus): Un booleano. Se `true`, React metterà a fuoco l'elemento al montaggio. +* [`dirname`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#dirname): Una stringa. Specifica il nome del campo del form per la direzionalità dell'elemento. +* [`disabled`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#disabled): Un booleano. Se `true`, l'input non sarà interattivo e apparirà attenuato. +* `children`: `` non accetta children. +* [`form`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#form): Una stringa. Specifica l'`id` del `` a cui appartiene questo input. Se omesso, è il form padre più vicino. +* [`formAction`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formaction): Una stringa. Sostituisce l'`` padre per `type="submit"` e `type="image"`. +* [`formEnctype`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formenctype): Una stringa. Sostituisce l'`` padre per `type="submit"` e `type="image"`. +* [`formMethod`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formmethod): Una stringa. Sostituisce il `` padre per `type="submit"` e `type="image"`. +* [`formNoValidate`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formnovalidate): Una stringa. Sostituisce il `` padre per `type="submit"` e `type="image"`. +* [`formTarget`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#formtarget): Una stringa. Sostituisce il `` padre per `type="submit"` e `type="image"`. +* [`height`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#height): Una stringa. Specifica l'altezza dell'immagine per `type="image"`. +* [`list`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#list): Una stringa. Specifica l'`id` del `` con le opzioni di autocomplete. +* [`max`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#max): Un numero. Specifica il valore massimo degli input numerici e datetime. +* [`maxLength`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#maxlength): Un numero. Specifica la lunghezza massima di testo e altri input. +* [`min`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#min): Un numero. Specifica il valore minimo degli input numerici e datetime. +* [`minLength`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#minlength): Un numero. Specifica la lunghezza minima di testo e altri input. +* [`multiple`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#multiple): Un booleano. Specifica se sono consentiti valori multipli per `` cambia. React estende l'evento `onSelect` per scattare anche con selezione vuota e durante le modifiche (che possono influenzare la selezione). +* `onSelectCapture`: Una versione di `onSelect` che scatta nella [fase di capture.](/learn/responding-to-events#capture-phase-events) +* [`pattern`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#pattern): Una stringa. Specifica il pattern che il `value` deve rispettare. +* [`placeholder`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#placeholder): Una stringa. Visualizzata con un colore attenuato quando il valore dell'input è vuoto. +* [`readOnly`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#readonly): Un booleano. Se `true`, l'input non è modificabile dall'utente. +* [`required`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#required): Un booleano. Se `true`, il valore deve essere fornito affinché il form possa essere inviato. +* [`size`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#size): Un numero. Simile all'impostazione della larghezza, ma l'unità dipende dal controllo. +* [`src`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#src): Una stringa. Specifica la sorgente dell'immagine per un input `type="image"`. +* [`step`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#step): Un numero positivo o una stringa `'any'`. Specifica la distanza tra valori validi. +* [`type`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#type): Una stringa. Uno dei [tipi di input.](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types) +* [`width`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#width): Una stringa. Specifica la larghezza dell'immagine per un input `type="image"`. #### Caveats {/*caveats*/} -- Checkboxes need `checked` (or `defaultChecked`), not `value` (or `defaultValue`). -- If a text input receives a string `value` prop, it will be [treated as controlled.](#controlling-an-input-with-a-state-variable) -- If a checkbox or a radio button receives a boolean `checked` prop, it will be [treated as controlled.](#controlling-an-input-with-a-state-variable) -- An input can't be both controlled and uncontrolled at the same time. -- An input cannot switch between being controlled or uncontrolled over its lifetime. -- Every controlled input needs an `onChange` event handler that synchronously updates its backing value. +- Le checkbox necessitano di `checked` (o `defaultChecked`), non di `value` (o `defaultValue`). +- Se un input di testo riceve una prop `value` di tipo stringa, verrà [trattato come controllato.](#controlling-an-input-with-a-state-variable) +- Se una checkbox o un radio button riceve una prop `checked` booleana, verrà [trattato come controllato.](#controlling-an-input-with-a-state-variable) +- Un input non può essere contemporaneamente controllato e non controllato. +- Un input non può passare da controllato a non controllato (o viceversa) nel corso della sua vita. +- Ogni input controllato necessita di un gestore di eventi `onChange` che aggiorni in modo sincrono il valore sottostante. --- ## Usage {/*usage*/} -### Displaying inputs of different types {/*displaying-inputs-of-different-types*/} +### Visualizzare input di tipi diversi {/*displaying-inputs-of-different-types*/} -To display an input, render an `` component. By default, it will be a text input. You can pass `type="checkbox"` for a checkbox, `type="radio"` for a radio button, [or one of the other input types.](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types) +Per visualizzare un input, renderizza un componente ``. Per impostazione predefinita, sarà un input di testo. Puoi passare `type="checkbox"` per una checkbox, `type="radio"` per un radio button, [o uno degli altri tipi di input.](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types) @@ -148,11 +155,11 @@ input { margin: 5px; } --- -### Providing a label for an input {/*providing-a-label-for-an-input*/} +### Fornire un'etichetta per un input {/*providing-a-label-for-an-input*/} -Typically, you will place every `` inside a [`