Skip to content

Commit 020b62b

Browse files
committed
docs/portals 本文を試訳
1 parent b2676a3 commit 020b62b

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

content/docs/portals.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
22
id: portals
3-
title: Portals
3+
title: ポータル
44
permalink: docs/portals.html
55
---
66

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+
ポータルは、親コンポーネントの DOM 階層の外にある DOM ノードに対して、子コンポーネントを描画するための第一級の方法を提供します。
88

99
```js
1010
ReactDOM.createPortal(child, container)
1111
```
1212

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+
第1引数 (`child`) [React の子要素としてレンダー可能なもの](/docs/react-component.html#render)なら何でもよく、要素、文字列、フラグメントがそれに当たります。第2引数 (`container`) DOM 要素を指定します。
1414

15-
## Usage
15+
## 使い方
1616

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+
通常、コンポーネントの `render` メソッドから要素を返すと、最も近い親ノードの子要素として DOM にマウントされます。
1818

1919
```js{4,6}
2020
render() {
21-
// React mounts a new div and renders the children into it
21+
// React は新しい div 要素をマウントし、子をその中に描画します
2222
return (
2323
<div>
2424
{this.props.children}
@@ -27,34 +27,36 @@ render() {
2727
}
2828
```
2929

30-
However, sometimes it's useful to insert a child into a different location in the DOM:
30+
しかし、時に子要素を DOM 上の異なる場所に挿入したほうが便利なことがあります。
3131

3232
```js{6}
3333
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 は新しい div をつくり*ません*。小要素は `domNode` に対して描画されます。
35+
// `domNode` DOM ノードであれば何でも良く、 DOM 構造内のどこにあるかは問いません。
3636
return ReactDOM.createPortal(
3737
this.props.children,
3838
domNode
3939
);
4040
}
4141
```
4242

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.
43+
典型的なポータルのユースケースは、親要素が `overflow: hidden` `z-index` のスタイルを持っているものの、子要素がコンテナを「飛び出して」いるように見せたいようなものです。例えば、ダイアログ、ホバーカード、ツールチップがそれに当たります。
4444

45-
> Note:
45+
> 補足
4646
>
47-
> When working with portals, remember that [managing keyboard focus](/docs/accessibility.html#programmatically-managing-focus) becomes very important.
47+
> ポータルを利用する際は、[キーボードのフォーカスの管理](/docs/accessibility.html#programmatically-managing-focus)を行うことが重要になるので、忘れずに行ってください。
4848
>
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).
49+
> モーダルダイアログについては [WAI-ARIA モーダルの推奨実装方法](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal)に従い、誰もが利用できるという状態を確保してください。
5050
5151
[**Try it on CodePen**](https://codepen.io/gaearon/pen/yzMaBd)
5252

53-
## Event Bubbling Through Portals
53+
## ポータルを介したイベントのバブリング
5454

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*.
55+
ポータルは DOM ツリーのどこにでもありうるとはいえ、他の点では通常の React の子要素と同じように振る舞います。コンテクスト (context) のような機能は、たとえ子要素がポータルだろうと完全に同じように動きます。というのも、 **DOM ツリー**上の位置にかかわらず、ポータルは依然として **React のツリー**内にいるからです。
5656

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:
57+
これにはイベントのバブリングも含まれます。ポータルの内部から発行されたイベントは **React のツリー**内の祖先へと伝播します。たとえそれが **DOM ツリー** 上では祖先でなくともです。
58+
59+
次のような HTML 構造があったとして、
5860

5961
```html
6062
<html>
@@ -65,10 +67,10 @@ This includes event bubbling. An event fired from inside a portal will propagate
6567
</html>
6668
```
6769

68-
A `Parent` component in `#app-root` would be able to catch an uncaught, bubbling event from the sibling node `#modal-root`.
70+
`#app-root` 内にある `Parent` コンポーネントは、 `#modal-root` 内のコンポーネントから伝播したイベントがキャッチされなかった場合に、それをキャッチできます。
6971

7072
```js{28-31,42-49,53,61-63,70-71,74}
71-
// These two containers are siblings in the DOM
73+
// この 2 つのコンテナは DOM 上の兄弟要素とします
7274
const appRoot = document.getElementById('app-root');
7375
const modalRoot = document.getElementById('modal-root');
7476
@@ -151,4 +153,4 @@ ReactDOM.render(<Parent />, appRoot);
151153

152154
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBWpE)
153155

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.
156+
ポータルから浮上したイベントが親コンポーネントでキャッチできるということは、より柔軟な抽象を、本質的にポータルに依存しない形で開発できるということです。たとえば `<Modal />` コンポーネントをレンダーして、親コンポーネントがそこから来るイベントを捕捉するのは、`<Modal />` の実装がポータルを使っているかに関係なくできます。

0 commit comments

Comments
 (0)