简体   繁体   中英

React MUI Chip onDelete access to stopPropagation method

I have a Chip like:

  const onDelete = (e) => {
    e.stopPropagation();
    // e.nativeEvent.stopPropagation();
  };
  return (
    <Chip
      label={name}
      sx={sx}
      component={NavLink}
      to={to}
      clickable={true}
      onDelete={onDelete}
    />);

None of the calls stopPropagation() worked, because they are undefined on the Event sent by MUI to the onDelete callback.

Is there anyway I can prevent this chip to follow the Link in to attribute if user clicked to Delete?

The stopPropagation() prevents further propagation of the current event but redirecting to links are still processed. If you want to stop those behaviors, you can use preventDefault() method :

const onDelete = (e) => {
    e.preventDefault();
    // e.nativeEvent.stopPropagation();
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM