Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle click event using event.currentTarget in DataTable #6333

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading