diff --git a/changelog.md b/changelog.md index b05f1ff39..8cd22c371 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ 2024-11-01 - d9cb67f8abf3c1128203f14bce687c8b5b4075a6 - Remove unnecessary separator between consecutive page numbers in OXD pagination +2024-11-01 - 5f4c5306a8ec4b497cb824fa673e50ac0162af4b - ProfilePicture.vue, ProfilePic.vue, profile-pic.spec.ts- add onclick event to prevent default behaviour of link and execute a function fix issue + +2024-11-01 - 891d531ac92cf7e3bcced8c018a7f7fd2efe6bb9 - Icons.ts - add external link icon + 2024-10-28 - e5840791366e3abbf3cb6b57f77ede4a8842fb79 - Icon/icons.ts - Add oxd-date-input, oxd-attachment-input,oxd-checkbox-input, oxd-checkbox-group-input, oxd-select-input, oxd-file-input, oxd-radio-input, oxd-radio-group-input, oxd-switch-input, oxd-time-input, oxd-text-input, oxd-password-input, oxd-circle-plus, oxd-textbox, oxd-text, oxd-divider, oxd-grid, oxd-grid-item, oxd-subform, oxd-masterdata, oxd-employee-autocomplete, oxd-status, oxd-required to OXD Icons 2024-10-26 - a7f234223a3a34e55a77e3c216733c9f01e5e3c9 - directives/focus-first-element/index.ts - Update the focus first directive to wait for animations to stop diff --git a/components/src/core/components/CardTable/Cell/LinkWithPill.vue b/components/src/core/components/CardTable/Cell/LinkWithPill.vue index 5423c2bb4..ad68800a5 100644 --- a/components/src/core/components/CardTable/Cell/LinkWithPill.vue +++ b/components/src/core/components/CardTable/Cell/LinkWithPill.vue @@ -6,7 +6,12 @@ @@ -52,6 +53,14 @@ export default defineComponent({ type: Boolean, default: false, }, + header: { + type: Object, + default: () => ({}), + }, + rowItem: { + type: Object, + default: () => ({}), + }, }, setup(props) { const imgSrc = ref(null); @@ -87,6 +96,14 @@ export default defineComponent({ const isLoading = computed(() => props.loading || imgLoading.value); + const handleLinkClick = (event: MouseEvent) => { + const cellConfig = props.header?.cellConfig; + if (cellConfig && typeof cellConfig?.onClick === 'function') { + event.preventDefault(); + props.header?.cellConfig.onClick(props.rowItem, event); + } + }; + watchEffect(async () => { imgSrc.value = await loadImage(props.item as string); }); @@ -94,6 +111,7 @@ export default defineComponent({ return { isLoading, profilePicture, + handleLinkClick, }; }, }); diff --git a/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts b/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts index 34e59f7c4..10dc30cab 100644 --- a/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts +++ b/components/src/core/components/CardTable/Cell/__tests__/link-with-pill.spec.ts @@ -109,4 +109,54 @@ describe('CardTable > Cell > LinkWithPill.vue', () => { .trim(), ).toEqual('external'); }); + + it('should trigger handleLinkClick on link click', async () => { + const mockOnClick = jest.fn(); + const rowItem = { + url1: 'https://orangehrm.com', + tag: 'external', + }; + + const wrapper = mount(LinkWithPill, { + global: GLOBAL, + props: { + item: 'This is a link', + target: '_parent', + link: 'url1', + rowItem: rowItem, + header: { + cellConfig: { + onClick: mockOnClick, + }, + }, + }, + }); + + const link = wrapper.find('a'); + await link.trigger('click'); + + expect(mockOnClick).toHaveBeenCalledWith(rowItem, expect.any(MouseEvent)); + }); + + it('should not prevent default behavior if no onClick handler is present', async () => { + const wrapper = mount(LinkWithPill, { + global: GLOBAL, + props: { + item: 'This is a link', + target: '_blank', + link: 'url1', + rowItem: { + url1: 'https://orangehrm.com', + tag: 'external', + }, + }, + }); + + const link = wrapper.find('a'); + const event = {preventDefault: jest.fn()}; + + await link.trigger('click', event); + + expect(event.preventDefault).not.toHaveBeenCalled(); + }); }); diff --git a/components/src/core/components/Icon/icons.ts b/components/src/core/components/Icon/icons.ts index e63bd9d22..ea9c430ae 100644 --- a/components/src/core/components/Icon/icons.ts +++ b/components/src/core/components/Icon/icons.ts @@ -2117,6 +2117,11 @@ export const oxdRequired: icon = { `, }; +export const oxdExternalLink: icon = { + name: 'oxd-external-link', + value: ``, +}; + const icons: Icons = { 'oxd-likes': oxdLikes, 'oxd-birthday': oxdBirthday, @@ -2350,6 +2355,7 @@ const icons: Icons = { 'oxd-employee-autocomplete': oxdEmployeeAutocomplete, 'oxd-status': oxdStatus, 'oxd-required': oxdRequired, + 'oxd-external-link': oxdExternalLink, }; export default icons; diff --git a/components/src/core/components/ProfilePic/ProfilePic.vue b/components/src/core/components/ProfilePic/ProfilePic.vue index bfa90154e..948c52c26 100644 --- a/components/src/core/components/ProfilePic/ProfilePic.vue +++ b/components/src/core/components/ProfilePic/ProfilePic.vue @@ -1,7 +1,12 @@