Fix DataTable expander button triggering unwanted row-click events #7799
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
DataTable 展开按钮触发了不必要的行点击事件
DataTable expander button triggers unwanted row-click events
问题描述
Description
当点击 DataTable 行中的展开按钮时,点击事件会冒泡并触发行点击事件处理器,导致意外行为。
When clicking the expander button in a DataTable row, the click event bubbles up and triggers the row-click event handler, causing unintended behavior.
重现步骤
Steps to Reproduce
expander
列)Create a DataTable with expandable rows (using
expander
column)Add a row-click event handler to the DataTable
Click on the expander button to expand/collapse a row
Observe that the row-click event is also triggered
期望行为
Expected Behavior
Clicking the expander button should only trigger the expand/collapse functionality
Row-click events should NOT be triggered when clicking the expander button
Only direct clicks on the row (outside of action buttons) should trigger row-click events
实际行为
Actual Behavior
Clicking the expander button triggers both the expand/collapse action AND the row-click event
This causes unwanted side effects and conflicts with intended user interactions
根本原因
Root Cause
展开按钮的点击事件冒泡到父级
<td>
元素,该元素有处理行点击的@click="onClick"
事件处理器。The expander button's click event bubbles up to the parent
<td>
element, which has a@click="onClick"
event handler that processes row clicks.解决方案
Solution
为展开按钮的点击处理器添加
.stop
事件修饰符以阻止事件冒泡:Add the
.stop
event modifier to the expander button's click handler to prevent event bubbling:环境信息
Environment
代码位置
Code Location
文件 / File:
packages/primevue/src/datatable/BodyCell.vue
行数 / Line: ~71 (expander button template)