diff --git a/src/components/Filter/Filter.tsx b/src/components/Filter/Filter.tsx index f3c1f96d1..828141e1b 100644 --- a/src/components/Filter/Filter.tsx +++ b/src/components/Filter/Filter.tsx @@ -128,6 +128,15 @@ const Filter: React.FC = props => { transition disablePortal placement="bottom-start" + modifiers={{ + flip: { + enabled: false + }, + preventOverflow: { + boundariesElement: "scrollParent", + enabled: false + } + }} > {({ TransitionProps, placement }) => ( ; - filterField: IFilterElement; setDisplayValues: ( values: Record ) => void; - onFilterPropertyChange: React.Dispatch>; } const useStyles = makeStyles( diff --git a/src/components/Filter/FilterContent.tsx b/src/components/Filter/FilterContent.tsx index 18a7d3fa6..9a9021ccc 100644 --- a/src/components/Filter/FilterContent.tsx +++ b/src/components/Filter/FilterContent.tsx @@ -11,22 +11,18 @@ import makeStyles from "@material-ui/core/styles/makeStyles"; import { fade } from "@material-ui/core/styles/colorManipulator"; import { buttonMessages } from "@saleor/intl"; import { TextField } from "@material-ui/core"; -import { toggle } from "@saleor/utils/lists"; -import createMultiAutocompleteSelectHandler from "@saleor/utils/handlers/multiAutocompleteSelectChangeHandler"; import useStateFromProps from "@saleor/hooks/useStateFromProps"; import Hr from "../Hr"; import Checkbox from "../Checkbox"; import SingleSelectField from "../SingleSelectField"; import { SingleAutocompleteChoiceType } from "../SingleAutocompleteSelectField"; import FormSpacer from "../FormSpacer"; -import MultiAutocompleteSelectField, { - MultiAutocompleteChoiceType -} from "../MultiAutocompleteSelectField"; -import Link from "../Link"; +import { MultiAutocompleteChoiceType } from "../MultiAutocompleteSelectField"; import { IFilter, FieldType, FilterType } from "./types"; import Arrow from "./Arrow"; import { FilterReducerAction } from "./reducer"; import FilterAutocompleteField from "./FilterAutocompleteField"; +import FilterOptionField from "./FilterOptionField"; export interface FilterContentProps { currencySymbol: string; @@ -341,61 +337,12 @@ const FilterContent: React.FC = ({ )} - {filterField.type === FieldType.options && - (filterField.multiple ? ( - filterField.options.map(option => ( -
- - } - label={option.label} - name={filterField.name} - onChange={() => - onFilterPropertyChange({ - payload: { - name: filterField.name, - update: { - value: toggle( - option.value, - filterField.value, - (a, b) => a === b - ) - } - }, - type: "set-property" - }) - } - /> -
- )) - ) : ( - - onFilterPropertyChange({ - payload: { - name: filterField.name, - update: { - value: [event.target.value] - } - }, - type: "set-property" - }) - } - /> - ))} + {filterField.type === FieldType.options && ( + + )} {filterField.type === FieldType.boolean && filterField.options.map(option => (
({ + option: { + left: -theme.spacing(0.5), + position: "relative" + }, + optionRadio: { + left: -theme.spacing(0.25) + }, + root: {} + }), + { name: "FilterOptionField" } +); + +const FilterOptionField: React.FC = ({ + filterField, + onFilterPropertyChange +}) => { + const classes = useStyles({}); + const handleSelect = (value: string) => + onFilterPropertyChange({ + payload: { + name: filterField.name, + update: { + value: filterField.multiple + ? toggle(value, filterField.value, (a, b) => a === b) + : [value] + } + }, + type: "set-property" + }); + + return ( +
+ {filterField.options.map(option => ( +
+ + ) : ( + + ) + } + label={option.label} + name={filterField.name} + onChange={() => handleSelect(option.value)} + /> +
+ ))} +
+ ); +}; + +FilterOptionField.displayName = "FilterOptionField"; +export default FilterOptionField; diff --git a/src/components/Filter/types.ts b/src/components/Filter/types.ts index ea257c8f7..86930048e 100644 --- a/src/components/Filter/types.ts +++ b/src/components/Filter/types.ts @@ -1,5 +1,6 @@ import { FetchMoreProps, SearchPageProps } from "@saleor/types"; import { MultiAutocompleteChoiceType } from "../MultiAutocompleteSelectField"; +import { FilterReducerAction } from "./reducer"; export enum FieldType { autocomplete, @@ -28,6 +29,11 @@ export interface IFilterElement type: FieldType; } +export interface FilterBaseFieldProps { + filterField: IFilterElement; + onFilterPropertyChange: React.Dispatch>; +} + export type IFilter = Array>; export enum FilterType {