Skip to content

Commit

Permalink
Merge pull request #305 from vtex-apps/fix/autocomplete
Browse files Browse the repository at this point in the history
Fix autocomplete when clicking on the add to cart button
  • Loading branch information
thalytafabrine authored Apr 8, 2021
2 parents 47028ea + 9ccad23 commit 4ef78b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Autocomplete closing when clicking on the Add to Cart button.

## [2.71.1] - 2021-04-05

### Fixed
Expand Down
10 changes: 8 additions & 2 deletions react/ProductSummaryCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ function ProductSummaryCustom({

const productListDispatch = ProductListContext.useProductListDispatch()

const productListState = ProductListContext.useProductListState()
const autocompleteSummary =
productListState?.listName === 'autocomplete-result-list'

const inViewRef = useRef<HTMLDivElement | null>(null)
const onView = useCallback(() => {
productListDispatch?.({
Expand Down Expand Up @@ -130,7 +134,8 @@ function ProductSummaryCustom({
const linkProps = href
? {
to: href,
onClickCapture: actionOnClick,
onClick: autocompleteSummary ? actionOnClick : undefined,
onClickCapture: autocompleteSummary ? undefined : actionOnClick,
}
: {
page: 'store.product',
Expand All @@ -139,7 +144,8 @@ function ProductSummaryCustom({
id: product?.productId,
},
query,
onClickCapture: actionOnClick,
onClick: autocompleteSummary ? actionOnClick : undefined,
onClickCapture: autocompleteSummary ? undefined : actionOnClick,
}

return (
Expand Down
1 change: 1 addition & 0 deletions react/__mocks__/vtex.product-list-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { Fragment } from 'react'
export const useProductImpression = () => null
export const ProductListContext = {
useProductListDispatch: () => null,
useProductListState: () => null,
// eslint-disable-next-line react/display-name
ProductListProvider: ({ children }) => <Fragment>{children}</Fragment>,
}

0 comments on commit 4ef78b3

Please sign in to comment.