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

Utilizes ModalBase to lock scroll on mobile filters #5659

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Box, Button, Flex, Sans, color } from "@artsy/palette"
import React, { SFC } from "react"
import {
Box,
Button,
Clickable,
Flex,
ModalBase,
Sans,
color,
} from "@artsy/palette"
import React, { SFC, useRef } from "react"
import styled from "styled-components"
import {
initialArtworkFilterState,
Expand All @@ -13,22 +21,42 @@ export const ArtworkFilterMobileActionSheet: SFC<{
}> = ({ children, onClose }) => {
const filterContext = useArtworkFilterContext()

const contentRef = useRef<HTMLDivElement | null>(null)

// This reflects our zero state for this UI which doesn't include the keyword
const isReset = isEqual(
omit(filterContext.filters, "reset", "keyword"),
initialArtworkFilterState
)

const handleScrollToTop = () => {
if (!contentRef.current) return
contentRef.current.scrollTop = 0
}

return (
<Container>
<ModalBase
onClose={onClose}
dialogProps={{
width: "100%",
height: "100%",
background: color("white100"),
dzucconi marked this conversation as resolved.
Show resolved Hide resolved
flexDirection: "column",
}}
>
<Header p={1}>
<Button variant="noOutline" size="small" onClick={onClose}>
Close
</Button>

<Title size="3" weight="medium" textAlign="center">
Filter
</Title>
{/* TODO: This extraneous Flex is not necessary, Clickable (and Box) should have Flex props*/}
dzucconi marked this conversation as resolved.
Show resolved Hide resolved
<Flex flex="1">
<Clickable width="100%" onClick={handleScrollToTop}>
<Title size="3" weight="medium" textAlign="center">
Filter
</Title>
</Clickable>
</Flex>

<Button
size="small"
Expand All @@ -40,7 +68,7 @@ export const ArtworkFilterMobileActionSheet: SFC<{
</Button>
</Header>

<Content>
<Content ref={contentRef as any}>
dzucconi marked this conversation as resolved.
Show resolved Hide resolved
<Box width="100%" p={2}>
{children}
</Box>
Expand All @@ -51,25 +79,10 @@ export const ArtworkFilterMobileActionSheet: SFC<{
Apply
</Button>
</Footer>
</Container>
</ModalBase>
)
}

const Container = styled(Box)`
position: fixed;

/* The z-index after Force's mobile top-nav header */
z-index: 971;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: white;
display: flex;
flex-direction: column;
overflow: hidden;
`

const Header = styled(Flex)`
width: 100%;
align-items: center;
Expand Down