diff --git a/src/components/Filter.js b/src/components/Filter.js index edfd3f1..e9631dc 100644 --- a/src/components/Filter.js +++ b/src/components/Filter.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; +import Chip from '@mui/material/Chip'; import Checkbox from '@mui/material/Checkbox'; import IconButton from '@mui/material/IconButton'; import Collapse from '@mui/material/Collapse'; @@ -138,21 +139,25 @@ class Filter extends Component { handleOptionChange = (event) => { const { name, checked } = event.target; - - // Update local state first to ensure immediate UI feedback - this.setState(prevState => ({ - options: { + const narrow = + typeof window !== "undefined" && window.innerWidth < 600; + + this.setState((prevState) => { + const nextOptions = { ...prevState.options, - [name]: checked - } - })); - - // Then notify the parent component + [name]: checked, + }; + return { + options: nextOptions, + ...(narrow && checked ? { isCollapsed: true } : {}), + }; + }); + if (this.props.onFilterChange) { - this.props.onFilterChange({ - type: this.props.filterType || 'default', - name: name, - value: checked + this.props.onFilterChange({ + type: this.props.filterType || "default", + name, + value: checked, }); } }; @@ -181,6 +186,13 @@ class Filter extends Component { })); }; + clearFilterOption = (optionId) => (event) => { + event.stopPropagation(); + this.handleOptionChange({ + target: { name: optionId, checked: false }, + }); + }; + render() { const { options, counts, isCollapsed } = this.state; const { title, options: optionsList = [] } = this.props; @@ -267,11 +279,79 @@ class Filter extends Component { )} {isXsScreen && ( - + { + e.stopPropagation(); + this.toggleCollapse(); + }} + > {isCollapsed ? : } )} + + {isXsScreen && + isCollapsed && + optionsList.some((o) => options[o.id]) && ( + + {optionsList + .filter((o) => options[o.id]) + .map((option) => ( + + {this.props.filterType === "manufacturer" && + this.props.manufacturerImages?.get(option.id) && ( + + )} + + {option.name} + + + } + /> + ))} + + )} diff --git a/src/components/ProductDetailPage.js b/src/components/ProductDetailPage.js index 102b3bb..98176fe 100644 --- a/src/components/ProductDetailPage.js +++ b/src/components/ProductDetailPage.js @@ -1089,6 +1089,8 @@ class ProductDetailPage extends Component { const { product, loading, upgrading, error, attributeImages, /*isSteckling,*/ attributes, komponentenLoaded, komponentenData, komponentenImages, totalKomponentenPrice, totalSavings, shareAnchorEl, sharePopperOpen, snackbarOpen, snackbarMessage, snackbarSeverity } = this.state; + const hasAttributeImages = attributes.some((attr) => attributeImages[attr.kMerkmalWert]); + // Debug alerts removed @@ -1298,7 +1300,19 @@ class ProductDetailPage extends Component { {(attributes.some(attr => attributeImages[attr.kMerkmalWert]) || attributes.some(attr => !attributeImages[attr.kMerkmalWert])) && ( - + {attributes .filter(attribute => attributeImages[attribute.kMerkmalWert]) .map((attribute) => { @@ -1321,7 +1335,11 @@ class ProductDetailPage extends Component { key={attribute.kMerkmalWert} label={attribute.cWert} disabled - sx={{ + sx={(theme) => ({ + // Max-width query: reliable on portrait phones (avoids display:contents wrapper quirks) + [theme.breakpoints.down('sm')]: { + display: 'none', + }, '&.Mui-disabled': { opacity: 1, // ← Remove the "fog" }, @@ -1329,7 +1347,7 @@ class ProductDetailPage extends Component { fontWeight: 'bold', color: 'inherit', // ← Keep normal text color }, - }} + })} /> ))}