Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown menus being clipped #1762

Merged
merged 5 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/images/ChevronDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions src/components/LanguageSwitch/LanguageSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const useStyles = makeStyles(
textAlign: "justify"
},
menuPaper: {
maxHeight: `calc(100vh - ${theme.spacing(2)}px)`,
maxHeight: 600,
overflow: "scroll"
},
popover: {
Expand Down Expand Up @@ -81,7 +81,6 @@ const LanguageSwitch: React.FC<LanguageSwitchProps> = props => {
open={isExpanded}
anchorEl={anchor.current}
transition
disablePortal
placement="bottom-end"
>
{({ TransitionProps, placement }) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TextField, Typography } from "@material-ui/core";
import { Popper, TextField, Typography } from "@material-ui/core";
import { fade } from "@material-ui/core/styles/colorManipulator";
import CloseIcon from "@material-ui/icons/Close";
import Debounce, { DebounceProps } from "@saleor/components/Debounce";
Expand Down Expand Up @@ -128,6 +128,7 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
...rest
} = props;
const classes = useStyles(props);
const anchor = React.useRef<HTMLInputElement | null>(null);

const handleSelect = (
item: string,
Expand Down Expand Up @@ -196,7 +197,8 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
if (fetchOnFocus) {
fetchChoices(inputValue);
}
}
},
ref: anchor
}}
error={error}
helperText={helperText}
Expand All @@ -205,28 +207,35 @@ const MultiAutocompleteSelectFieldComponent: React.FC<MultiAutocompleteSelectFie
disabled={disabled}
/>
{isOpen && (
<MultiAutocompleteSelectFieldContent
add={
add && {
...add,
onClick: () => {
add.onClick();
closeMenu();
<Popper
anchorEl={anchor.current}
open={isOpen}
style={{ width: anchor.current.clientWidth, zIndex: 10 }}
jwm0 marked this conversation as resolved.
Show resolved Hide resolved
placement="bottom-end"
>
<MultiAutocompleteSelectFieldContent
add={
add && {
...add,
onClick: () => {
add.onClick();
closeMenu();
}
}
}
}
choices={choices.filter(
choice => !value.includes(choice.value)
)}
displayCustomValue={displayCustomValue}
displayValues={displayValues}
getItemProps={getItemProps}
hasMore={hasMore}
highlightedIndex={highlightedIndex}
loading={loading}
inputValue={inputValue}
onFetchMore={onFetchMore}
/>
choices={choices.filter(
choice => !value.includes(choice.value)
)}
displayCustomValue={displayCustomValue}
displayValues={displayValues}
getItemProps={getItemProps}
hasMore={hasMore}
highlightedIndex={highlightedIndex}
loading={loading}
inputValue={inputValue}
onFetchMore={onFetchMore}
/>
</Popper>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InputBase, TextField } from "@material-ui/core";
import { InputBase, Popper, TextField } from "@material-ui/core";
import { InputProps } from "@material-ui/core/Input";
import { ExtendedFormHelperTextProps } from "@saleor/channels/components/ChannelForm/types";
import { makeStyles } from "@saleor/macaw-ui";
Expand Down Expand Up @@ -90,6 +90,7 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
...rest
} = props;
const classes = useStyles(props);
const anchor = React.useRef<HTMLInputElement | null>(null);

const handleChange = (item: string) => {
onChange({
Expand Down Expand Up @@ -219,30 +220,38 @@ const SingleAutocompleteSelectFieldComponent: React.FC<SingleAutocompleteSelectF
label={label}
fullWidth={true}
onBlur={onBlur}
ref={anchor}
/>
{isOpen && (!!inputValue || !!choices.length) && (
<SingleAutocompleteSelectFieldContent
add={
!!add && {
...add,
onClick: () => {
add.onClick();
closeMenu();
<Popper
anchorEl={anchor.current}
open={isOpen}
style={{ width: anchor.current.clientWidth, zIndex: 10 }}
placement="bottom-end"
>
<SingleAutocompleteSelectFieldContent
add={
!!add && {
...add,
onClick: () => {
add.onClick();
closeMenu();
}
}
}
}
choices={choices}
displayCustomValue={displayCustomValue}
emptyOption={emptyOption}
getItemProps={getItemProps}
hasMore={hasMore}
highlightedIndex={highlightedIndex}
loading={loading}
inputValue={inputValue}
isCustomValueSelected={isCustomValueSelected}
selectedItem={selectedItem}
onFetchMore={onFetchMore}
/>
choices={choices}
displayCustomValue={displayCustomValue}
emptyOption={emptyOption}
getItemProps={getItemProps}
hasMore={hasMore}
highlightedIndex={highlightedIndex}
loading={loading}
inputValue={inputValue}
isCustomValueSelected={isCustomValueSelected}
selectedItem={selectedItem}
onFetchMore={onFetchMore}
/>
</Popper>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface SingleAutocompleteSelectFieldContentProps
inputValue: string;
isCustomValueSelected: boolean;
selectedItem: any;
style?: React.CSSProperties;
}

const useStyles = makeStyles(
Expand All @@ -67,6 +68,7 @@ const useStyles = makeStyles(
? theme.palette.grey[50]
: theme.palette.grey[900],
bottom: 0,
color: theme.palette.primary.main,
display: "flex",
height: 30,
justifyContent: "center",
Expand Down Expand Up @@ -102,11 +104,8 @@ const useStyles = makeStyles(
root: {
borderBottomLeftRadius: 8,
borderBottomRightRadius: 8,
left: 0,
marginTop: theme.spacing(),
margin: theme.spacing(2, 0),
overflow: "hidden",
position: "absolute",
right: 0,
zIndex: 22
}
}),
Expand Down Expand Up @@ -146,7 +145,8 @@ const SingleAutocompleteSelectFieldContent: React.FC<SingleAutocompleteSelectFie
inputValue,
isCustomValueSelected,
selectedItem,
onFetchMore
onFetchMore,
style
} = props;

if (!!add && !!displayCustomValue) {
Expand Down Expand Up @@ -200,7 +200,7 @@ const SingleAutocompleteSelectFieldContent: React.FC<SingleAutocompleteSelectFie
const choicesToDisplay = choices.slice(0, slice);

return (
<Paper className={classes.root} elevation={8}>
<Paper className={classes.root} elevation={8} style={style}>
<div
className={classes.content}
ref={anchor}
Expand Down