Skip to content

Commit 86e7edf

Browse files
Adding translation to createPortal (#674)
* Adding translation to createPortal * Update src/content/reference/react-dom/createPortal.md --------- Co-authored-by: Mateo Guzmán <[email protected]>
1 parent 2273c1e commit 86e7edf

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/content/reference/react-dom/createPortal.md

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: createPortal
44

55
<Intro>
66

7-
`createPortal` lets you render some children into a different part of the DOM.
7+
`createPortal` permite renderizar componentes hijos en otra parte del DOM.
88

99

1010
```js
@@ -20,75 +20,75 @@ title: createPortal
2020
2121
---
2222
23-
## Reference {/*reference*/}
23+
## Referencia {/*reference*/}
2424
2525
### `createPortal(children, domNode, key?)` {/*createportal*/}
2626
27-
To create a portal, call `createPortal`, passing some JSX, and the DOM node where it should be rendered:
27+
Para crear un portal, debes llamar a `createPortal` y pasarle el JSX junto con el nodo de DOM donde se renderizará:
2828
2929
```js
3030
import { createPortal } from 'react-dom';
3131

3232
// ...
3333

3434
<div>
35-
<p>This child is placed in the parent div.</p>
35+
<p>Este elemento hijo va en el div padre.</p>
3636
{createPortal(
37-
<p>This child is placed in the document body.</p>,
37+
<p>Este elemento hijo va en el body.</p>,
3838
document.body
3939
)}
4040
</div>
4141
```
4242
43-
[See more examples below.](#usage)
43+
[Ver más ejemplos a continuación.](#usage)
4444
45-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events bubble up from children to parents according to the React tree.
45+
Un portal modifica solamente la ubicación física del nodo de DOM, mientras que el JSX que se renderiza en él actúa como un nodo hijo del componente de React que lo renderiza. Por lo tanto, el nodo hijo tendrá acceso al contexto proporcionado por el árbol padre y los eventos se propagarán de hijo a padre siguiendo la estructura del árbol de React.
4646
47-
#### Parameters {/*parameters*/}
47+
#### Parámetros {/*parameters*/}
4848
49-
* `children`: Anything that can be rendered with React, such as a piece of JSX (e.g. `<div />` or `<SomeComponent />`), a [Fragment](/reference/react/Fragment) (`<>...</>`), a string or a number, or an array of these.
49+
* `children`: Todo elemento que se pueda renderizar con React, ya sea código JSX (por ejemplo, `<div />` o `<SomeComponent />`), un [Fragment](/reference/react/Fragment) (`<>...</>`), un string o un número, o un array que contenga estos elementos.
5050
51-
* `domNode`: Some DOM node, such as those returned by `document.getElementById()`. The node must already exist. Passing a different DOM node during an update will cause the portal content to be recreated.
51+
* `domNode`: Un nodo de DOM, como el que devuelve `document.getElementById()`. El nodo debe existir previamente. Si durante una actualización se pasa un nodo de DOM diferente, el contenido del portal se volverá a crear.
5252
53-
* **optional** `key`: A unique string or number to be used as the portal's [key.](/learn/rendering-lists/#keeping-list-items-in-order-with-key)
53+
* **opcional** `key`: Un valor único en forma de string o número que se usará como [key](/learn/rendering-lists/#keeping-list-items-in-order-with-key) para el portal.
5454
55-
#### Returns {/*returns*/}
55+
#### Valor devuelto {/*returns*/}
5656
57-
`createPortal` returns a React node that can be included into JSX or returned from a React component. If React encounters it in the render output, it will place the provided `children` inside the provided `domNode`.
57+
`createPortal` devuelve un nodo de React que puede incluirse en JSX o ser devuelto desde un componente de React. Si React encuentra el nodo en la salida del renderizado, insertará `children` dentro del `domNode` proporcionado.
5858
59-
#### Caveats {/*caveats*/}
59+
#### Advertencias {/*caveats*/}
6060
61-
* Events from portals propagate according to the React tree rather than the DOM tree. For example, if you click inside a portal, and the portal is wrapped in `<div onClick>`, that `onClick` handler will fire. If this causes issues, either stop the event propagation from inside the portal, or move the portal itself up in the React tree.
61+
* Los eventos del portal se propagan siguiendo la estructura del árbol de React en lugar del árbol del DOM. Por ejemplo, si haces clic dentro del portal, y el portal está envuelto en `<div onClick>`, ese `onClick` se ejecutará. Si esto causa problemas, puedes detener la propagación del evento desde el portal o levantar el portal en la estructura del árbol de React.
6262
6363
---
6464
65-
## Usage {/*usage*/}
65+
## Uso {/*usage*/}
6666
67-
### Rendering to a different part of the DOM {/*rendering-to-a-different-part-of-the-dom*/}
67+
### Renderizar en otra parte del DOM {/*rendering-to-a-different-part-of-the-dom*/}
6868
69-
*Portals* let your components render some of their children into a different place in the DOM. This lets a part of your component "escape" from whatever containers it may be in. For example, a component can display a modal dialog or a tooltip that appears above and outside of the rest of the page.
69+
Los *portales* permiten que tus componentes rendericen sus elementos hijos en otras partes del DOM, permitiéndoles "escapar" de cualquier contenedor en el que se encuentren. Por ejemplo, un componente puede mostrar una ventana modal o un tooltip que aparezca por encima y fuera del resto de la página.
7070
71-
To create a portal, render the result of `createPortal` with <CodeStep step={1}>some JSX</CodeStep> and the <CodeStep step={2}>DOM node where it should go</CodeStep>:
71+
Para crear un portal, renderiza el resultado de `createPortal` con <CodeStep step={1}>código JSX</CodeStep> y el <CodeStep step={2}>nodo de DOM en el cual se va a insertar</CodeStep>:
7272
73-
```js [[1, 8, "<p>This child is placed in the document body.</p>"], [2, 9, "document.body"]]
73+
```js [[1, 8, "<p>Este elemento hijo va en el body.</p>"], [2, 9, "document.body"]]
7474
import { createPortal } from 'react-dom';
7575

7676
function MyComponent() {
7777
return (
7878
<div style={{ border: '2px solid black' }}>
79-
<p>This child is placed in the parent div.</p>
79+
<p>Este elemento hijo va en el div padre.</p>
8080
{createPortal(
81-
<p>This child is placed in the document body.</p>,
81+
<p>Este elemento hijo va en el body.</p>,
8282
document.body
8383
)}
8484
</div>
8585
);
8686
}
8787
```
8888
89-
React will put the DOM nodes for <CodeStep step={1}>the JSX you passed</CodeStep> inside of the <CodeStep step={2}>DOM node you provided</CodeStep>.
89+
React insertará los nodos de DOM del <CodeStep step={1}>JSX que pasaste</CodeStep> dentro del <CodeStep step={2}>nodo de DOM que proporcionaste</CodeStep>.
9090
91-
Without a portal, the second `<p>` would be placed inside the parent `<div>`, but the portal "teleported" it into the [`document.body`:](https://developer.mozilla.org/en-US/docs/Web/API/Document/body)
91+
Si no se utiliza un portal, el segundo `<p>` se insertaría dentro del `<div>` padre, pero gracias al uso del portal, este se "teletransporta" al elemento [`document.body`:](https://developer.mozilla.org/es/docs/Web/API/Document/body)
9292
9393
<Sandpack>
9494
@@ -98,9 +98,9 @@ import { createPortal } from 'react-dom';
9898
export default function MyComponent() {
9999
return (
100100
<div style={{ border: '2px solid black' }}>
101-
<p>This child is placed in the parent div.</p>
101+
<p>Este elemento hijo va en el div padre.</p>
102102
{createPortal(
103-
<p>This child is placed in the document body.</p>,
103+
<p>Este elemento hijo va en el body.</p>,
104104
document.body
105105
)}
106106
</div>
@@ -110,30 +110,30 @@ export default function MyComponent() {
110110
111111
</Sandpack>
112112
113-
Notice how the second paragraph visually appears outside the parent `<div>` with the border. If you inspect the DOM structure with developer tools, you'll see that the second `<p>` got placed directly into the `<body>`:
113+
Nota cómo el segundo párrafo aparece visualmente fuera del `<div>` padre con borde. Si inspeccionas la estructura del DOM con las herramientas para desarrolladores, verás que el segundo `<p>` se ha insertado directamente dentro del elemento `<body>`:
114114
115115
```html {4-6,9}
116116
<body>
117117
<div id="root">
118118
...
119119
<div style="border: 2px solid black">
120-
<p>This child is placed inside the parent div.</p>
120+
<p>Este elemento hijo va dentro del div padre.</p>
121121
</div>
122122
...
123123
</div>
124-
<p>This child is placed in the document body.</p>
124+
<p>Este elemento hijo va en el body.</p>
125125
</body>
126126
```
127127
128-
A portal only changes the physical placement of the DOM node. In every other way, the JSX you render into a portal acts as a child node of the React component that renders it. For example, the child can access the context provided by the parent tree, and events still bubble up from children to parents according to the React tree.
128+
Un portal modifica solamente la ubicación física del nodo de DOM, mientras que el JSX que se renderiza en él actúa como un nodo hijo del componente de React que lo renderiza. Por lo tanto, el nodo hijo tendrá acceso al contexto proporcionado por el árbol padre y los eventos continuarán propagándose de hijo a padre siguiendo la estructura del árbol de React.
129129
130130
---
131131
132-
### Rendering a modal dialog with a portal {/*rendering-a-modal-dialog-with-a-portal*/}
132+
### Renderizar una ventana modal con un portal {/*rendering-a-modal-dialog-with-a-portal*/}
133133
134-
You can use a portal to create a modal dialog that floats above the rest of the page, even if the component that summons the dialog is inside a container with `overflow: hidden` or other styles that interfere with the dialog.
134+
Los portales permiten dejar que una ventana modal aparezca por encima del resto de la página, incluso si el componente que la llama está dentro de un contenedor con estilos que afecten a la ventana modal, como `overflow: hidden`.
135135
136-
In this example, the two containers have styles that disrupt the modal dialog, but the one rendered into a portal is unaffected because, in the DOM, the modal is not contained within the parent JSX elements.
136+
En este ejemplo, ambos contenedores tienen estilos que interfieren con la ventana modal, pero la que se renderiza a través de un portal no se ve afectada porque, en el DOM, la ventana no está dentro de los elementos JSX padres.
137137
138138
<Sandpack>
139139
@@ -164,7 +164,7 @@ export default function NoPortalExample() {
164164
return (
165165
<>
166166
<button onClick={() => setShowModal(true)}>
167-
Show modal without a portal
167+
Mostrar modal sin uso de portal
168168
</button>
169169
{showModal && (
170170
<ModalContent onClose={() => setShowModal(false)} />
@@ -184,7 +184,7 @@ export default function PortalExample() {
184184
return (
185185
<>
186186
<button onClick={() => setShowModal(true)}>
187-
Show modal using a portal
187+
Mostrar modal con uso de portal
188188
</button>
189189
{showModal && createPortal(
190190
<ModalContent onClose={() => setShowModal(false)} />,
@@ -199,8 +199,8 @@ export default function PortalExample() {
199199
export default function ModalContent({ onClose }) {
200200
return (
201201
<div className="modal">
202-
<div>I'm a modal dialog</div>
203-
<button onClick={onClose}>Close</button>
202+
<div>Soy una ventana modal</div>
203+
<button onClick={onClose}>Cerrar</button>
204204
</div>
205205
);
206206
}
@@ -238,29 +238,29 @@ export default function ModalContent({ onClose }) {
238238
239239
<Pitfall>
240240
241-
It's important to make sure that your app is accessible when using portals. For instance, you may need to manage keyboard focus so that the user can move the focus in and out of the portal in a natural way.
241+
Es importante garantizar la accesibilidad de tu aplicación al utilizar portales. Para ello, puede que tengas que gestionar el foco del teclado para que el usuario pueda navegar dentro y fuera del portal de forma natural.
242242
243-
Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/#dialog_modal) when creating modals. If you use a community package, ensure that it is accessible and follows these guidelines.
243+
Sigue la [Guía de Creación de Ventanas Modales con WAI-ARIA](https://www.w3.org/WAI/ARIA/apg/#dialog_modal) al crear portales. Si usas paquetes de la comunidad, asegúrate de que sean accesibles y sigan estas pautas.
244244
245245
</Pitfall>
246246
247247
---
248248
249-
### Rendering React components into non-React server markup {/*rendering-react-components-into-non-react-server-markup*/}
249+
### Renderizar componentes de React en marcado de servidor no generado por React {/*rendering-react-components-into-non-react-server-markup*/}
250250
251-
Portals can be useful if your React root is only part of a static or server-rendered page that isn't built with React. For example, if your page is built with a server framework like Rails, you can create areas of interactivity within static areas such as sidebars. Compared with having [multiple separate React roots,](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) portals let you treat the app as a single React tree with shared state even though its parts render to different parts of the DOM.
251+
Los portales resultan útiles cuando se desea integrar contenido de React en páginas estáticas o generadas por el servidor. Por ejemplo, si la página está construida con un framework del lado del servidor como Rails, se puede agregar interactividad dentro de áreas estáticas, como sidebars. En lugar de tener [varias raíces de React por separado,](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react) los portales permiten tratar la aplicación como un solo árbol de React con estado compartido, a pesar de que sus partes se rendericen en otras secciones del DOM.
252252
253253
<Sandpack>
254254
255255
```html index.html
256256
<!DOCTYPE html>
257257
<html>
258-
<head><title>My app</title></head>
258+
<head><title>Mi aplicación</title></head>
259259
<body>
260-
<h1>Welcome to my hybrid app</h1>
260+
<h1>Bienvenido a mi aplicación híbrida</h1>
261261
<div class="parent">
262262
<div class="sidebar">
263-
This is server non-React markup
263+
Este marcado de servidor no se renderiza con React
264264
<div id="sidebar-content"></div>
265265
</div>
266266
<div id="root"></div>
@@ -301,11 +301,11 @@ export default function App() {
301301
}
302302

303303
function MainContent() {
304-
return <p>This part is rendered by React</p>;
304+
return <p>Esta sección se renderiza con React</p>;
305305
}
306306

307307
function SidebarContent() {
308-
return <p>This part is also rendered by React!</p>;
308+
return <p>¡Esta sección también se renderiza con React!</p>;
309309
}
310310
```
311311
@@ -342,15 +342,15 @@ p {
342342
343343
---
344344
345-
### Rendering React components into non-React DOM nodes {/*rendering-react-components-into-non-react-dom-nodes*/}
345+
### Renderizar componentes de React en nodos de DOM no generados por React {/*rendering-react-components-into-non-react-dom-nodes*/}
346346
347-
You can also use a portal to manage the content of a DOM node that's managed outside of React. For example, suppose you're integrating with a non-React map widget and you want to render React content inside a popup. To do this, declare a `popupContainer` state variable to store the DOM node you're going to render into:
347+
Se puede manejar el contenido de un nodo de DOM fuera de React utilizando portales. Por ejemplo, si estás trabajando con un widget de mapa que no usa React y deseas renderizar contenido de React dentro de una ventana emergente, puedes hacerlo definiendo una variable de estado `popupContainer` que almacene el nodo de DOM donde se realizará la renderización.
348348
349349
```js
350350
const [popupContainer, setPopupContainer] = useState(null);
351351
```
352352
353-
When you create the third-party widget, store the DOM node returned by the widget so you can render into it:
353+
Al crear el widget de terceros, almacena el nodo de DOM devuelto para poder renderizar en él:
354354
355355
```js {5-6}
356356
useEffect(() => {
@@ -363,20 +363,20 @@ useEffect(() => {
363363
}, []);
364364
```
365365
366-
This lets you use `createPortal` to render React content into `popupContainer` once it becomes available:
366+
De esta forma, puedes usar `createPortal` para renderizar contenido de React en `popupContainer` una vez que esté disponible:
367367
368368
```js {3-6}
369369
return (
370370
<div style={{ width: 250, height: 250 }} ref={containerRef}>
371371
{popupContainer !== null && createPortal(
372-
<p>Hello from React!</p>,
372+
<p>¡Saludos desde React!</p>,
373373
popupContainer
374374
)}
375375
</div>
376376
);
377377
```
378378
379-
Here is a complete example you can play with:
379+
A continuación, un ejemplo completo para que puedas probar:
380380
381381
<Sandpack>
382382
@@ -420,7 +420,7 @@ export default function Map() {
420420
return (
421421
<div style={{ width: 250, height: 250 }} ref={containerRef}>
422422
{popupContainer !== null && createPortal(
423-
<p>Hello from React!</p>,
423+
<p>¡Saludos desde React!</p>,
424424
popupContainer
425425
)}
426426
</div>

0 commit comments

Comments
 (0)