Skip to content

Commit

Permalink
Merge pull request #610 from pixiv/toshusai/fix-modal-does-not-work-i…
Browse files Browse the repository at this point in the history
…n-server-side

fix: modalがサーバーサイドで利用できない問題を修正
  • Loading branch information
toshusai authored Jul 26, 2024
2 parents 963d84d + 5131dad commit 43f410b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/react/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Modal = forwardRef<HTMLDivElement, ModalProps>(function ModalInner(
ref
)

const isMobile = useWindowWidth() < 744
const isMobile = (useWindowWidth() ?? Infinity) < 744
const transitionEnabled = isMobile && bottomSheet !== false
const showDismiss = !isMobile || bottomSheet !== true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ export function useCharcoalModalOverlay(
}
}

function isWindowDefined() {
return typeof window !== 'undefined'
}

export function useWindowWidth() {
const [width, setWidth] = React.useState(window.innerWidth)
const [width, setWidth] = React.useState(
isWindowDefined() ? window.innerWidth : null
)
React.useEffect(() => {
const handleResize = () => {
setWidth(window.innerWidth)
Expand Down

0 comments on commit 43f410b

Please sign in to comment.