-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a proof of concept for utilizing the "new" native HTML `dialog` element with the `open` attribute. By default, it is accessible with focus and keyboard navigation. In this version, it triggers a dialog/modal upon clicking on an event. The dialog includes a close button (the dialog also closes when pressing the escape key or clicking on the backdrop) and a button that currently displays an alert with the event's title. `handleEventEditing` will later be an update request to the API.
- Loading branch information
1 parent
8bdf5b4
commit 144841a
Showing
5 changed files
with
150 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// The dialog element allready has keyboard support | ||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ | ||
/* eslint-disable jsx-a11y/click-events-have-key-events */ | ||
import React, { forwardRef } from "react"; | ||
|
||
type DialogType = { | ||
children: React.ReactNode; | ||
closeDialog: () => void; | ||
}; | ||
|
||
const Dialog = forwardRef<HTMLDialogElement, DialogType>( | ||
({ children, closeDialog }, ref) => { | ||
return ( | ||
<dialog | ||
ref={ref} | ||
// close dialog when clicking outside of it (::backdrop pseudo-element) | ||
onClick={({ currentTarget, target }) => { | ||
if (currentTarget === target) { | ||
closeDialog(); | ||
} | ||
}} | ||
> | ||
<button | ||
type="button" | ||
onClick={closeDialog} | ||
style={{ | ||
border: "1px solid black", | ||
padding: "5px", | ||
background: "grey" | ||
}} | ||
> | ||
Close | ||
</button> | ||
{children} | ||
</dialog> | ||
); | ||
} | ||
); | ||
export default Dialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import { EventImpl } from "@fullcalendar/core/internal"; | ||
|
||
type DialogFomularProps = { | ||
evnetInfo: EventImpl; | ||
handleEventEditing: (title: string) => void; | ||
}; | ||
|
||
const DialogFomular: React.FC<DialogFomularProps> = ({ | ||
evnetInfo, | ||
handleEventEditing | ||
}) => { | ||
return ( | ||
<> | ||
<p>DialogFomular:</p> | ||
<pre>{JSON.stringify(evnetInfo, null, 2)}</pre> | ||
<form> | ||
{/* Should be type submit */} | ||
<button | ||
type="button" | ||
onClick={() => handleEventEditing(evnetInfo.title)} | ||
style={{ | ||
border: "1px solid black", | ||
padding: "5px", | ||
background: "grey" | ||
}} | ||
> | ||
Show title btn | ||
</button> | ||
</form> | ||
</> | ||
); | ||
}; | ||
|
||
export default DialogFomular; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useRef, useState } from "react"; | ||
|
||
const useDialog = () => { | ||
const [dialogContent, setDialogContent] = useState<React.ReactNode>(null); | ||
|
||
const dialogRef = useRef<HTMLDialogElement>(null); | ||
|
||
const closeDialog = () => { | ||
dialogRef.current?.close(); | ||
}; | ||
|
||
const openDialogWithContent = (content: React.ReactNode) => { | ||
setDialogContent(content); | ||
dialogRef.current?.showModal(); | ||
}; | ||
|
||
return { | ||
dialogContent, | ||
dialogRef, | ||
openDialogWithContent, | ||
closeDialog | ||
}; | ||
}; | ||
|
||
export default useDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters