forked from crowetic/commerce
Fix navigation between cart and menu on mobile (#709)
* Fix navigation between cart and menu on mobile On mobile when the Sidebar menu is open and you want to switch to cart, it would toggle the sidebar and close it instead of switching view. * Adds missing openSidebar to useUI hook * Sets correct Sidebar view when adding a product If the last selected view on mobile was the menu, it was shown instead of the cart when adding a product. Co-authored-by: Bel <curciobelen@gmail.com>
This commit is contained in:
parent
0c5597fb93
commit
2c8d46ce90
@ -46,7 +46,7 @@ const UserNav: React.FC<{
|
||||
variant="naked"
|
||||
onClick={() => {
|
||||
setSidebarView('CART_VIEW')
|
||||
toggleSidebar()
|
||||
openSidebar()
|
||||
}}
|
||||
aria-label={`Cart items: ${itemsCount}`}
|
||||
>
|
||||
@ -88,8 +88,8 @@ const UserNav: React.FC<{
|
||||
aria-label="Menu"
|
||||
variant="naked"
|
||||
onClick={() => {
|
||||
setSidebarView('MOBILEMENU_VIEW')
|
||||
openSidebar()
|
||||
setSidebarView('MOBILE_MENU_VIEW')
|
||||
}}
|
||||
>
|
||||
<Menu />
|
||||
|
@ -17,7 +17,7 @@ interface ProductSidebarProps {
|
||||
|
||||
const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
||||
const addItem = useAddItem()
|
||||
const { openSidebar } = useUI()
|
||||
const { openSidebar, setSidebarView } = useUI()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [selectedOptions, setSelectedOptions] = useState<SelectedOptions>({})
|
||||
|
||||
@ -33,6 +33,7 @@ const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
||||
productId: String(product.id),
|
||||
variantId: String(variant ? variant.id : product.variants[0]?.id),
|
||||
})
|
||||
setSidebarView('CART_VIEW')
|
||||
openSidebar()
|
||||
setLoading(false)
|
||||
} catch (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user