Skip to content

Commit 5ea2d6a

Browse files
authored
fix conflict
1 parent b2a1037 commit 5ea2d6a

1 file changed

Lines changed: 1 addition & 26 deletions

File tree

src/content/learn/responding-to-events.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -317,19 +317,11 @@ button { margin-right: 10px; }
317317

318318
</Sandpack>
319319

320-
<<<<<<< HEAD
321320
请注意,`App` 组件并不需要知道 `Toolbar` 将会对 `onPlayMovie``onUploadImage`**什么** 。上述示例是 `Toolbar` 的实现细节。其中,`Toolbar` 将它们作为 `onClick` 处理函数传递给了 `Button` 组件,其实还可以通过键盘快捷键来触发它们。根据应用程序特定的交互方式(如 `onPlayMovie`)来命名 prop ,可以让你灵活地更改以后使用它们的方式。
322321

323322
<Note>
324323

325324
确保为事件处理程序使用适当的 HTML 标签。例如,要处理点击事件,请使用 [`<button onClick={handleClick}>`](https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/button) 而不是 `<div onClick={handleClick}>`。使用真正的浏览器 `<button>` 启用内置的浏览器行为,如键盘导航。如果你不喜欢按钮的默认浏览器样式,并且想让它看起来更像一个链接或不同的 UI 元素,你可以使用 CSS 来实现。[了解有关编写无障碍标签的更多信息](https://developer.mozilla.org/zh-CN/docs/Learn/Accessibility/HTML)
326-
=======
327-
Notice how the `App` component does not need to know *what* `Toolbar` will do with `onPlayMovie` or `onUploadImage`. That's an implementation detail of the `Toolbar`. Here, `Toolbar` passes them down as `onClick` handlers to its `Button`s, but it could later also trigger them on a keyboard shortcut. Naming props after app-specific interactions like `onPlayMovie` gives you the flexibility to change how they're used later.
328-
329-
<Note>
330-
331-
Make sure that you use the appropriate HTML tags for your event handlers. For example, to handle clicks, use [`<button onClick={handleClick}>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) instead of `<div onClick={handleClick}>`. Using a real browser `<button>` enables built-in browser behaviors like keyboard navigation. If you don't like the default browser styling of a button and want to make it look more like a link or a different UI element, you can achieve it with CSS. [Learn more about writing accessible markup.](https://developer.mozilla.org/en-US/docs/Learn/Accessibility/HTML)
332-
>>>>>>> abe931a8cb3aee3e8b15ef7e187214789164162a
333325

334326
</Note>
335327

@@ -424,21 +416,12 @@ button { margin: 5px; }
424416

425417
当你点击按钮时:
426418

427-
<<<<<<< HEAD
428419
1. React 调用了传递给 `<button>``onClick` 处理函数。
429420
2. 定义在 `Button` 中的处理函数执行了如下操作:
430421
* 调用 `e.stopPropagation()`,阻止事件进一步冒泡。
431422
* 调用 `onClick` 函数,它是从 `Toolbar` 组件传递过来的 prop。
432423
3.`Toolbar` 组件中定义的函数,显示按钮对应的 alert。
433424
4. 由于传播被阻止,父级 `<div>``onClick` 处理函数不会执行。
434-
=======
435-
1. React calls the `onClick` handler passed to `<button>`.
436-
2. That handler, defined in `Button`, does the following:
437-
* Calls `e.stopPropagation()`, preventing the event from bubbling further.
438-
* Calls the `onClick` function, which is a prop passed from the `Toolbar` component.
439-
3. That function, defined in the `Toolbar` component, displays the button's own alert.
440-
4. Since the propagation was stopped, the parent `<div>`'s `onClick` handler does *not* run.
441-
>>>>>>> abe931a8cb3aee3e8b15ef7e187214789164162a
442425

443426
由于调用了 `e.stopPropagation()`,点击按钮现在将只显示一个 alert(来自 `<button>`),而并非两个(分别来自 `<button>` 和父级 toolbar `<div>`)。点击按钮与点击周围的 toolbar 不同,因此阻止传播对这个 UI 是有意义的。
444427

@@ -455,19 +438,11 @@ button { margin: 5px; }
455438
</div>
456439
```
457440

458-
<<<<<<< HEAD
459441
每个事件分三个阶段传播:
460442

461443
1. 它向下传播,调用所有的 `onClickCapture` 处理函数。
462-
2. 它执行被点击元素的 `onClick` 处理函数。
444+
2. 它执行被点击元素的 `onClick` 处理函数。
463445
3. 它向上传播,调用所有的 `onClick` 处理函数。
464-
=======
465-
Each event propagates in three phases:
466-
467-
1. It travels down, calling all `onClickCapture` handlers.
468-
2. It runs the clicked element's `onClick` handler.
469-
3. It travels upwards, calling all `onClick` handlers.
470-
>>>>>>> abe931a8cb3aee3e8b15ef7e187214789164162a
471446

472447
捕获事件对于路由或数据分析之类的代码很有用,但你可能不会在应用程序代码中使用它们。
473448

0 commit comments

Comments
 (0)