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

prevent dropdowns from flowing off the screen #464

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions spotlight-client/src/UiLibrary/Dropdown/InPlaceMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const InPlaceOptionList = styled.ul`
border: 1px solid ${colors.rule};
border-radius: ${rem(BUTTON_HEIGHT / 4)};
font-size: ${rem(13)};
max-height: 70vh;
white-space: nowrap;

&:focus {
Expand All @@ -54,14 +55,22 @@ const InPlaceMenu = ({
waitForCloseAnimation,
}: MenuProps): React.ReactElement => {
const [menuHeight, setMenuHeight] = useState(0);
const [listOverflow, setListOverflow] = useState("visible");

const showMenuItems = isOpen || waitForCloseAnimation;
const menuStyles = useSpring({
const wrapperStyles = useSpring({
from: { height: 0 },
height: isOpen ? menuHeight : 0,
config: { clamp: true, friction: 20, tension: 210 },
onRest: (props) => {
if (props.height === 0) setWaitForCloseAnimation(false);
if (props.height === 0) {
setWaitForCloseAnimation(false);
setListOverflow("visible");
} else {
// updated at the end of the animation because it will
// interfere with menu expansion if it's already set
setListOverflow("auto");
}
},
});

Expand All @@ -75,8 +84,11 @@ const InPlaceMenu = ({
}}
>
{({ measureRef }) => (
<InPlaceMenuWrapper style={menuStyles}>
<InPlaceOptionList {...getMenuProps({ ref: measureRef })}>
<InPlaceMenuWrapper style={wrapperStyles}>
<InPlaceOptionList
{...getMenuProps({ ref: measureRef })}
style={{ overflow: listOverflow }}
>
{showMenuItems &&
options.map((option, index) =>
renderOption({
Expand Down