marekrozmus / react-swipeable-list

Swipeable list component for React supporting several behaviours (e.g. iOS)
https://marekrozmus.github.io/react-swipeable-list/
MIT License
114 stars 20 forks source link

SwipeableListItem onClick action triggered, when element swiped #35

Closed canberkakartuna closed 1 year ago

canberkakartuna commented 1 year ago

Swipe action triggers onClick event

Steps to reproduce the behavior:

  1. Swipe trailing actions
  2. 'SwipeableListItem' element onClick triggered

Expected behavior: onClick should work apart from swipe actions

Desktop (please complete the following information):

Code:

    const trailingActions = (onDelete) => (
      <TrailingActions>
        <SwipeAction onClick={onDelete} destructive={true}>
          <ActionContent style={{ backgroundColor: 'red' }}>
            <DeleteOutlined style={{ fontSize: 18 }} />
          </ActionContent>
        </SwipeAction>
      </TrailingActions>
    );

    <SwipeableList fullSwipe={false} type={ListType.IOS}>
      {!!items.length &&
        items?.map((item) => (
          <SwipeableListItem
            leadingActions={null}
            trailingActions={trailingActions(() => removeItem(item))}
            key={item?.id}
            onClick={(e) => {
              console.log('click'); // THIS CODE SHOULD NOT WORK ON SWIPE BUT IT DOES.
            }}
          >
            <Card style={{ borderRadius: 0, width: '100%' }}>
              <Row>
                <Col span={1}>1</Col>
                <Col span={20}>
                  <p>{item?.name}</p>
                </Col>
                <Col span={3}>
                  <p>{item?.totalCost}</p>
                </Col>
              </Row>
            </Card>
          </SwipeableListItem>
        ))}
    </SwipeableList>
marekrozmus commented 1 year ago

@all-contributors please add @canberkakartuna for bug

allcontributors[bot] commented 1 year ago

@marekrozmus

I've put up a pull request to add @canberkakartuna! :tada:

marekrozmus commented 1 year ago

@canberkakartuna Fixed in 1.9.1 - thanks :)

canberkakartuna commented 1 year ago

Thanks @marekrozmus :)