11"use client" ;
22
33import clsx from "clsx" ;
4- import { ReactNode , useEffect , useState } from "react" ;
4+ import { ReactNode , useEffect , useRef , useState } from "react" ;
55
66interface Props {
77 className ?: string ;
@@ -14,6 +14,7 @@ interface Props {
1414export function Modal ( props : Props ) {
1515 const [ daisyModalEnabled , setDaisyModalEnabled ] = useState ( false ) ;
1616 const [ daisyModalOpen , setDaisyModalOpen ] = useState ( false ) ;
17+ const modalDivRef = useRef < HTMLDivElement > ( null ) ;
1718 useEffect ( ( ) => {
1819 if ( props . open ) {
1920 // daisyuiのmodalモードにする → modalを開くアニメーションをする
@@ -27,6 +28,22 @@ export function Modal(props: Props) {
2728 return ( ) => clearTimeout ( timeout ) ;
2829 }
2930 } , [ props . open ] ) ;
31+ useEffect ( ( ) => {
32+ if ( daisyModalEnabled ) {
33+ const updateHeight = ( ) => {
34+ if ( modalDivRef . current && window . visualViewport ) {
35+ modalDivRef . current . style . height = `${ window . visualViewport . height } px` ;
36+ }
37+ } ;
38+ updateHeight ( ) ;
39+ window . addEventListener ( "resize" , updateHeight ) ;
40+ return ( ) => window . removeEventListener ( "resize" , updateHeight ) ;
41+ } else {
42+ if ( modalDivRef . current ) {
43+ modalDivRef . current . style . height = "" ;
44+ }
45+ }
46+ } , [ daisyModalEnabled ] ) ;
3047
3148 return (
3249 < >
@@ -39,6 +56,7 @@ export function Modal(props: Props) {
3956 < div
4057 className = { clsx ( daisyModalEnabled && "modal h-dvh" ) }
4158 role = { daisyModalEnabled ? "dialog" : undefined }
59+ ref = { modalDivRef }
4260 >
4361 < div
4462 className = { clsx (
0 commit comments