Skip to content

Commit

Permalink
fix: keyboard covers content on mobile safari (#2555)
Browse files Browse the repository at this point in the history
* wip

* working solution

* clean up
  • Loading branch information
LeahMarieBush authored Aug 29, 2024
1 parent 7862fe6 commit eb7dd83
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/components/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: MPL-2.0
*/

import { useEffect, useState } from 'react'
import { DialogOverlay, DialogContent } from '@reach/dialog'
import '@reach/dialog/styles.css'
import {
Expand Down Expand Up @@ -33,6 +34,7 @@ export default function Dialog({
variant = 'modal',
}: DialogProps) {
const shouldReduceMotion = useReducedMotion()
const [padding, setPadding] = useState('0px')

const overlayMotionProps = {
variants: overlayVariants,
Expand All @@ -42,6 +44,19 @@ export default function Dialog({
transition: { duration: shouldReduceMotion ? 0 : 0.3 },
}

useEffect(() => {
const handleResize = () => {
setPadding(
(window.innerHeight - window.visualViewport.height).toString() + 'px'
)
}

window.visualViewport.addEventListener('resize', handleResize)

return () =>
window.visualViewport.removeEventListener('resize', handleResize)
}, [])

return (
<AnimatePresence>
{isOpen && (
Expand All @@ -55,6 +70,7 @@ export default function Dialog({
<div
key="contentWrapper"
className={classNames(s.contentWrapper, s[variant])}
style={variant === 'bottom' ? { paddingBottom: padding } : null}
>
<DialogContent
aria-describedby={ariaDescribedBy}
Expand Down

0 comments on commit eb7dd83

Please sign in to comment.