diff --git a/docs/pages/kcard.vue b/docs/pages/kcard.vue index 0e1dcef4e..b49ff0012 100644 --- a/docs/pages/kcard.vue +++ b/docs/pages/kcard.vue @@ -48,7 +48,7 @@ { text: 'KCard and KCardGrid', href: '#k-card-and-grid' }, { text: 'Title', href: '#title' }, { text: 'Accessibility', href: '#a11y' }, - { text: 'Navigation', href: '#navigation' }, + { text: 'Click event and navigation', href: '#click-navigation' }, { text: 'Layout', href: '#layout' }, { text: 'Responsiveness', href: '#responsiveness' }, { text: 'Content slots', href: '#content-slots' }, @@ -214,28 +214,56 @@

Always test semantics, accessibility, and right-to-left of the final cards.

- Navigation - + Click event and navigation +

-

KCard's entire area is clickable, navigating to a target provided via the to prop as a regular Vue route object.

- - - - - - - - - - - +

KCard's entire area is clickable.

+ +

You can use the to prop to navigate to a URL when the card is clicked.

+ + + + + + + + +

Listen to the click event to perform a custom action (whether or not the to prop is used).

+ + + + + + + + + + + export default { + methods() { + onClick() { + console.log('Card clicked'); + } + }, + }; + + + +

Note that long clicks are ignored to allow for text selection.

See to learn how to disable card navigation in favor of a custom handler when elements like buttons are rendered within a card.

@@ -563,7 +591,7 @@ -

When adding interactive elements like buttons to a card via slots, apply the .stop event modifier to their @click event to prevent the card from navigating away when clicked.

+

When adding interactive elements like buttons to a card via slots, apply the .stop event modifier to their @click event to prevent the card .

This applies to all slot content, but considering accessibility is especially important with interactive elements. For instance, ariaLabel is applied to the bookmark icon button in the following example so that screenreaders can communicate its purpose. In production, more work would be needed to indicate the bookmark's toggled state. Always assess on a case-by-case basis.

diff --git a/lib/cards/KCard.vue b/lib/cards/KCard.vue index 7a7e93084..340250c8e 100644 --- a/lib/cards/KCard.vue +++ b/lib/cards/KCard.vue @@ -36,12 +36,13 @@ selecting card's content in `onClick`) --> + + + + +