Skip to content

Commit

Permalink
Merge pull request #681 from vtex-apps/fix/filter-sidebar-close
Browse files Browse the repository at this point in the history
Fix: filter sidebar closes when clicking shipping option drawer
  • Loading branch information
ArthurFerrao authored Oct 30, 2024
2 parents f1b49ae + 6472c72 commit b64e30f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
7 changes: 6 additions & 1 deletion react/components/FilterNavigator/legacy/FilterSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { facetOptionShape } from '../../../constants/propTypes'
import useSelectedFilters from './hooks/useSelectedFilters'
import searchResult from './searchResult.css'
import QueryContext from '../../QueryContext'
import isShippingOptionsComponent from '../../../utils/isShippingOptionsComponent'

const FilterSidebar = ({ filters, preventRouteChange = false }) => {
const { navigate, setQuery } = useRuntime()
Expand Down Expand Up @@ -49,7 +50,11 @@ const FilterSidebar = ({ filters, preventRouteChange = false }) => {
}
}

const handleClose = () => {
const handleClose = e => {
if (isShippingOptionsComponent(e)) {
return
}

setOpen(false)
}

Expand Down
7 changes: 6 additions & 1 deletion react/components/FilterSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
filterCategoryDepartmentCollectionAndFT,
} from '../utils/queryAndMapUtils'
import { pushFilterManipulationPixelEvent } from '../utils/filterManipulationPixelEvents'
import isShippingOptionsComponent from '../utils/isShippingOptionsComponent'

const CSS_HANDLES = [
'filterPopupButton',
Expand Down Expand Up @@ -110,7 +111,11 @@ const FilterSidebar = ({
}
}

const handleClose = () => {
const handleClose = e => {
if (isShippingOptionsComponent(e)) {
return
}

setOpen(false)
}

Expand Down
23 changes: 23 additions & 0 deletions react/utils/isShippingOptionsComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const SHIPPING_OPTION_COMPONENT_DRAWER_CLASS =
'vtex-shipping-option-components-0-x-drawer'

const SHIPPING_OPTION_COMPONENT_OVERLAY_CLASS =
'vtex-shipping-option-components-0-x-overlay'

const isShippingOptionsComponent = e => {
if (!e.target) {
return false
}

const shippingOptionsDawerElement = e.target.closest(
`.${SHIPPING_OPTION_COMPONENT_DRAWER_CLASS}`
)

const isShippingOptionsOverlayElement = e.target.classList.contains(
SHIPPING_OPTION_COMPONENT_OVERLAY_CLASS
)

return shippingOptionsDawerElement || isShippingOptionsOverlayElement
}

export default isShippingOptionsComponent

0 comments on commit b64e30f

Please sign in to comment.