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
* update portals (translating to PT-BR)
* update portals
* Fix typos
* Atualização de "Uso" para "Utilização"
* Correção de erro de digitação
* Correção de erro de digitação
* Correção da tradução de "modal"
* Correção de erro de digitação
* Correção de plural
* Atualização de "notar" para "observar"
* atualização
* Update portals.md
Copy file name to clipboardExpand all lines: content/docs/portals.md
+40-40Lines changed: 40 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,21 @@ title: Portals
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
+
Portals fornece uma forma elegante de renderizar um elemento filho dentro de um nó DOM que existe fora da hierarquia do componente pai.
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
+
O primeiro argumento (`child`) é qualquer [elemento filho React renderizável](/docs/react-component.html#render), como um elemento, string ou fragmento. O segundo argumento (`container`) é um elemento DOM.
14
14
15
-
## Usage {#usage}
15
+
## Utilização {#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, quando retornamos um elemento pelo método render de um componente ele é montado dentro do DOM como um filho do nó pai mais próximo:
18
18
19
19
```js{4,6}
20
20
render() {
21
-
// React mounts a new div and renders the children into it
21
+
// React monta uma nova div e renderiza o filho dentro dela
22
22
return (
23
23
<div>
24
24
{this.props.children}
@@ -27,34 +27,34 @@ render() {
27
27
}
28
28
```
29
29
30
-
However, sometimes it's useful to insert a child into a different location in the DOM:
30
+
Entretanto, em algumas situação é útil inserir um elemento filho em um local diferente no DOM:
31
31
32
32
```js{6}
33
33
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.
34
+
// React *não* cria uma nova div. Ele renderiza os filhos dentro do `domNode`.
35
+
// `domNode` é qualquer nó DOM válido, independente da sua localização no DOM.
36
36
return ReactDOM.createPortal(
37
37
this.props.children,
38
38
domNode
39
39
);
40
40
}
41
41
```
42
+
Um caso típico do uso de portals é quando um componente pai tem o estilo `overflow: hidden` ou `z-index`, mas você precisa que o filho visualmente "saia" desse contêiner. Por exemplo, caixas de diálogo, hovercards e tooltips.
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
-
45
-
> Note:
44
+
> Nota:
46
45
>
47
-
> When working with portals, remember that [managing keyboard focus](/docs/accessibility.html#programmatically-managing-focus)becomes very important.
46
+
> Quando estiver trabalhando com portals, lembre-se que [tratar o evento focus](/docs/accessibility.html#programmatically-managing-focus)se torna muito importante.
48
47
>
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).
48
+
> No caso dos modals, assegure-se que todos possam interagir com eles seguindo as práticas descritas em[WAI-ARIA Modal Authoring Practices](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal).
50
49
51
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/yzMaBd)
50
+
[**Experimente no CodePen**](https://codepen.io/gaearon/pen/yzMaBd)
52
51
53
-
## Event Bubbling Through Portals {#event-bubbling-through-portals}
52
+
## Propagação de Eventos Através do Portals {#event-bubbling-through-portals}
54
53
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*.
54
+
Apesar de um portal poder estar em qualquer lugar na árvore DOM, seu comportamento é como o de qualquer outro elemento React filho. Funcionalidades como contexto funcionam da mesma forma independente se o filho é um portal, pois o portal ainda existe na *árvore React* independentemente da posição que esteja na *árvore DOM*.
56
55
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:
56
+
Isso inclui a propagação de eventos. Um evento disparado dentro de um portal será propagado para os elementos antecessores da *árvore React*, mesmo que estes não sejam antecessores na *árvore DOM*.
57
+
Considere a seguinte estrutura HTML:
58
58
59
59
```html
60
60
<html>
@@ -65,10 +65,10 @@ This includes event bubbling. An event fired from inside a portal will propagate
65
65
</html>
66
66
```
67
67
68
-
A `Parent` component in `#app-root`would be able to catch an uncaught, bubbling event from the sibling node`#modal-root`.
68
+
Um componente `Pai` em `#app-root`será capaz de capturar a propagação de um evento não tratado vindo do nó irmão`#modal-root`.
@@ -79,14 +79,14 @@ class Modal extends React.Component {
79
79
}
80
80
81
81
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.
82
+
// O elemento portal é inserido na árvore DOM depois que
83
+
// os componentes filhos de `Modal` são montados, o que significa que os filhos
84
+
// serão montados em um nó DOM separado. Se um componente
85
+
// filho precisa ser colocado na árvore DOM
86
+
// imediatamente quando é montado, por exemplo para medir um
87
+
// nó DOM ou usar 'autoFocus' em um descendente, adicione
88
+
// state ao Modal e renderize o filho apenas quando o Modal
89
+
// estiver inserido na árvore 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
+
// Isso é disparado quando o botão no filho é clicado,
114
+
// atualizando o state do componente Pai, mesmo que o filho
115
+
// não seja um descendente direto no DOM.
116
116
this.setState(state => ({
117
117
clicks: state.clicks + 1
118
118
}));
@@ -121,12 +121,12 @@ class Parent extends React.Component {
121
121
render() {
122
122
return (
123
123
<div onClick={this.handleClick}>
124
-
<p>Number of clicks: {this.state.clicks}</p>
124
+
<p>Número de cliques: {this.state.clicks}</p>
125
125
<p>
126
-
Open up the browser DevTools
127
-
to observe that the button
128
-
is not a child of the div
129
-
with the onClick handler.
126
+
Abra o DevTools do navegador
127
+
para observar que o botão
128
+
não é um filho da div
129
+
com o onClick.
130
130
</p>
131
131
<Modal>
132
132
<Child />
@@ -137,18 +137,18 @@ 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
+
// O evento de clique nesse botão irá propagar para o ascendente,
141
+
// porque o atributo 'onClick' não está definido
142
142
return (
143
143
<div className="modal">
144
-
<button>Click</button>
144
+
<button>Clicar</button>
145
145
</div>
146
146
);
147
147
}
148
148
149
149
ReactDOM.render(<Parent />, appRoot);
150
150
```
151
151
152
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBWpE)
152
+
[**Experimente no 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
+
Capturar um evento propagado a partir de um portal em um componente pai permite o desenvolvimento de abstrações mais flexíveis que não dependem diretamente de portals. Por exemplo, se você renderizar um componente `<Modal />`, o componente pai pode captura seus eventos independentemente se são implementados usando portals.
0 commit comments