braze-inc / braze-web-sdk

Public repo for the Braze Web SDK
https://www.braze.com
Other
70 stars 25 forks source link

Question: Content Cards, is there onClose listener available ? #124

Closed yevhen-logosha closed 1 year ago

yevhen-logosha commented 1 year ago

Braze Web SDK Version

4.0.5

Integration Method

NPM

Browser

Chrome

Steps To Reproduce

Hi guys. Sorry don't know where else to ask you this. We are integrating Content Cards. All well and good, only when it came to displaying an unread cards count we hit a roadblock..

I can get a count no problem with below code

      requestContentCardsRefresh(() => {
        const unreadCount = getCachedContentCards().getUnviewedCardCount();

        updatesCardCountVar(unreadCount);
      });

I use toggleContentCards() method to show/hide drawer. I can resent unread count if user clicks same button to hide drawer.

But, if they click X button within actual drawer, I have no way(or at least I can't find) to capture it and reset unread count

Screenshot 2022-07-15 at 10 48 32

Expected Behavior

We as devs are able to listen to something like onClose method to be able to reset count if user closes the drawer by the means of clicking the X button within the drawer.

Actual Incorrect Behavior

Unable to reset unread cards count if user dismisses the drawer by clicking the X

Verbose Logs

No response

Additional Information

No response

spvismaya commented 1 year ago

Hi @yevhen-logosha! We do not support such a listener method, but you could try adding a custom event listener to the close button by finding it in HTML when displayed, as described below:

const closeButton = document.querySelector(".ab-feed > .ab-feed-buttons-wrapper > .ab-close-button");
closeButton.addEventListener('click', customEventListener);

Please feel free to reopen this issue if this solution does not work for you. Thank you!