<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lesley Chang</title>
    <description>The latest articles on DEV Community by Lesley Chang (@rasreee).</description>
    <link>https://dev.to/rasreee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F780328%2F7bfd1f30-f2c5-45c5-92f5-4410ac3e32cd.png</url>
      <title>DEV Community: Lesley Chang</title>
      <link>https://dev.to/rasreee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rasreee"/>
    <language>en</language>
    <item>
      <title>CMD+K Search Modal Tutorial (Part 1)</title>
      <dc:creator>Lesley Chang</dc:creator>
      <pubDate>Sat, 25 Dec 2021 08:05:40 +0000</pubDate>
      <link>https://dev.to/rasreee/cmdk-search-modal-tutorial-part-1-3fko</link>
      <guid>https://dev.to/rasreee/cmdk-search-modal-tutorial-part-1-3fko</guid>
      <description>&lt;p&gt;Preview the live demo &lt;a href="https://react-search-modal-tutorial.vercel.app/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we will build a ⌘K Search Modal, which is what it sounds like - a modal for searching content that can be opened by the ⌘K keyboard shortcut. The tutorial will be comprised of two parts: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part 1: The Assignment (the one you're reading)&lt;/li&gt;
&lt;li&gt;Part 2: My Implementation &amp;amp; Walkthrough&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Part 2 will be released to the public on December 31st, one week from when Part 1 (this article) is published.&lt;/p&gt;

&lt;p&gt;If you are reading this after both have been released already but want to practice building from scratch according to a list of requirements, try to force yourself to spend at least a week on Part 1 before looking at Part 2.&lt;/p&gt;

&lt;p&gt;Otherwise, feel free to skip ahead to Part 2 to read the walkthrough of how I built this ⌘K Search Modal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we're building
&lt;/h2&gt;

&lt;p&gt;For reference, here are some ⌘K Search Modals built by others:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tailwindcss.com/"&gt;TailwindCSS Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://uiw.tf/cmdk"&gt;uiwtf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We're going to be building a simple version of the ⌘K Search Modal with the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clicking the toggle button or pressing &lt;code&gt;⌘K&lt;/code&gt; keyboard shortcut opens the modal&lt;/li&gt;
&lt;li&gt;Clicking outside or one of the search results hides the modal&lt;/li&gt;
&lt;li&gt;Changing the search input text automatically updates the search results&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Assignment
&lt;/h2&gt;

&lt;p&gt;The end goal is a module that exports components SearchModalProvider and SearchModalToggle that clients can use to render a ⌘K Search Modal. Internally, it will render a component called SearchModal.&lt;/p&gt;

&lt;p&gt;Clients (apps that depend this module) can use these components by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Wrap their app with SearchModalProvider&lt;/li&gt;
&lt;li&gt;Render SearchModalToggle wherever they want to display it&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Project Setup
&lt;/h3&gt;

&lt;p&gt;Clone or fork the &lt;a href="https://github.com/rasreee/cmdk-search-tutorial-skeleton"&gt;Github repo&lt;/a&gt; for the skeleton code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/rasreee/cmdk-search-tutorial-skeleton.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From project root, install the dependencies, and run the app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Action Items
&lt;/h3&gt;

&lt;p&gt;Given the skeleton code, implement SearchModalProvider, SearchModalToggle, and SearchModal.&lt;/p&gt;

&lt;h4&gt;
  
  
  SearchModalProvider
&lt;/h4&gt;

&lt;p&gt;Edit SearchModalProvider.tsx to implement SearchModalProvider according to the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses React Context API&lt;/li&gt;
&lt;li&gt;Holds state of the SearchModal&lt;/li&gt;
&lt;li&gt;Renders SearchModal&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  SearchModalToggle
&lt;/h4&gt;

&lt;p&gt;Edit SearchModalToggle.tsx to implement the toggle button component according to the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Toggles the modal open when either:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;⌘K&lt;/code&gt; keyboard shortcut is pressed&lt;/li&gt;
&lt;li&gt;Button is clicked&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;When hovered, the background color is darkened by 20%&lt;/li&gt;
&lt;li&gt;When clicked, the background color is darkened by 40%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the left-most icon, you can use any icon you like. Otherwise, use the &lt;code&gt;search&lt;/code&gt; icon from &lt;a href="http://heroicons.com"&gt;heroicons.com&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  SearchModal
&lt;/h4&gt;

&lt;p&gt;Edit SearchModal.tsx to implement the search modal according to the following requirements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changes to the input automatically updates the search results&lt;/li&gt;
&lt;li&gt;Clicking outside or selecting a search result hides the modal&lt;/li&gt;
&lt;li&gt;Users can press Tab to focus on the search result&lt;/li&gt;
&lt;li&gt;When a search result is focused, users can press Enter to select it&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Questions?
&lt;/h2&gt;

&lt;p&gt;If you run into any issues with the tutorial, please feel free to open an issue against the &lt;a href="https://github.com/rasreee/cmdk-search-tutorial-skeleton"&gt;Github repo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>emotion</category>
      <category>challenge</category>
    </item>
  </channel>
</rss>
