You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/portals.md
+34-34
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,25 @@
1
1
---
2
2
id: portals
3
-
title: Portals
3
+
title: Portales
4
4
permalink: docs/portals.html
5
5
---
6
6
7
-
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.
7
+
Los portales proporcionan una opción de primera clase para renderizar hijos en un nodo DOM que existe por fuera de la jerarquía del DOM del Componente padre.
8
8
9
9
```js
10
10
ReactDOM.createPortal(child, container)
11
11
```
12
12
13
-
The first argument (`child`) is any [renderable React child](/docs/react-component.html#render), such as an element, string, or fragment. The second argument (`container`) is a DOM element.
13
+
El primer argumento (`child`) es cualquier [hijo renderizable por React](/docs/react-component.html#render), como un elemento, cadena de caracteres o fragmento. El segundo argumento (`container`) es un elemento DOM.
14
14
15
-
## Usage {#usage}
15
+
## Uso {#usage}
16
16
17
-
Normally, when you return an element from a component's render method, it's mounted into the DOM as a child of the nearest parent node:
17
+
Normalmente, cuando retornas un elemento del método de render de un componente, este se monta en el DOM como un elemento hijo del nodo padre más cercano:
18
18
19
19
```js{4,6}
20
20
render() {
21
-
// React mounts a new div and renders the children into it
21
+
// React crea un nuevo elemento y muestra al
22
+
// componente hijo dentro de él.
22
23
return (
23
24
<div>
24
25
{this.props.children}
@@ -27,34 +28,34 @@ render() {
27
28
}
28
29
```
29
30
30
-
However, sometimes it's useful to insert a child into a different location in the DOM:
31
+
Sin embargo, a veces es útil insertar un hijo en una ubicación diferente en el DOM:
31
32
32
33
```js{6}
33
34
render() {
34
-
// React does *not* create a new div. It renders the children into `domNode`.
35
-
// `domNode` is any valid DOM node, regardless of its location in the DOM.
35
+
// React *no* crea un nuevo div, convierte el hijo en `domNode`.
36
+
// `domNode` es cualquier nodo DOM válido, independientemente de su ubicación en el DOM.
36
37
return ReactDOM.createPortal(
37
38
this.props.children,
38
39
domNode
39
40
);
40
41
}
41
42
```
42
43
43
-
A typical use case for portals is when a parent component has an `overflow: hidden` or `z-index` style, but you need the child to visually "break out" of its container. For example, dialogs, hovercards, and tooltips.
44
+
Un caso de uso típico de los portales es cuando un componente principal tiene un estilo `overflow: hidden` or `z-index`, pero necesita que el elemento "salga" visualmente de su contenedor. Por ejemplo, cuadros de diálogo, *hovercards* y *tooltips*.
44
45
45
-
> Note:
46
+
> Nota:
46
47
>
47
-
> When working with portals, remember that [managing keyboard focus](/docs/accessibility.html#programmatically-managing-focus)becomes very important.
48
+
> Cuando trabajes con portales, recuerda que [administrar el foco del teclado](/docs/accessibility.html#programmatically-managing-focus)es muy importante.
48
49
>
49
-
> For modal dialogs, ensure that everyone can interact with them by following the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal).
50
+
> Para los cuadros de diálogos, asegúrate de que todos puedan interactuar con ellos siguiendo las [Prácticas de creación modal de WAI-ARIA](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal).
50
51
51
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/yzMaBd)
52
+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/yzMaBd)
52
53
53
-
## Event Bubbling Through Portals {#event-bubbling-through-portals}
54
+
## Propagación de eventos a través de Portales {#event-bubbling-through-portals}
54
55
55
-
Even though a portal can be anywhere in the DOM tree, it behaves like a normal React child in every other way. Features like context work exactly the same regardless of whether the child is a portal, as the portal still exists in the *React tree* regardless of position in the *DOM tree*.
56
+
Aunque un portal puede estar en cualquier parte del árbol DOM, se comporta como un hijo de React normal en cualquier otra forma. Las características como el contexto funcionan exactamente de la misma manera, independientemente de si el elemento hijo es un portal, ya que el portal aún existe en el *árbol de React* sin importar la posición en el *árbol DOM*.
56
57
57
-
This includes event bubbling. An event fired from inside a portal will propagate to ancestors in the containing *React tree*, even if those elements are not ancestors in the *DOM tree*. Assuming the following HTML structure:
58
+
Esto incluye propagación de eventos. Un evento activado desde adentro de un portal se propagará a los ancestros en el *árbol de React*, incluso si esos elementos no son ancestros en el *árbol DOM*. Asumiendo la siguiente estructura HTML:
58
59
59
60
```html
60
61
<html>
@@ -65,10 +66,10 @@ This includes event bubbling. An event fired from inside a portal will propagate
65
66
</html>
66
67
```
67
68
68
-
A `Parent`component in `#app-root`would be able to catch an uncaught, bubbling event from the sibling node`#modal-root`.
69
+
Un componente `Parent`en `#app-root`sería capaz de detectar un evento de propagación no capturado desde el nodo hermano`#modal-root`.
@@ -79,14 +80,13 @@ class Modal extends React.Component {
79
80
}
80
81
81
82
componentDidMount() {
82
-
// The portal element is inserted in the DOM tree after
83
-
// the Modal's children are mounted, meaning that children
84
-
// will be mounted on a detached DOM node. If a child
85
-
// component requires to be attached to the DOM tree
86
-
// immediately when mounted, for example to measure a
87
-
// DOM node, or uses 'autoFocus' in a descendant, add
88
-
// state to Modal and only render the children when Modal
89
-
// is inserted in the DOM tree.
83
+
// El elemento del portal se inserta en el árbol DOM después de
84
+
// que se montan los hijos del Modal, lo que significa que los hijos
85
+
// se montarán en un nodo DOM separado. Si un componente hijo
86
+
// requiere estar conectado inmediatamente cuando se monta al árbol del DOM
87
+
// por ejemplo, para medir un nodo DOM, o usar 'autoFocus' en un descendiente,
88
+
// agrega el estado a Modal y renderiza solo a los hijos
89
+
// cuando se inserta Modal en el árbol DOM.
90
90
modalRoot.appendChild(this.el);
91
91
}
92
92
@@ -110,9 +110,9 @@ class Parent extends React.Component {
110
110
}
111
111
112
112
handleClick() {
113
-
// This will fire when the button in Child is clicked,
114
-
// updating Parent's state, even though button
115
-
// is not direct descendant in the DOM.
113
+
// Esto se activará cuando el botón en el Child sea cliqueado,
114
+
// actualizando el estado de Parent,
115
+
// aunque el botón no sea descendiente directo en el DOM.
116
116
this.setState(state => ({
117
117
clicks: state.clicks + 1
118
118
}));
@@ -137,8 +137,8 @@ class Parent extends React.Component {
137
137
}
138
138
139
139
function Child() {
140
-
// The click event on this button will bubble up to parent,
141
-
// because there is no 'onClick' attribute defined
140
+
// El evento de clic en este botón se convertirá en principal,
141
+
// porque no hay un atributo 'onClick' definido.
142
142
return (
143
143
<div className="modal">
144
144
<button>Click</button>
@@ -149,6 +149,6 @@ function Child() {
149
149
ReactDOM.render(<Parent />, appRoot);
150
150
```
151
151
152
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBWpE)
152
+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/jGBWpE)
153
153
154
-
Catching an event bubbling up from a portal in a parent component allows the development of more flexible abstractions that are not inherently reliant on portals. For example, if you render a`<Modal />` component, the parent can capture its events regardless of whether it's implemented using portals.
154
+
La captura de un evento que sale de un portal en un componente padre permite el desarrollo de abstracciones más flexibles que no dependen intrínsecamente de los portales. Por ejemplo, si renderizas un componente`<Modal />`, el padre puede capturar sus eventos sin importar si es implementado usando portales.
0 commit comments