Skip to content

Commit

Permalink
Merge pull request #6333 from KumJungMin/fix/issue-6323
Browse files Browse the repository at this point in the history
fix: handle click event using event.currentTarget in DataTable
  • Loading branch information
tugcekucukoglu authored Sep 10, 2024
2 parents 5f61a7d + a3a4534 commit 08340e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions packages/primevue/src/datatable/DataTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ describe('DataTable.vue', () => {
await wrapper.setProps({ selection: null, selectionMode: 'single' });

await wrapper.vm.onRowClick({
originalEvent: { target: wrapper.findAll('tr.p-datatable-selectable-row')[0].element },
originalEvent: { currentTarget: wrapper.findAll('tr.p-datatable-selectable-row')[0].element },
data: smallData[0],
index: 0
});
Expand All @@ -472,13 +472,13 @@ describe('DataTable.vue', () => {
await wrapper.setProps({ selection: null, selectionMode: 'multiple' });

await wrapper.vm.onRowClick({
originalEvent: { shiftKey: true, target: wrapper.findAll('tr.p-datatable-selectable-row')[0].element },
originalEvent: { shiftKey: true, currentTarget: wrapper.findAll('tr.p-datatable-selectable-row')[0].element },
data: smallData[0],
index: 0
});

await wrapper.vm.onRowClick({
originalEvent: { shiftKey: true, target: wrapper.findAll('tr.p-datatable-selectable-row')[1].element },
originalEvent: { shiftKey: true, currentTarget: wrapper.findAll('tr.p-datatable-selectable-row')[1].element },
data: smallData[1],
index: 1
});
Expand All @@ -492,13 +492,13 @@ describe('DataTable.vue', () => {
await wrapper.setProps({ selection: null, selectionMode: 'multiple', metaKeySelection: false });

await wrapper.vm.onRowClick({
originalEvent: { target: wrapper.findAll('.p-datatable-selectable-row')[0].element },
originalEvent: { currentTarget: wrapper.findAll('.p-datatable-selectable-row')[0].element },
data: smallData[0],
index: 0
});

await wrapper.vm.onRowClick({
originalEvent: { target: wrapper.findAll('tr.p-datatable-selectable-row')[1].element },
originalEvent: { currentTarget: wrapper.findAll('tr.p-datatable-selectable-row')[1].element },
data: smallData[1],
index: 1
});
Expand Down
32 changes: 16 additions & 16 deletions packages/primevue/src/datatable/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -280,29 +280,29 @@
</template>

<script>
import { FilterMatchMode, FilterOperator, FilterService } from '@primevue/core/api';
import { HelperSet, UniqueComponentId, getVNodeProp } from '@primevue/core/utils';
import {
getAttribute,
addClass,
addStyle,
clearSelection,
findSingle,
isClickable,
exportCSV,
find,
findSingle,
focus,
exportCSV,
getOffset,
addStyle,
getAttribute,
getHiddenElementOuterHeight,
getHiddenElementOuterWidth,
getIndex,
getOffset,
getOuterHeight,
getOuterWidth,
getHiddenElementOuterWidth,
getHiddenElementOuterHeight,
getWindowScrollTop,
getOuterHeight,
isClickable,
removeClass,
addClass,
setAttribute
} from '@primeuix/utils/dom';
import { resolveFieldData, localeComparator, sort, findIndexInList, equals, reorderArray, isNotEmpty, isEmpty } from '@primeuix/utils/object';
import { equals, findIndexInList, isEmpty, isNotEmpty, localeComparator, reorderArray, resolveFieldData, sort } from '@primeuix/utils/object';
import { FilterMatchMode, FilterOperator, FilterService } from '@primevue/core/api';
import { HelperSet, UniqueComponentId, getVNodeProp } from '@primevue/core/utils';
import ArrowDownIcon from '@primevue/icons/arrowdown';
import ArrowUpIcon from '@primevue/icons/arrowup';
import SpinnerIcon from '@primevue/icons/spinner';
Expand Down Expand Up @@ -736,7 +736,7 @@ export default {
const body = this.$refs.bodyRef && this.$refs.bodyRef.$el;
const focusedItem = findSingle(body, 'tr[data-p-selectable-row="true"][tabindex="0"]');
if (isClickable(event.target)) {
if (isClickable(event.currentTarget)) {
return;
}
Expand Down Expand Up @@ -813,9 +813,9 @@ export default {
this.rowTouched = false;
if (focusedItem) {
if (event.target?.getAttribute('data-pc-section') === 'rowtoggleicon' || event.target?.parentElement?.getAttribute('data-pc-section') === 'rowtoggleicon') return;
if (event.currentTarget?.getAttribute('data-pc-section') === 'rowtoggleicon') return;
const targetRow = event.target?.closest('tr[data-p-selectable-row="true"]');
const targetRow = event.currentTarget?.closest('tr[data-p-selectable-row="true"]');
focusedItem.tabIndex = '-1';
targetRow.tabIndex = '0';
Expand Down

0 comments on commit 08340e2

Please sign in to comment.