material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Card] Card onExpandChange is called twice when clicking on CardHeader expand icon

Open jgreubel opened this issue 9 years ago • 1 comments

Problem description

Card.onExpandChange is called twice when clicking on the expand icon on the CardHeader.

Link to minimal working code that reproduces the issue

https://www.webpackbin.com/bins/-KoneVjXo4E69DDO7X--

import React from 'react';
import { Card, CardHeader } from 'material-ui';

const HelloWorld = () => (
  <Card onExpandChange={() => console.log('onExpandChange Called!')}>
    <CardHeader
      actAsExpander
      showExpandableButton
      />  
  </Card>
);

export default HelloWorld;

When clicking on the expandIcon on the CardHeader, you will see the 'onExpandChange Called!' console log appear twice.

Versions

image

Link to old issue that was closed even though the issue still exists: #2081

P.S. Someone did mention a potential solution in the linked issue above:

tbescherer commented on Aug 25, 2016 • edited

It looks to me like this issue still exists. See https://github.com/callemall/material-ui/blob/v0.15.4/src/Card/Card.js#L106-L114 In the event that showExpandableButton and and actAsExpander are true, the child (CardHeader) will receive handleExpanding as the prop touchTapEvent AND CardExpandable will receive handleExpanding as the prop onExpandChange. Both of these will be triggered by a click on the CardExpandable component. I think this issue could be solved by adding event.stopPropagation() to the handleExpanding function.

jgreubel avatar Jul 11 '17 22:07 jgreubel

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it. Still, we will accept PR fixes until v1-beta takes over the master branch.

oliviertassinari avatar Aug 04 '17 07:08 oliviertassinari