From c2a5378b9d2dded8fe253429f233cbafffc1845f Mon Sep 17 00:00:00 2001 From: KumJungMin Date: Wed, 9 Oct 2024 13:34:53 +0900 Subject: [PATCH 1/3] fix: prevent row-click trigger when inner button clicked --- packages/primevue/src/datatable/DataTable.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/primevue/src/datatable/DataTable.vue b/packages/primevue/src/datatable/DataTable.vue index d592506ea3..c42557b87d 100755 --- a/packages/primevue/src/datatable/DataTable.vue +++ b/packages/primevue/src/datatable/DataTable.vue @@ -734,7 +734,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.currentTarget)) { + if (isClickable(event.target)) { return; } @@ -811,7 +811,7 @@ export default { this.rowTouched = false; if (focusedItem) { - if (event.currentTarget?.getAttribute('data-pc-section') === 'rowtoggleicon') return; + if (event.target?.getAttribute('data-pc-section') === 'rowtoggleicon') return; const targetRow = event.currentTarget?.closest('tr[data-p-selectable-row="true"]'); From f71e839ac9835e09b894724383b29448898f02ab Mon Sep 17 00:00:00 2001 From: KumJungMin Date: Wed, 9 Oct 2024 14:23:20 +0900 Subject: [PATCH 2/3] test: add test to ensure row is not selected when inner button is clicked --- .../primevue/src/datatable/DataTable.spec.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/primevue/src/datatable/DataTable.spec.js b/packages/primevue/src/datatable/DataTable.spec.js index 4e6f15c045..8c0636419c 100644 --- a/packages/primevue/src/datatable/DataTable.spec.js +++ b/packages/primevue/src/datatable/DataTable.spec.js @@ -582,6 +582,48 @@ describe('DataTable.vue', () => { expect(wrapper.emitted()['row-select'][1][0].index).toBe(1); }); + it('should not select row when inner button is clicked', async () => { + wrapper = mount(DataTable, { + global: { + plugins: [PrimeVue], + components: { + Column, + Button + } + }, + props: { + value: smallData, + expandedRows: [], + paginatorTemplate: 'CurrentPageReport FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown', + rowsPerPageOptions: [5, 6, 7], + currentPageReportTemplate: 'Showing {first} to {last} of {totalRecords}' + }, + slots: { + default: ` + + + + + + ` + }, + methods: { + buttonClicked() { + console.log('button clicked'); + } + } + }); + + const button = wrapper.find('button'); + expect(button.exists()).toBe(true); + + await button.trigger('click'); + + expect(wrapper.emitted()['row-click']).toBeUndefined(); + }); + it('should select all rows', async () => { wrapper = mount(DataTable, { global: { From 2e72c8b5f45f550b643a64fb14c68a9ec43d7766 Mon Sep 17 00:00:00 2001 From: KumJungMin Date: Wed, 9 Oct 2024 14:34:31 +0900 Subject: [PATCH 3/3] style: apply eslint --- packages/primevue/src/datatable/DataTable.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/primevue/src/datatable/DataTable.spec.js b/packages/primevue/src/datatable/DataTable.spec.js index 8c0636419c..1dd5401108 100644 --- a/packages/primevue/src/datatable/DataTable.spec.js +++ b/packages/primevue/src/datatable/DataTable.spec.js @@ -617,6 +617,7 @@ describe('DataTable.vue', () => { }); const button = wrapper.find('button'); + expect(button.exists()).toBe(true); await button.trigger('click');