<?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>Forem: Sebastian Kurpiel</title>
    <description>The latest articles on Forem by Sebastian Kurpiel (@sebastiankurp).</description>
    <link>https://forem.com/sebastiankurp</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%2F289807%2F58b9e0a7-d16c-4162-87cc-ccc8214e1be1.png</url>
      <title>Forem: Sebastian Kurpiel</title>
      <link>https://forem.com/sebastiankurp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sebastiankurp"/>
    <language>en</language>
    <item>
      <title>Getting rid of ugly scrollbars using Overlayscrollbars</title>
      <dc:creator>Sebastian Kurpiel</dc:creator>
      <pubDate>Fri, 21 Feb 2020 22:54:37 +0000</pubDate>
      <link>https://forem.com/sebastiankurp/getting-rid-of-ugly-scrollbars-using-overlayscrollbars-21i</link>
      <guid>https://forem.com/sebastiankurp/getting-rid-of-ugly-scrollbars-using-overlayscrollbars-21i</guid>
      <description>&lt;p&gt;At &lt;a href="https://draftbit.com/" rel="noopener noreferrer"&gt;Draftbit&lt;/a&gt; we were running into an issue where when a user plugged in a mouse into their machine, any scrollable content would render with the default styled macOS scrollbars. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fedfsy9kj61rx39n6ljo1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fedfsy9kj61rx39n6ljo1.png" alt="MacOS scrollbars when mouse is plugged in"&gt;&lt;/a&gt;&lt;br&gt;
As you can tell, that's not the prettiest look and the scrollbars take up a bit of space in their div. The situation on windows machines wasn't any better as scrollbars are always rendered no matter what.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl7vmngbztidvd224igtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fl7vmngbztidvd224igtg.png" alt="Windows scrollbars always rendering oof"&gt;&lt;/a&gt;&lt;br&gt;
The quick and easy solution is to use &lt;code&gt;css&lt;/code&gt;,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 css
.scrollBar { //Needed for Mozilla when applying overflow:scroll or auto
  scrollbar-width: none;
}
::-webkit-scrollbar { //Needed for Chrome and Safari
  width: 0px;
}

