diff --git a/src/content/reference/react-dom/components/input.md b/src/content/reference/react-dom/components/input.md index b6214249d..4ebea08a1 100644 --- a/src/content/reference/react-dom/components/input.md +++ b/src/content/reference/react-dom/components/input.md @@ -4,7 +4,7 @@ title: "" -The [built-in browser `` component](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) lets you render different kinds of form inputs. +O [componente `` do navegador](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input) integrado permite que você renderize diferentes tipos de entradas de formulário. ```js @@ -16,94 +16,94 @@ The [built-in browser `` component](https://developer.mozilla.org/en-US/d --- -## Reference {/*reference*/} +## Referência {/*reference*/} ### `` {/*input*/} -To display an input, render the [built-in browser ``](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) component. +Para exibir uma entrada, renderize o componente [`` do navegador integrado](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input). ```js ``` -[See more examples below.](#usage) +[Veja mais exemplos abaixo.](#usage) #### Props {/*props*/} -`` supports all [common element props.](/reference/react-dom/components/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. - -#### 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. +O componente `` aceita todas as [props comuns de elementos.](/reference/react-dom/components/common#props) + +- [`formAction`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formaction): Uma string ou função. Substitui o `` pai para `type="submit"` e `type="image"`. Quando uma URL for passada para `action`, o formulário se comportará como um formulário HTML padrão. Quando uma função é passada para `formAction`, a função manipulará o envio do formulário. Veja [``](/reference/react-dom/components/form#props). + +Você pode [tornar uma entrada controlada](#controlling-an-input-with-a-state-variable) passando uma dessas props: + +* [`checked`](https://developer.mozilla.org/pt-BR/docs/Web/API/HTMLInputElement#checked): Um booleano. Para uma entrada do tipo checkbox ou um botão de rádio, controla se está selecionado. +* [`value`](https://developer.mozilla.org/pt-BR/docs/Web/API/HTMLInputElement#value): Uma string. Para uma entrada de texto, controla o seu texto. (Para um botão de rádio, especifica seus dados de formulário.) + +Quando você passa qualquer uma delas, também deve passar um manipulador `onChange` que atualiza o valor passado. + +Essas props do componente `` são relevantes apenas para entradas não controladas: + +* [`defaultChecked`](https://developer.mozilla.org/pt-BR/docs/Web/API/HTMLInputElement#defaultChecked): Um booleano. Especifica [o valor inicial](#providing-an-initial-value-for-an-input) para entradas do tipo `type="checkbox"` e `type="radio"`. +* [`defaultValue`](https://developer.mozilla.org/pt-BR/docs/Web/API/HTMLInputElement#defaultValue): Uma string. Especifica [o valor inicial](#providing-an-initial-value-for-an-input) para uma entrada de texto. + +Essas props do componente `` são relevantes tanto para entradas não controladas quanto para controladas: + +* [`accept`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#accept): Uma string. Especifica quais tipos de arquivo são aceitos por uma entrada `type="file"`. +* [`alt`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#alt): Uma string. Especifica o texto alternativo da imagem para uma entrada `type="image"`. +* [`capture`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#capture): Uma string. Especifica a mídia (microfone, vídeo ou câmera) capturada por uma entrada `type="file"`. +* [`autoComplete`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#autocomplete): Uma string. Especifica um dos possíveis [comportamentos de preenchimento automático.](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Attributes/autocomplete#values) +* [`autoFocus`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#autofocus): Um booleano. Se `true`, o React focará o elemento na montagem. +* [`dirname`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#dirname): Uma string. Especifica o nome do campo do formulário para a direcionalidade do elemento. +* [`disabled`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#disabled): Um booleano. Se `true`, a entrada não será interativa e aparecerá esmaecida. +* `children`: O componente `` não aceita `children`. +* [`form`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#form): Uma string. Especifica o `id` do componente `` a que esta entrada pertence. Se omitido, é o formulário pai mais próximo. +* [`formAction`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formaction): Uma string. Substitui o `` pai para `type="submit"` e `type="image"`. +* [`formEnctype`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formenctype): Uma string. Substitui o `` pai para `type="submit"` e `type="image"`. +* [`formMethod`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formmethod): Uma string. Substitui o `` pai para `type="submit"` e `type="image"`. +* [`formNoValidate`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formnovalidate): Uma string. Substitui o `` pai para `type="submit"` e `type="image"`. +* [`formTarget`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#formtarget): Uma string. Substitui o `` pai para `type="submit"` e `type="image"`. +* [`height`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#height): Uma string. Especifica a altura da imagem para `type="image"`. +* [`list`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#list): Uma string. Especifica o `id` do componente `` com as opções de preenchimento automático. +* [`max`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#max): Um número. Especifica o valor máximo das entradas numéricas e de data/hora. +* [`maxLength`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#maxlength): Um número. Especifica o comprimento máximo de texto e outras entradas. +* [`min`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#min): Um número. Especifica o valor mínimo das entradas numéricas e de data/hora. +* [`minLength`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#minlength): Um número. Especifica o comprimento mínimo de texto e outras entradas. +* [`multiple`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#multiple): Um booleano. Especifica se vários valores são permitidos para ``. O React estende o evento `onSelect` para também disparar para seleção vazia e em edições (que podem afetar a seleção). +* `onSelectCapture`: Uma versão do `onSelect` que dispara na [fase de captura.](/learn/responding-to-events#capture-phase-events) +* [`pattern`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#pattern): Uma string. Especifica o padrão que o `value` deve corresponder. +* [`placeholder`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#placeholder): Uma string. Exibido em uma cor esmaecida quando o valor da entrada está vazio. +* [`readOnly`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#readonly): Um booleano. Se `true`, a entrada não é editável pelo usuário. +* [`required`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#required): Um booleano. Se `true`, o valor deve ser fornecido para o formulário ser enviado. +* [`size`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#size): Um número. Semelhante a definir a largura, mas a unidade depende do controle. +* [`src`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#src): Uma string. Especifica a fonte da imagem para uma entrada `type="image"`. +* [`step`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#step): Um número positivo ou uma string `'any'`. Especifica a distância entre valores válidos. +* [`type`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#type): Uma string. Um dos [tipos de entrada.](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#input_types) +* [`width`](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#width): Uma string. Especifica a largura da imagem para uma entrada `type="image"`. + +#### Ressalvas {/*caveats*/} + +- Checkboxes precisam de `checked` (ou `defaultChecked`), não de `value` (ou `defaultValue`). +- Se uma entrada de texto receber uma prop `value` string, ela será [tratada como controlada.](#controlling-an-input-with-a-state-variable) +- Se um checkbox ou um botão de rádio receber uma prop `checked` booleana, ele será [tratado como controlado.](#controlling-an-input-with-a-state-variable) +- Uma entrada não pode ser controlada e não controlada ao mesmo tempo. +- Uma entrada não pode alternar entre ser controlada ou não controlada durante sua vida útil. +- Toda entrada controlada precisa de um manipulador de evento `onChange` que atualiza o valor de apoio de forma síncrona. --- -## Usage {/*usage*/} +## Uso {/*usage*/} -### Displaying inputs of different types {/*displaying-inputs-of-different-types*/} +### Exibindo entradas de diferentes tipos {/*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) +Para exibir uma entrada, renderize um componente ``. Por padrão, será uma entrada de texto. Você pode passar `type="checkbox"` para uma checkbox, `type="radio"` para um botão de rádio, [ou um dos outros tipos de entrada.](https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/input#input_types) @@ -112,7 +112,7 @@ export default function MyForm() { return ( <>

- Radio buttons: + Botões de rádio:

@@ -148,11 +148,11 @@ input { margin: 5px; } --- -### Providing a label for an input {/*providing-a-label-for-an-input*/} +### Fornecendo um rótulo para uma entrada {/*providing-a-label-for-an-input*/} -Typically, you will place every `` inside a [`