Skip to content

Commit

Permalink
feat(kcatalog): emit on card click (#1608)
Browse files Browse the repository at this point in the history
Add an event emission for when a `KCatalogItem` is clicked.
  • Loading branch information
kaiarrowood authored Aug 2, 2023
1 parent dd0f68b commit 8cbe88c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/components/catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ fetcher(payload) {

## Events

### @card:click

Emitted when a `KCatalogItem` is clicked, the payload is the clicked item's object.

### CTA Clicks

- `@kcatalog-empty-state-cta-clicked` - If using a CTA button in the empty state, this event is fired when clicked.
Expand Down
18 changes: 18 additions & 0 deletions src/components/KCatalog/KCatalog.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ describe('KCatalog', () => {
.should('have.callCount', 3) // fetcher's 3rd call
.should('returned', { data: [{ query: '' }], total: 1 })
})

it('emits an event when card is clicked', () => {
mount(KCatalog, {
props: {
testMode: 'true',
cacheIdentifier: 'general-props-long',
fetcher: () => {
return { data: [longItem], total: 1 }
},
noTruncation: true,
},
})

cy.get('.k-card-catalog .catalog-item').first().click().then(() => {
// Check for emitted event
cy.wrap(Cypress.vueWrapper.emitted()).should('have.property', 'card:click')
})
})
})

describe('states', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/KCatalog/KCatalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
:item="(item as CatalogItem)"
:test-mode="!!testMode || undefined"
:truncate="!noTruncation"
@click="$emit('card:click', item)"
>
<template #cardTitle>
<slot
Expand Down Expand Up @@ -435,6 +436,7 @@ const props = defineProps({
})
const emit = defineEmits<{
(e: 'card:click', item: CatalogItem): void
(e: 'kcatalog-error-cta-clicked'): void
(e: 'kcatalog-empty-state-cta-clicked'): void
(e: 'update:catalog-preferences', preferences: CatalogPreferences): void
Expand Down
4 changes: 2 additions & 2 deletions src/components/KCatalog/KCatalogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ defineProps({
},
})
const emit = defineEmits(['clicked'])
const emit = defineEmits(['card:click'])
const handleCardClick = (evt: Event, item: CatalogItem): void => {
emit('clicked', {
emit('card:click', {
evt,
item,
})
Expand Down

0 comments on commit 8cbe88c

Please sign in to comment.