LoginSignup
0
0

Reactでdialog試してみた。

Last updated at Posted at 2023-09-06

作ったサンプル

dialog.tsx
import { useRef } from "react";

export function Dialog() {
  const dialogRef = useRef<HTMLDialogElement>(null);

  const handleShowDialogEvent = () => {
    if (dialogRef.current) {
      dialogRef.current.showModal();
    }
  }

  const handleCloseDialogEvent = () => {
    if (dialogRef.current) {
      dialogRef.current.close();
    }
  }

  return (
    <>
      <button onClick={handleShowDialogEvent}>ダイアログ表示</button>

      <dialog ref={dialogRef}>
        <h1>サンプル</h1>
        <div>ダイアログが表示される。</div>
        <button onClick={handleCloseDialogEvent}>閉じる</button>
      </dialog>
    </>
  )
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0