No video

Best Way to Add Popup Modals in React

  Рет қаралды 5,156

Colby Fayock

Colby Fayock

2 ай бұрын

Add modal dialogs in React that pop up in the browser using the HTML Dialog element.
Learn how to use the native browser Dialog element in React to dynamically render modal content, show and hide the modal, and navigate through a gallery of images using arrow keys. We'll even see how we can use Tailwind to customize the style of the modal.
🧰 Resources
Tutorial: spacejelly.dev/posts/how-to-c...
Code: github.com/colbyfayock/my-modal
Demo: my-modal.vercel.app/
📺 KZbin: kzbin.info?sub_c...
🐦 Twitter: / colbyfayock
📹 Twitch: / colbyfayock
✉️ Newsletter: www.colbyfayock.com/newsletter/
🎥 What I Use: www.colbyfayock.com/uses
#colbyfayock #react #tailwindcss #javascript #modal #dialog #html #webdevelopment

Пікірлер: 25
@colbyfayock
@colbyfayock 19 сағат бұрын
Learn how to build a full stack Next.js app in my upcoming course: colbyfayock.com/course
@nikitaliakhovka3489
@nikitaliakhovka3489 2 ай бұрын
For the document overflow, you can leverage the power of the :has() selector: CSS: html:has(dialog[open]) { overflow: hidden; } Tailwind: (on html tag) className="[&:has(dialog[open])]:overflow-hidden"
@colbyfayock
@colbyfayock 2 ай бұрын
i still have yet to spend time with :has 😅 i need to!
@abishekbaiju1705
@abishekbaiju1705 Ай бұрын
I just read your article about this and it was super clear. Thanks a lot for making these content. subscribed to both youtube and newsletter.
@colbyfayock
@colbyfayock Ай бұрын
thanks for your kind words 🙏
@colbyfayock
@colbyfayock 2 ай бұрын
Get fresh tutorials and other free content straight to your inbox! colbyfayock.com/news
@fran_sar
@fran_sar 13 күн бұрын
Really awesome tutorial. Thank you a lot (from Argentina)! I found many code and styles details and concepts that I didn't know or just forgot helps a bunch.
@colbyfayock
@colbyfayock 9 күн бұрын
no problem!
@John-eq5cd
@John-eq5cd 2 ай бұрын
Excellent. Thank you, Colby.
@colbyfayock
@colbyfayock 2 ай бұрын
you're welcome!
@mohamedelmhassani5618
@mohamedelmhassani5618 2 ай бұрын
Thaaaanks Colby, so helpful. no more extra KBs to my projects 😂
@colbyfayock
@colbyfayock 2 ай бұрын
haha yes!! no problem 🙌
@dannievinther
@dannievinther 2 ай бұрын
Awesome stuff :) A better choice, I believe, would be to use the Popover API: e.g., . That way you get more of the functionality for free as well as a implicit role.
@colbyfayock
@colbyfayock 2 ай бұрын
thanks! i haven't played around with Popover API but someone else mentioned that and i did a little looking around. it looks like they largely can both do the same thing but have different semantics and small functionally differences which matter more in the context of modal vs non-modal dialogs. i'l have to spend more time with it, both from a functionality perspective, and to understand those differences more. maybe can make a good video down the line here's what i sent in the other comment: ---- they have large crossover but behave a slightly differently. here are a few difference though they're small: developer.chrome.com/blog/introducing-popover-api/#the_difference_between_a_popover_and_a_dialog ... looks like there was some chatter regarding this on whatwg GitHub issues with some interesting notes about the differences, though the chatter died off end of last year: github.com/whatwg/html/issues/9376 it seems like the consensus is
@AhmadJS
@AhmadJS 2 ай бұрын
👍👍👍👍👍
@colbyfayock
@colbyfayock 2 ай бұрын
🙌
@FlintBits
@FlintBits 2 ай бұрын
Why wouldn't you use popover api? By definition it is the "best way"
@colbyfayock
@colbyfayock 2 ай бұрын
they have large crossover but behave a slightly differently. here are a few difference though they're small: developer.chrome.com/blog/introducing-popover-api/#the_difference_between_a_popover_and_a_dialog what gives you the impression popover is "by definition" the best way compared to the dialog? looks like there was some chatter regarding this on whatwg GitHub issues with some interesting notes about the differences, though the chatter died off end of last year: github.com/whatwg/html/issues/9376 it seems like the consensus is
@FlintBits
@FlintBits 2 ай бұрын
​@@colbyfayock I would argue a light dismiss for a photo popup is better than a button, even more so on mobile.
@colbyfayock
@colbyfayock 2 ай бұрын
​@@FlintBits yeah definitely agree. i don't add that functionality directly in the video but i link at the end to another video i produced to implement it: kzbin.info/www/bejne/g5Crpp1_e9h8mJI
@EverydayBeing-de1qu
@EverydayBeing-de1qu 2 ай бұрын
Seems like alot of effort for a modal... I usually just create new component modal with fixed inset-0 bg-black bg-opacity-0 and then another div with h-full flex justify-center items-center and then a main with the actual modal and specify the h and w you want it to be.
@MohamedElguarir
@MohamedElguarir 2 ай бұрын
yeah well until you want to hit escape to close the modal or change focus using the keyboard 🤷🏻‍♂️
@colbyfayock
@colbyfayock 2 ай бұрын
if you dont care about UX, sure
`const` was a mistake
31:50
Theo - t3․gg
Рет қаралды 132 М.
The Most Important Skill You Never Learned
34:56
Web Dev Simplified
Рет қаралды 182 М.
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 29 МЛН
Secret Experiment Toothpaste Pt.4 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 32 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 43 МЛН
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 509 М.
A flexbox trick to improve text wrapping
5:02
Kevin Powell
Рет қаралды 198 М.
Bye.
25:10
GothamChess
Рет қаралды 151 М.
Fetching Data Doesn't Get Better Than This
6:58
Josh tried coding
Рет қаралды 101 М.
Modal in Next.js & React | Create a Dialog Component
22:57
Dave Gray
Рет қаралды 31 М.
You might not need useEffect() ...
21:45
Academind
Рет қаралды 155 М.
Abort Fetch API Requests using AbortController
6:37
Colby Fayock
Рет қаралды 9 М.
React Dialogs (the right way)
15:46
Coding in Public
Рет қаралды 6 М.
Speech Recognition & Voice Synthesis in React (Web Speech API)
31:00
How to OVER Engineer a Website // What is a Tech Stack?
11:20
Fireship
Рет қаралды 2,3 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 29 МЛН