Skip to content

Commit 9b5862c

Browse files
authored
Merge pull request #647 from reactjs/tr/createPortal
Translate "createPortal"
2 parents 774042f + c5fbe33 commit 9b5862c

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

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

+33-33
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` を使うことで、DOM 上の別の場所に子要素をレンダーすることができます。
88

99

1010
```js
@@ -20,11 +20,11 @@ title: createPortal
2020
2121
---
2222
23-
## Reference {/*reference*/}
23+
## リファレンス {/*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+
ポータルを作成するには、`createPortal` を呼び出し、JSX とそれをレンダーする先の DOM ノードを渡します。
2828
2929
```js
3030
import { createPortal } from 'react-dom';
@@ -40,35 +40,35 @@ import { createPortal } from 'react-dom';
4040
</div>
4141
```
4242
43-
[See more examples below.](#usage)
43+
[さらに例を読む](#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+
ポータルは DOM ノードの物理的な配置だけを変更します。それ以外のすべての点で、ポータルにレンダーする JSX は、レンダー元の React コンポーネントの子ノードとして機能します。例えば、子は親ツリーが提供するコンテクストにアクセスでき、イベントは React ツリーに従って子から親へとバブルアップします。
4646
47-
#### Parameters {/*parameters*/}
47+
#### 引数 {/*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`: React でレンダーできるあらゆるもの、例えば JSX`<div />` `<SomeComponent />` など)、[フラグメント](/reference/react/Fragment) (`<>...</>`)、文字列や数値、またはこれらの配列。
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`: `document.getElementById()` によって返されるような DOM ノード。ノードはすでに存在している必要があります。更新中に異なる DOM ノードを渡すと、ポータルの内容が再作成されます。
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+
* **省略可能** `key`: ポータルの [key](/learn/rendering-lists/#keeping-list-items-in-order-with-key) として使用される一意の文字列または数値。
5454
55-
#### Returns {/*returns*/}
55+
#### 返り値 {/*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` は、JSX に含めたり React コンポーネントから返したりすることができる React ノードを返します。React がレンダー出力内でそのようなものを検出すると、渡された `children` を渡された `domNode` の内部に配置します。
5858
59-
#### Caveats {/*caveats*/}
59+
#### 注意点 {/*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+
* ポータルからのイベントは、DOM ツリーではなく React ツリーに沿って伝播します。例えば、ポータル内部でクリックが起き、ポータルが `<div onClick>` でラップされている場合、その `onClick` ハンドラが発火します。これが問題を引き起こす場合、ポータル内部からイベント伝播を停止するか、ポータル自体を React ツリー内で上に移動します。
6262
6363
---
6464
65-
## Usage {/*usage*/}
65+
## 使用法 {/*usage*/}
6666
67-
### Rendering to a different part of the DOM {/*rendering-to-a-different-part-of-the-dom*/}
67+
### 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+
*ポータル*により、コンポーネントが子の一部を DOM 内の別の場所にレンダーできるようになります。これにより、コンポーネントの出力の一部を、自身の含まれているコンテナの外に「脱出」させることが可能です。例えばコンポーネントから、ページの他の要素の上部や外部に表示されるモーダルダイアログやツールチップを表示することができます。
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+
ポータルを作成するには、<CodeStep step={1}>何らかの JSX</CodeStep> <CodeStep step={2}>行き先の DOM ノード</CodeStep> を渡した `createPortal` の呼び出し結果をレンダーします。
7272
7373
```js [[1, 8, "<p>This child is placed in the document body.</p>"], [2, 9, "document.body"]]
7474
import { createPortal } from 'react-dom';
@@ -86,9 +86,9 @@ function MyComponent() {
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 は、<CodeStep step={1}>渡した JSX</CodeStep> に対応する DOM ノードを <CodeStep step={2}>渡した DOM ノード</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+
ポータルがなければ 2 つ目の `<p>` は親の `<div>` の内部に配置されますが、ポータルはそれを [`document.body`](https://developer.mozilla.org/en-US/docs/Web/API/Document/body) に「テレポート」させます。
9292
9393
<Sandpack>
9494
@@ -110,7 +110,7 @@ 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+
2 つ目の段落が親の `<div>` の境界線の外側に表示されていることに注意してください。開発者ツールで DOM 構造を調べると、2 つ目の `<p>` が直接 `<body>` に配置されていることがわかります。
114114
115115
```html {4-6,9}
116116
<body>
@@ -125,15 +125,15 @@ Notice how the second paragraph visually appears outside the parent `<div>` with
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+
ポータルは DOM ノードの物理的な配置だけを変更します。それ以外のすべての点で、ポータルにレンダーする JSX は、レンダー元の React コンポーネントの子ノードとして機能します。例えば、子は親ツリーが提供するコンテクストにアクセスでき、イベントは React ツリーに従って子から親へとバブルアップします。
129129
130130
---
131131
132-
### Rendering a modal dialog with a portal {/*rendering-a-modal-dialog-with-a-portal*/}
132+
### ポータルを使ったモーダルダイアログのレンダー {/*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+
ポータルを使用して、ページ内の他の要素上に浮かんで表示されるモーダルダイアログを作成することができます。ダイアログを呼び出すコンポーネントが `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+
この例では、2 つのコンテナはモーダルダイアログの表示を妨げるようなスタイルを持っていますが、ポータルを使ってレンダーされた方は影響を受けていません。DOM 内ではモーダルは親 JSX 要素の中に含まれていないからです。
137137
138138
<Sandpack>
139139
@@ -238,17 +238,17 @@ 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+
ポータルを使用する際には、アプリを正しくアクセシブルにすることが重要です。例えば、ユーザが自然にポータルの内または外へフォーカスを移動できるよう、キーボードフォーカスを管理する必要があるかもしれません。
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+
モーダルを作成する際には、[WAI-ARIA のモーダル作成実践ガイド](https://www.w3.org/WAI/ARIA/apg/#dialog_modal)に従ってください。コミュニティパッケージを使用する場合は、それがアクセシブルであり、このガイドラインに従っていることを確認してください。
244244
245245
</Pitfall>
246246
247247
---
248248
249-
### Rendering React components into non-React server markup {/*rendering-react-components-into-non-react-server-markup*/}
249+
### React のサーバマークアップに 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+
React で構築されていない静的ページあるいはサーバレンダーされたページの一部に React ルートがある場合にも、ポータルは有用です。例えば、ページが Rails のようなサーバフレームワークで構築されている場合、サイドバーなどの静的な部位の内部に操作可能なエリアを作成することができます。[別々の React ルート](/reference/react-dom/client/createRoot#rendering-a-page-partially-built-with-react)を複数用いる場合と異なり、ポータルを使うとアプリを単一の React ツリーとして扱うことができ、部位ごとに DOM 内の異なる場所にレンダーさせつつも state を共有可能です。
252252
253253
<Sandpack>
254254
@@ -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+
### React DOM ノードに 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+
React 外で管理されている DOM ノードの内容を管理するためにポータルを使用することもできます。例えば、非 React のマップウィジェットと統合していて、ポップアップ内に React のコンテンツをレンダーしたいとします。これを行うには、レンダーする DOM ノードを格納するための `popupContainer` state 変数を宣言します。
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+
サードパーティのウィジェットを作成する際に、ウィジェットが返す DOM ノードを格納しておき、その内部にレンダーが行えるようにします。
354354
355355
```js {5-6}
356356
useEffect(() => {
@@ -363,7 +363,7 @@ useEffect(() => {
363363
}, []);
364364
```
365365
366-
This lets you use `createPortal` to render React content into `popupContainer` once it becomes available:
366+
このようにしておけば、`popupContainer` が利用可能になったところでその中に `createPortal` を使って React コンテンツをレンダーすることができるようになります。
367367
368368
```js {3-6}
369369
return (
@@ -376,7 +376,7 @@ return (
376376
);
377377
```
378378
379-
Here is a complete example you can play with:
379+
以下に、試してみることができる完全な例を示します。
380380
381381
<Sandpack>
382382

0 commit comments

Comments
 (0)