::-webkit-scrollbar-track-piece {
  background-color: transparent;
  -webkit-border-radius: 6px;
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8ekepufdtwfe15a20o2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8ekepufdtwfe15a20o2d.png" alt="No scrollbars rendered"&gt;&lt;/a&gt;&lt;br&gt;
This will remove the scrollbars and still allow for scrolling, however it removes the indicator showing the user how far they have scrolled. This causes issues with accessibility and isn't the route we wanted to go.&lt;/p&gt;

&lt;p&gt;After discussing possibilities including scroll hijacking we settled on using &lt;a href="https://kingsora.github.io/OverlayScrollbars/#!overview" rel="noopener noreferrer"&gt;OverlayScrollbars&lt;/a&gt;, a library which hides native scrollbars and replaces them with styleable overlay scrollbars.&lt;/p&gt;

&lt;p&gt;To integrate we did the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a wrapper component, &lt;code&gt;ScrollContainer&lt;/code&gt;, which uses Overlayscrollbars' &lt;code&gt;OverlayScrollbarsComponent&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;apply the appropriate styles to the component, for us the &lt;code&gt;os-theme-dark&lt;/code&gt; was perfect for the dark theme of our builder.&lt;/li&gt;
&lt;li&gt;apply options to achieve the scrollbar behaviour that we needed, for our needs we wanted the scrollbars to hide when the user was not scrolling so we enable &lt;code&gt;autohide&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;we then searched the entire app to find where we were using &lt;code&gt;overflow:auto&lt;/code&gt; or &lt;code&gt;overflow:scroll&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;if found we would replace that &lt;code&gt;div&lt;/code&gt; with &lt;code&gt;ScrollConatiner&lt;/code&gt; and apply the proper tailwind classNames.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzy6sy20avog56pk5a4qk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzy6sy20avog56pk5a4qk.gif" alt="OverlayScrollbars, no scrollbars"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And &lt;strong&gt;BOOM&lt;/strong&gt;,like that, Draftbit was free of those ugly scrollbars and in their place were some sleek scrollbars that work and look good. If you enjoy making apps look good and want to enter the no-code space, &lt;a href="https://draftbit.com/about#jobs" rel="noopener noreferrer"&gt;Draftbit&lt;/a&gt; is hiring! Come check out how we're making app-building accessible to everyone!&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 js
import * as React from "react";
import { OverlayScrollbarsComponent } from "overlayscrollbars-react";

const ScrollContainer = ({ className, children }) =&amp;gt; {
  return (
    &amp;lt;OverlayScrollbarsComponent
      className={"os-theme-dark " + className}
      options={{ scrollbars: { autoHide: "scroll" } }}&amp;gt;
      {children}
    &amp;lt;/OverlayScrollbarsComponent&amp;gt;
  );
};

export default ScrollContainer;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 js 
import * as React from "react";
import ScrollContainer from "/ScrollContainer"

const PanelThatNeedsToBeScrollable = () =&amp;gt; {
  return (
    &amp;lt;ScrollContainer className="p-4 mt-4"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;span className="tallerThanHeightOfScreen"&amp;gt; I'm so tall that my content needs to scroll!!! &amp;lt;/span&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/ScrollContainer&amp;gt;
}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>design</category>
      <category>howto</category>
    </item>
    <item>
      <title>Capturing a click outside a Reason-React Component</title>
      <dc:creator>Sebastian Kurpiel</dc:creator>
      <pubDate>Fri, 14 Feb 2020 04:34:42 +0000</pubDate>
      <link>https://forem.com/sebastiankurp/capturing-a-click-outside-a-reason-react-component-cp7</link>
      <guid>https://forem.com/sebastiankurp/capturing-a-click-outside-a-reason-react-component-cp7</guid>
      <description>&lt;p&gt;I found myself the other day trying to build a dropdown component in Reason that on outside click would close the menu if opened.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ka3i4froq1enekjj26z.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ka3i4froq1enekjj26z.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only example I could find of this was in Reason from &lt;a href="https://github.com/glennsl/rescratch/blob/master/src/common/OnClickOutside.re" rel="noopener noreferrer"&gt;GlennSL&lt;/a&gt; and it was a bit outdated since it was written in 2018, before hooks were fully implemented into reason. The code below is an updated version using hooks, it requires the &lt;code&gt;bs-dependency&lt;/code&gt; of &lt;code&gt;bs-webapi&lt;/code&gt; so make sure to add that before you use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight reasonml"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;genType&lt;/span&gt; &lt;span class="s2"&gt;"OnClickOutside"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;react&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;make&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;onOutsideClick&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;outsideContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Js&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Nullable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nn"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;useEffect0&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;open&lt;/span&gt; &lt;span class="nn"&gt;Webapi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dom&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;onClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;MouseEvent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;outsideDiv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nn"&gt;Belt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getExn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nn"&gt;Js&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Nullable&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;toOption&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;outsideContainer&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;targetElement&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;EventTarget&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;unsafeAsElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nn"&gt;Element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;targetElement&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;outsideDiv&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;onOutsideClick&lt;/span&gt;&lt;span class="bp"&gt;()&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nn"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addClickEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nn"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;removeClickEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;outsideContainer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nn"&gt;ReactDOMRe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nn"&gt;Ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;domRef&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;children&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The logic breakdown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;wrap the component in a div with a ref&lt;/li&gt;
&lt;li&gt;add an event listener for onClick&lt;/li&gt;
&lt;li&gt;in that onClick function check whether the element clicked contains the div with the ref, if it does then the click is inside the div. If not then the click is outside of the div.&lt;/li&gt;
&lt;li&gt;If the click is outside of the container then do whatever you need it to(in this case above, close the menu)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the use case above we wrap our select component in the &lt;code&gt;OnClickOutside&lt;/code&gt; and onOutsideClick close the dropdown menu container like so;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight reasonml"&gt;&lt;code&gt;  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setVisibility&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OnClickOutside&lt;/span&gt; &lt;span class="n"&gt;onOutsideClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;_e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;setVisibility&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nn"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;
          &lt;span class="n"&gt;toggled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt; &lt;span class="n"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;_e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;setVisibility&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt; 
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nn"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="n"&gt;toggled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;visible&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;OnClickOutside&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you enjoy writing Reason and would like to write more of it, you're in luck. Draftbit is &lt;a href="https://draftbit.com/about#jobs" rel="noopener noreferrer"&gt;hiring&lt;/a&gt;, we're a no-code tool that let's users build cross-platform apps and we're built mostly in reason! Check us out!&lt;/p&gt;

&lt;h3&gt;
  
  
  UPDATE:
&lt;/h3&gt;

&lt;p&gt;I was experiencing some state issues with the trigger so I added an extra useEffect to fix this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
[@genType "OverlayTrigger"]
[@react.component]
let make = (~onClick, ~children) =&amp;gt; {
  let outsideContainer = React.useRef(Js.Nullable.null);
  open Webapi.Dom;
  let onClickHandler = event =&amp;gt; {
    let target = MouseEvent.target(event);
    let outsideDiv =
      Belt.Option.getExn(
        Js.Nullable.toOption(React.Ref.current(outsideContainer)),
      );
    let targetElement = EventTarget.unsafeAsElement(target);
    if (!Element.contains(targetElement, outsideDiv)) {
      onClick();
    };
  };

  React.useEffect2(
    () =&amp;gt; {
      Document.addMouseDownEventListener(onClickHandler, document);
      Some(
        () =&amp;gt; Document.removeMouseDownEventListener(onClickHandler, document),
      );
    },
    (onClick, React.Ref.current(outsideContainer)),
  );

  &amp;lt;div
    className="cursor-pointer w-full"
    ref={outsideContainer-&amp;gt;ReactDOMRe.Ref.domRef}&amp;gt;
    children
  &amp;lt;/div&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>reason</category>
      <category>react</category>
      <category>tutorial</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
