0

I have a Card Fluent UI component defined like this

    <Card className={mergeClasses(styles.card, className)} onClick={() => onClicked(id)} >
        <CardContent {...props} />
        <CardBottom {...props} onSave={() => onSaved(id)} />
    </Card >

The onClick() method needs to be defined at the Card component level, but I don't want to run this onClick event when clicking on the CardBottom area since that contains other button that is executing its own event (onSaved).

Is there a way I can skip running the onClick event when the click happens in the CardBottom component?

1 Answer 1

1

You can stop the propagation of the event in CardBottom component's event handler.

Change:

<CardBottom {...props} onSave={() => onSaved(id)} />

To:

<CardBottom
  {...props}
  onSave={(event) => {
    event.stopPropagation(); //stop the propagation
    onSaved(id);
  }}
/>
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm! Marking as valid answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.