Building a command palette with Tailwind CSS, React, and Headless UI

  Рет қаралды 66,503

Tailwind Labs

Tailwind Labs

Күн бұрын

In this video I'll walk you through the steps to build a fully accessible command palette using Tailwind CSS, React, and the new combobox component in Headless UI.
Chapters:
00:00 Intro
00:10 What we're building
00:34 Command palette examples
01:13 Our starting point
03:00 The Dialog component
04:41 Styling the Dialog
08:28 The Combobox component
13:17 Displaying the projects data
17:05 Styling the active project
19:03 Wiring up the search
22:25 Handling empty states
23:54 Handling page navigation
27:17 Creating a custom keyboard shortcut
30:49 Adding subtle transitions
34:19 Resetting the search query state
36:30 Looking back at our journey
37:33 Outro

Пікірлер: 169
@IanZamojc
@IanZamojc 2 жыл бұрын
I especially like how you've shown some of the traps (window location vs router, resetting search too early, etc.) and how to avoid them.
@simonswiss
@simonswiss 2 жыл бұрын
Thanks! Yeah, they let you appreciate the subtle details even more, things you'd take for granted 👍
@IanZamojc
@IanZamojc Жыл бұрын
@June@97 You should post this as a top level comment. Also, you'll have to specify which font you mean; the one on the web page or the one in the text editor?
@amirreza-dev
@amirreza-dev 2 жыл бұрын
There are some programmers in the world who makes programming much lovely, sweet and enjoyable You my sir are one of those people Thank you so much
@zyishai
@zyishai 2 жыл бұрын
Agree 100%!!!!
@simonswiss
@simonswiss 2 жыл бұрын
Awwwwe thank you so much 🙏
@nemethricsi
@nemethricsi Жыл бұрын
@@simonswiss I wanna echo these compliments. Really awesome tutorial! Can I ask what font are you using in your editor? 🙈 Thank you Simon
@simonswiss
@simonswiss Жыл бұрын
@@nemethricsi Thank you so much! The font is called Dank Mono.
@nemethricsi
@nemethricsi Жыл бұрын
@@simonswiss OMG I’m using the same font that’s why it was familiar 😂 But looked even more better in the video. Maybe less font-weight :) Tailwind is awesome! I’m just starting getting familiar with it.
@YazinS
@YazinS 2 жыл бұрын
The difference with Tailwind videos is obvious. These guys aren't just building cool stuff.. they're having fun! Love these videos
@victornwanguma2427
@victornwanguma2427 2 жыл бұрын
Tailwind makes frontend and styling beautiful for me
@Syndeer
@Syndeer Жыл бұрын
@@victornwanguma2427 Yeah I absolutely agree with you Tailwind css is so much fun and easier
@BarisPalabiyik
@BarisPalabiyik 2 жыл бұрын
Can't believe I just watch the whole thing, even tho I knew most of the things in it. That's says a lot about the pace and presentation.
@simonswiss
@simonswiss 2 жыл бұрын
Thank you so much! Yeah I really try to respect everyone's time, even in longer form video like this one.
@eyalch
@eyalch 2 жыл бұрын
Small suggestion: In the useEffect's dependencies array you're providing isOpen, which is required because isOpen is indeed being used inside the callback (to get an opposite value). This causes the keydown event listener to be re-created every time the command palette is opened and closed. A nice and easy solution to this is instead of passing the new value directly to setIsOpen we can pass a callback which accepts the current value and returns a new one, then we can remove isOpen from the dependencies array. Thank you for producing such high quality content!
@simonswiss
@simonswiss 2 жыл бұрын
That's a great tip, thank you!
@xadden
@xadden 2 жыл бұрын
Code wise, I believe Exo means instead of using setIsOpen(!isOpen), use setIsOpen(value => !value)
@eyalch
@eyalch 2 жыл бұрын
@@xadden Exactly!
@som.shekhar
@som.shekhar 2 жыл бұрын
Firstly, I don't think so recreating the function has any significant performance impact at all. Secondly, even if you pass a callback to `setIsOpen` you would now be recreating the callback function `(isOpen) => !isOpen` on every toggle -- which is a little less obvious, but true. So, essentially you're swapping in creation of one function for the other. Let me know your thoughts on this.
@eyalch
@eyalch 2 жыл бұрын
@@som.shekhar It's not only the function that gets re-created, but the event listener itself (together with the handler function)
@fabhi
@fabhi 2 жыл бұрын
CSS instructors are the most fun to watch!
@somerandomchannel382
@somerandomchannel382 2 жыл бұрын
Another great design idea of a ComboBox is ofcourse Tailwind's Search in Documentation . It's really flexible and handy to find any classes you want know the tailwind prefix for :)
@juraso7312
@juraso7312 2 жыл бұрын
tailwindcss search in documentation is build with algolia not combobox, search on tailwindui documentation is build with combobox
@hazemturki
@hazemturki 2 жыл бұрын
Lost my mind trying to get a combobox to work using listbox, so glad to this happened. I coincidentally landed on headless ui home page. And saw it, and that made me so happy. Thanks for all the work!
@aghileslounis
@aghileslounis 2 жыл бұрын
Amazing video as always, so inspiring to do great work
@universecode1101
@universecode1101 2 жыл бұрын
Awesome man 🚀 These three together 🔥 Tailwind is a game changer, thanks ✌🏻
@gomflo
@gomflo 2 жыл бұрын
Really amazing work, the subtle details, the production, how you explain, very well done.
@simonswiss
@simonswiss 2 жыл бұрын
Thank you! It really is a team effort 👍
@hot4mix
@hot4mix 2 жыл бұрын
Genuinly impressive flow. i will watch you code anything. literally anything xD
@simonswiss
@simonswiss 2 жыл бұрын
Thank you!
@JimOHalloran
@JimOHalloran 2 жыл бұрын
Wow, that was a ride! I built a select box with a search field on the drop down (Vue + Headless UI) a while ago, but I was never 100% happy with it. I think it's time to rebuild using the new combo box components!
@simonswiss
@simonswiss 2 жыл бұрын
Haha nice, let us know how you go!
@Billiam112
@Billiam112 2 жыл бұрын
Fantastic content! More in headless ui would be highly appreciated! ❤️
@code.design
@code.design Жыл бұрын
this tutorial is something else. I came for tailwind and learned as a bonus about nextjs. Awesome stuff!
@josegmdev
@josegmdev 2 жыл бұрын
Amazing video as always! you do an awesome job with this channel 🙌🏼
@simonswiss
@simonswiss 2 жыл бұрын
🙏
@alirezakiani1222
@alirezakiani1222 2 жыл бұрын
It was great. I always use your tutorials. Thank you for being
@sumitsharma_002
@sumitsharma_002 Жыл бұрын
Thank you it was really informative. @headlessui is such a cool library component to have in your projects.
@nguimeyabill-gates2577
@nguimeyabill-gates2577 2 жыл бұрын
I was actually stuck implementing a search component, he just answered my questions. Thanks a lot!
@AliMoeeny
@AliMoeeny 2 жыл бұрын
Isn't this just pure gold, thank you very much.
@octavian0704
@octavian0704 Жыл бұрын
Amazing mate !!! really well done and nicely explained. Thanks for sharing.
@eminalizade8998
@eminalizade8998 2 жыл бұрын
Loving TailwindCSS, keep up the good work! 😍
@hudson_w
@hudson_w 2 жыл бұрын
You're amazing. This is so cool. Keep having fun and inspiring others
@adityakadam2256
@adityakadam2256 2 жыл бұрын
It is such an amazing video. It makes me try it out by myself. Thanks a ton.
@GrahamBillington
@GrahamBillington 2 жыл бұрын
These videos are awesome, they help with learning react too
@StayFlyJW
@StayFlyJW 2 жыл бұрын
You, sir, are a dev that I need to learn under. Your design and teaching style is wonderful. Also, we need workflow… gotta replace ClickUp pronto.
@stephan3199
@stephan3199 2 жыл бұрын
Thanks so much! You really inspire me to be as good as you in the future
@sergeitinc
@sergeitinc 2 жыл бұрын
It's just some gift for us. Thank you so much.
@__sr__
@__sr__ 2 жыл бұрын
Excellent video as always.
@robotyang8501
@robotyang8501 2 жыл бұрын
love headless UI from now on.
@codingwithtien
@codingwithtien 2 жыл бұрын
Super useful tutorial.
@irsyadadl
@irsyadadl 2 жыл бұрын
Nice & Thank you Simon.
@dexter-wy5bo
@dexter-wy5bo 2 жыл бұрын
excellent video, as always !
@NamasteProgramming
@NamasteProgramming 2 жыл бұрын
This tutorial so good, I didn't even notice light theme IDE
@catreunion
@catreunion Жыл бұрын
Thank you Simon!
@webdev1943
@webdev1943 Жыл бұрын
nice way to explain , thank you
@WidianDAlbie
@WidianDAlbie 2 жыл бұрын
Thank you sir for amazing video
@s4ndeep1203
@s4ndeep1203 2 жыл бұрын
That didn't feel like 38 minutes ! loved it
@liferc
@liferc Жыл бұрын
Damn man! This is way too good. Please make video with other headless components it would be a lot better learning from you
@trenom
@trenom Жыл бұрын
good stuff learned so much from this video xD
@esdev
@esdev Жыл бұрын
Simon, You're just Aweeeeesome 🤩🥰
@jasonhoi85
@jasonhoi85 2 жыл бұрын
Great tutorial, i will use the same toolbox to make my command panel
@vOnez212
@vOnez212 2 жыл бұрын
Great stuff!
@amankumarverma8494
@amankumarverma8494 2 ай бұрын
So good 💯
@endernator
@endernator 2 жыл бұрын
mindblowingly good 🤯👏🏼
@dingen636
@dingen636 2 жыл бұрын
Top quality video as always! I know Tailwind is ment for implementation with JS frameworks but would be amazing to have documentation on how to use Tailwind in a Wordpress theme. Thanks for all the hard work!
@dexter-wy5bo
@dexter-wy5bo 2 жыл бұрын
This video should give you everything you need for that. It's possible and not hard at all, the only difference is you have to build/compile your tailwind css before pushing to the site, packaging the theme, etc... kzbin.info/www/bejne/pXiZiYOvZtlkgaM
@lukasmolcic5143
@lukasmolcic5143 2 жыл бұрын
If you are building a custom theme from scratch I would recommend setting up twig or some other templating language so that you can build components, working with tailwind without components is not that great, I used to use the timber plugin to achieve that, but these days we are usually going for headless wp + next for cms based websites.
@simonswiss
@simonswiss 2 жыл бұрын
Tailwind is definitely not limited or meant purely for implementation with JS frameworks! You could argue in fact that since it generates "just CSS", it works really well with WordPress, .NET, anything really. Headless UI, on the other hand, is definitely a JS framework implementation.
@yagorodi
@yagorodi Жыл бұрын
Amazing 👏
@Pixalynx
@Pixalynx 2 жыл бұрын
I would buy a react course from you !
@danvilela
@danvilela Жыл бұрын
I wanna like this video a thousand times!!
@simonswiss
@simonswiss 11 ай бұрын
One time will do - I appreciate the support!
@pkgoncalves
@pkgoncalves 2 жыл бұрын
Nice work!
@endernator
@endernator 2 жыл бұрын
soooo goooooooodddd.... please more ui with nextjs and headlessui.... it is a match made in heaven by the nerd gods 😇🤓
@kevingrondin974
@kevingrondin974 2 жыл бұрын
Thanks it’s very cool 👍
@austintoddj
@austintoddj 2 жыл бұрын
Love the video. Having a tough time translating the “custom keyboard shortcut” to a Vue app. Do you have any examples or links that might offer some insight into the specific keyboard event handling?
@MasterPloKoon
@MasterPloKoon 2 жыл бұрын
Would love to see a Vue tutorial next time when using Headless UI (:
@vilijanmonev896
@vilijanmonev896 2 жыл бұрын
Great video as always! Thank you very much, your skills are impressive. I have one question, in the Combox.Input I believe it is a common practice to perform the filter once the user has stopped typing or some amount of milliseconds has passed in order not to create computational overheat. Is there is a way to achieve something like this?
@matheuscabral4402
@matheuscabral4402 2 жыл бұрын
Great video!!! Any idea on how to prefetch on option selection?
@kashnigahbaruda
@kashnigahbaruda 2 жыл бұрын
MORE PLEASE
@AndersonSousa33
@AndersonSousa33 2 жыл бұрын
What a video!
@rafaeljuniorize
@rafaeljuniorize 2 жыл бұрын
🤩🥺 Beautiful
@tofustew
@tofustew 2 жыл бұрын
Another suggestion - omit the `text-sm` classname on the input field to avoid auto-zoom for iPhone users (Android, too, maybe?). Mobile Safari zooms in on input fields with text smaller than 16 px (and `text-sm` produces 14px text). Anyway, awesome video!
@LuisPerez-cb4rp
@LuisPerez-cb4rp 2 жыл бұрын
Thank you 🙏
@VinceKronlein
@VinceKronlein 2 жыл бұрын
This is so great, thanks Simon. I know it's a long shot, but any chance we can get a tutorial of this in Vue without Headless UI? My clients are not yet using Vue 3 so we're not able to use Headless UI yet. Either way, thanks for the great video.
@sargeantscigar
@sargeantscigar Жыл бұрын
Fantastic video, learned a lot! How can I implement your 🤙 terminal? It’s great!
@craftsmanhafeez
@craftsmanhafeez 2 жыл бұрын
does the combobox.button component mentioned in the headless ui docs have any special functionality. Can i wrap the combobox.input and combobox.button components in a form tag and use it like a normal searchbox for an ecommerce site with the combobox.options component giving the user search suggestions as he types?
@InfinityFnatic
@InfinityFnatic 2 жыл бұрын
What is the cursive font and how to set it up? Thank you!
@marbot9780
@marbot9780 2 жыл бұрын
Good Morning - thank you for the great video! Where can I download the Start and End environments? Greetings Markus
@dibbyo456
@dibbyo456 Жыл бұрын
Awesome
@joshuagalit6936
@joshuagalit6936 Жыл бұрын
The best !!
@GergelyCsermely
@GergelyCsermely 2 жыл бұрын
Thanks
@axelv21
@axelv21 2 жыл бұрын
wow, instant rebuilding my autocomplete with this! Goodby downshift.
@amanueltigistu8268
@amanueltigistu8268 2 жыл бұрын
What a great way of Building UI. Headless UI is really fantastic. But the framework support is limited to react & vue. There are really good framework like solid-js & svelte. Is there anything work to make Headless UI available for framework other than vue & react? One thing that I recommend is to make the core package separated from the framework implementations. In these way we can make Headless UI available for all of Us. Thanks.
@hiimaustin
@hiimaustin Жыл бұрын
I don’t know that you will see my comment or not but that you so much😍❤️ This is help me a lot🙏🏻❤️
@simonswiss
@simonswiss Жыл бұрын
I see your comment today! Glad you enjoyed, the video, Austin 🙏
@hiimaustin
@hiimaustin Жыл бұрын
@@simonswiss yess man! I love it
@jameswong3388
@jameswong3388 2 жыл бұрын
Hi anyone know how to do the navigation on vuejs3, tried @change="window.location.href..." but doesn't work
@clemensheithecker
@clemensheithecker 2 жыл бұрын
Thanks for the great video Simon! What theme and font are you using? It makes it easy to read and follow your code.
@simonswiss
@simonswiss 2 жыл бұрын
I usually use Night Owl + Dank Mono. This one uses Night Owl *Light* + Dank Mono ✨
@chbb9027
@chbb9027 2 жыл бұрын
What is that font in VSCode?
@jimmyj.6792
@jimmyj.6792 2 жыл бұрын
Tailwind world 😍😍😍😍 💕💕
@abacuswithrehan264
@abacuswithrehan264 2 жыл бұрын
Hello Loved the video. Can you share your current video font , theme and vscode settings please don't ignore, please 🙏
@tuscala
@tuscala 2 жыл бұрын
What is your VS Code theme? It's beautiful
@praveenprasad9477
@praveenprasad9477 2 жыл бұрын
Anyone know which app this "workflow"??
@davidluhr
@davidluhr 2 жыл бұрын
Another great guide Simon! Small suggestion: the combobox option markup can be a NextJS `` component with an `` tag for native navigation instead of `useRouter`. If I'm not mistaken, this will also take care of closing the Dialog on a route change.
@simonswiss
@simonswiss 2 жыл бұрын
Ah, nice one! I think it was still good to show the "onChange" prop on the Combobox component for general purposes, but for this specific scenario your solution sounds pretty elegant if it indeed closes the Dialog in the route change process 👍
@imsarvesh_
@imsarvesh_ 2 жыл бұрын
I am speechless 😶
@simonswiss
@simonswiss 2 жыл бұрын
Lucky you can use the command palette to do a search instead of talking to Siri/Google/Alexa 🤣
@Ms37maracaibo
@Ms37maracaibo 8 ай бұрын
Awesome! Could you make a command pallette using Nuxt 3 Tailwind and latest Headless UI ? Thanks !!!
@adarshdesai3081
@adarshdesai3081 3 ай бұрын
could you guys share the source code got the project management app?
@abdiafrah4907
@abdiafrah4907 2 жыл бұрын
Great content!!!! But one question, who uses white theme on code editor looool
@simonswiss
@simonswiss 2 жыл бұрын
I do, sometimes 😅
@QuangAkita
@QuangAkita Жыл бұрын
Could you please let me know font for code editor in this video!
@SaeedNeamati
@SaeedNeamati 2 жыл бұрын
first liked, then watched
@yazugaming5573
@yazugaming5573 Жыл бұрын
which font of your IDE use?
@msnxcrj
@msnxcrj 9 ай бұрын
I would like to know the vs code font he is using. I really love those!
@msnxcrj
@msnxcrj 9 ай бұрын
I figured it out, its "dank mono font"
@simonswiss
@simonswiss 4 ай бұрын
That's the one!@@msnxcrj
@fpigeonjr
@fpigeonjr 2 жыл бұрын
🤩woah
@abobakerhilal4138
@abobakerhilal4138 2 жыл бұрын
What is type font it used in vscode? Its nice
@simonswiss
@simonswiss 2 жыл бұрын
Dank Mono
@bassman2145
@bassman2145 7 ай бұрын
Does anyone know what font is being used in the code editor?
@simonswiss
@simonswiss 4 ай бұрын
I rock with Dank Mono in this video 👍
@jasonji1152
@jasonji1152 2 жыл бұрын
Can someone explain why `relative` fixed the stacking issue at 7:25? Thx
@simonswiss
@simonswiss 2 жыл бұрын
There are many CSS classes that create a new "stacking context", which is necessary here to stack the modal window above the "fixed" element. position:relative happens to be one of those. Super confusing for sure, but here's a good read: developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
@simonswiss
@simonswiss 2 жыл бұрын
Arguably I could/should have used the "isolate" utility class here - since its intent it to create a new stacking context. But that also confuses a lot of folks 😅
@robrechtmeersman8301
@robrechtmeersman8301 2 жыл бұрын
You'll want to stop propagation on your keydown event, because Ctrl+K is a reserved shortcut in Chrome on Windows.
@kashnigahbaruda
@kashnigahbaruda 2 жыл бұрын
Add multiple prop to SelectHeadlessUI component please!
@vojica6055
@vojica6055 2 жыл бұрын
Can someone help me, how to config file if my design is like this: i need on large desktop 1920px 1080 a container which is 1440grid width, can you help me how to edit that container is 1440 width and not 1526px (2xl) thanks a lot :)
@milon27
@milon27 Жыл бұрын
please create a headless ui playlist
@ShajidHasan
@ShajidHasan 2 жыл бұрын
Great video, Simon! What's that font you're using in your editor?
@simonswiss
@simonswiss 2 жыл бұрын
Thanks! It's called Dank Mono
@hazemturki
@hazemturki 2 жыл бұрын
Next Up: MacOS spotlight search please!!
@simonswiss
@simonswiss 2 жыл бұрын
Oooooh I was meant to show that one in my intro too - totally forgot, but I think Figma + devtools + vscode were enough demos to drive the point home. Spotlight is a fantastic example of a great command palette!
@DanStroot
@DanStroot 2 жыл бұрын
In desktop Safari, if I use command+k to open and close the search bar the screen scrolls to the bottom after I close the modal. Doesn't happen in Chrome or Firefox. Anyone seeing this? Any ideas?
@DanStroot
@DanStroot 2 жыл бұрын
Dialog model works fine, no issues. Put a Combobox in the model, no problem. The Combobox.Input seems to be the culprit. If that is inside the modal and you close with keyboard the page scrolls to the bottom on Safari. If I comment the Input out the page does not scroll.
@DanStroot
@DanStroot 2 жыл бұрын
import { useState, useEffect } from 'react'; import { Dialog, Combobox } from '@headlessui/react'; export function Test() { let [isOpen, setIsOpen] = useState(false); /* Handle Keyboard Input */ useEffect(() => { function handleKeyDown(event) { event.preventDefault(); event.stopPropagation(); /* e key for error - ha! */ if (event.key === 'e' && (event.ctrlKey || event.metaKey)) { setIsOpen((value) => !value); } } window.addEventListener('keydown', handleKeyDown); return () => { window.removeEventListener('keydown', handleKeyDown); }; }, []); /* minimal code to reproduce the issue */ return ( setIsOpen(false)} className='fixed top-0 z-10'> Hello {/* comment this out to see it work properly */} ); }
@coledrain2158
@coledrain2158 2 жыл бұрын
Sadly we won't be seeing Simon here again 😞
@coledrain2158
@coledrain2158 2 жыл бұрын
@Aroyan He is no longer on Tailwind Lab team.
@AnsgarSteinkamp
@AnsgarSteinkamp 2 жыл бұрын
New videos of Simon: kzbin.info
Theming Tailwind with CSS Variables
27:24
Tailwind Labs
Рет қаралды 117 М.
Headless UI vs Radix UI React/Vue Primitives | The Compared EP 3
7:15
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 6 МЛН
Build any layout with tailwind | crash course
34:28
Hitesh Choudhary
Рет қаралды 41 М.
Upgrading to Tailwind CSS v3.0
14:45
Tailwind Labs
Рет қаралды 49 М.
How the PROS Use Tailwind
9:55
Frontend FYI
Рет қаралды 42 М.
Building a Fancy Responsive Tile Grid with Tailwind CSS
13:28
Tailwind Labs
Рет қаралды 73 М.
Rebuilding Sick Fits with Tailwind CSS
1:13:16
Tailwind Labs
Рет қаралды 46 М.
10 Tailwind Tricks You NEED To Know!
10:45
Ravi - Perfect Base
Рет қаралды 264 М.
Sorting Tailwind CSS Classes Automatically with Prettier
10:00
Tailwind Labs
Рет қаралды 84 М.
Anaconda (Conda) for Python - What & Why?
26:10
Academind
Рет қаралды 216 М.
Build a Modern Landing Page With Tailwind CSS
1:50:04
John Komarnicki
Рет қаралды 181 М.
cn() - Every Tailwind Coder Needs It (clsx + twMerge)
7:46
ByteGrad
Рет қаралды 113 М.
How much charging is in your phone right now? 📱➡️ 🔋VS 🪫
0:11
😱НОУТБУК СОСЕДКИ😱
0:30
OMG DEN
Рет қаралды 2,8 МЛН