<?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: Punit Soni</title>
    <description>The latest articles on Forem by Punit Soni (@punitsonime).</description>
    <link>https://forem.com/punitsonime</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%2F583222%2Fa6679169-4065-4e20-89a7-862d7ebbf124.jpeg</url>
      <title>Forem: Punit Soni</title>
      <link>https://forem.com/punitsonime</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/punitsonime"/>
    <language>en</language>
    <item>
      <title>Custom React Hook: useResizeObserver</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Thu, 01 Aug 2024 12:39:10 +0000</pubDate>
      <link>https://forem.com/punitsonime/custom-react-hook-useresizeobserver-3m8</link>
      <guid>https://forem.com/punitsonime/custom-react-hook-useresizeobserver-3m8</guid>
      <description>&lt;p&gt;In this post, I'll share a custom React hook called &lt;code&gt;useResizeObserver&lt;/code&gt;. This hook helps you observe and get the bounding client rect of a DOM element, updating the rect whenever the element is resized. It's part of my React library, &lt;code&gt;react-helper-hooks&lt;/code&gt;, which contains many useful hooks to save developers time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Source Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ObserverRect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Omit&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DOMRectReadOnly&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;toJSON&lt;/span&gt;&lt;span class="dl"&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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useResizeObserver&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;any&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setRect&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ObserverRect&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ResizeObserver&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;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boundingRect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nf"&gt;setRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;boundingRect&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="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&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="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;useResizeObserver&lt;/code&gt; hook leverages the &lt;code&gt;ResizeObserver&lt;/code&gt; API to track size changes of a DOM element. It returns a ref to be attached to the target element and the current bounding client rect of that element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example Usage
&lt;/h2&gt;

&lt;p&gt;Here's an example of how to use the &lt;code&gt;useResizeObserver&lt;/code&gt; hook in a functional component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useResizeObserver&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./useResizeObserver&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ExampleComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useResizeObserver&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
       &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;textarea&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;both&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
           Resize this element to see the changes:
       &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;textarea&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Top: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Left: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;left&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Width: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Height: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;ExampleComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, a &lt;code&gt;textarea&lt;/code&gt; element is made resizable. The &lt;code&gt;useResizeObserver&lt;/code&gt; hook tracks its dimensions, which are displayed outside the &lt;code&gt;textarea&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  About &lt;code&gt;react-helper-hooks&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;useResizeObserver&lt;/code&gt; hook is part of my React library, &lt;a href="https://npm.com/package/react-helper-hooks" rel="noopener noreferrer"&gt;react-helper-hooks&lt;/a&gt;. This library includes a collection of custom hooks designed to save developers time and effort. Hooks like &lt;code&gt;useResizeObserver&lt;/code&gt; provide reusable, efficient solutions for common tasks in React applications.&lt;/p&gt;

&lt;p&gt;Feel free to check out the library and contribute or suggest new hooks!&lt;/p&gt;




&lt;p&gt;Let me know if you need any changes or additional information!&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Follow me on X ( Twitter ) - &lt;a href="https://twitter.com/punitsonime" rel="noopener noreferrer"&gt;https://twitter.com/punitsonime&lt;/a&gt;&lt;br&gt;
Let's connect on linked in - &lt;a href="https://www.linkedin.com/in/punitsonime/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/punitsonime/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Mastering `aria-activedescendant` in HTML!</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Tue, 19 Dec 2023 06:12:36 +0000</pubDate>
      <link>https://forem.com/punitsonime/mastering-aria-activedescendant-in-html-mb6</link>
      <guid>https://forem.com/punitsonime/mastering-aria-activedescendant-in-html-mb6</guid>
      <description>&lt;p&gt;🚀✨ Elevate your web app's accessibility by understanding and implementing this powerful attribute. Let's explore together! 💻🔍 #AriaActiveDescendantThread #WebAccessibility&lt;/p&gt;




&lt;h4&gt;
  
  
  1/ 🤔 What is &lt;code&gt;aria-activedescendant&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;aria-activedescendant&lt;/code&gt; is an attribute in HTML that establishes a relationship between a widget and its currently active descendant. It's particularly useful for enhancing the accessibility of dynamic or complex user interfaces. #Accessibility #AriaActiveDescendant&lt;/p&gt;




&lt;h4&gt;
  
  
  2/ 💡 Why use &lt;code&gt;aria-activedescendant&lt;/code&gt;?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Navigation Control:&lt;/strong&gt; Facilitates navigation within complex widgets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Content:&lt;/strong&gt; Ideal for components with changing content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Screen Reader Support:&lt;/strong&gt; Improves the experience for users relying on screen readers. #A11y #WebDevelopment&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  3/ 🌐 Basic Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"listbox"&lt;/span&gt; &lt;span class="na"&gt;aria-activedescendant=&lt;/span&gt;&lt;span class="s"&gt;"option1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"option1"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"option2"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"option3"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Option 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the listbox has an active descendant (&lt;code&gt;option1&lt;/code&gt;) indicating the currently focused option. #HTML #AriaActiveDescendantExample&lt;/p&gt;




&lt;h4&gt;
  
  
  4/ 🎨 Enhancing Navigation:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
  &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;
  &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"combobox"&lt;/span&gt;
  &lt;span class="na"&gt;aria-activedescendant=&lt;/span&gt;&lt;span class="s"&gt;"suggestion1"&lt;/span&gt;
  &lt;span class="na"&gt;aria-controls=&lt;/span&gt;&lt;span class="s"&gt;"suggestions"&lt;/span&gt;
&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"suggestions"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"listbox"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"suggestion1"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Suggestion 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"suggestion2"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Suggestion 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"suggestion3"&lt;/span&gt; &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"option"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Suggestion 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a search input with suggestions, &lt;code&gt;aria-activedescendant&lt;/code&gt; assists in managing the active suggestion. #Accessibility #WebDevTips&lt;/p&gt;




&lt;h4&gt;
  
  
  5/ ⚙️ Managing Focus:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;combobox&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[role="combobox"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;combobox&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="c1"&gt;// Handle arrow keys to update aria-activedescendant&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript can be used to manage focus within the widget, updating &lt;code&gt;aria-activedescendant&lt;/code&gt; accordingly. #JavaScript #FocusManagement&lt;/p&gt;




&lt;h4&gt;
  
  
  6/ 🚀 Best Practices:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Ensure a consistent and predictable experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Updates:&lt;/strong&gt; Keep &lt;code&gt;aria-activedescendant&lt;/code&gt; in sync with the widget's state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing:&lt;/strong&gt; Verify your implementation with screen readers and keyboard navigation. #A11yTesting #BestPractices&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  7/ 🌟 Real-world Impact:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Accessible Menus:&lt;/strong&gt; Create accessible dropdown menus or suggestion lists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rich Interfaces:&lt;/strong&gt; Power dynamic and interactive components.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Legal Compliance:&lt;/strong&gt; Contribute to meeting accessibility standards. #InclusiveDesign #WebAccessibility&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  8/ 🚦 Conclusion:
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;aria-activedescendant&lt;/code&gt; is a game-changer for accessible UIs. Let's build interfaces that everyone can navigate with ease! 🌐💙 #AriaActiveDescendant #AccessibilityChampion&lt;/p&gt;




&lt;p&gt;Share your thoughts, examples, and experiences with &lt;code&gt;aria-activedescendant&lt;/code&gt; below! Let's foster an inclusive web together! 💬🌐 #WebDevCommunity #A11yAwareness&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Follow me on X ( Twitter ) - &lt;a href="https://twitter.com/punitsonime" rel="noopener noreferrer"&gt;https://twitter.com/punitsonime&lt;/a&gt;&lt;br&gt;
Let's connect on linked in - &lt;a href="https://www.linkedin.com/in/punitsonime/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/punitsonime/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>a11y</category>
    </item>
    <item>
      <title>🌐🔍 Unveiling the Power of `aria-label` in HTML!</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Mon, 18 Dec 2023 05:49:49 +0000</pubDate>
      <link>https://forem.com/punitsonime/unveiling-the-power-of-aria-label-in-html-29c</link>
      <guid>https://forem.com/punitsonime/unveiling-the-power-of-aria-label-in-html-29c</guid>
      <description>&lt;p&gt;Enhance your website's accessibility with this simple yet impactful attribute. Let's dive in! 🚀💻&lt;/p&gt;

&lt;h4&gt;
  
  
  1/ 🤔 What is &lt;code&gt;aria-label&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;aria-label&lt;/code&gt; is an attribute in HTML that provides a screen reader with a concise label, improving accessibility for users with visual impairments. It's a crucial tool for making your web content more inclusive. #AriaLabel #WebAccessibility&lt;/p&gt;

&lt;h4&gt;
  
  
  2/ 💡 Why use &lt;code&gt;aria-label&lt;/code&gt;?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Screen Reader Support:&lt;/strong&gt; Enables screen readers to announce a custom label.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Icon-Only Elements:&lt;/strong&gt; Perfect for icons or images without descriptive text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Content:&lt;/strong&gt; Useful for dynamic content updates where traditional labels might be insufficient. #AccessibilityForAll #InclusiveDesign&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3/ 🌐 Basic Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Close"&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"closePopup()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;X&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the button has an &lt;code&gt;aria-label&lt;/code&gt; providing context to screen reader users, even though the visible text is just 'X'. #HTML #AriaLabelExample&lt;/p&gt;

&lt;h4&gt;
  
  
  4/ 🎨 Customizing &lt;code&gt;aria-label&lt;/code&gt;:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Search input"&lt;/span&gt; &lt;span class="na"&gt;placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Search..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enhance user experience by combining &lt;code&gt;aria-label&lt;/code&gt; with placeholders, ensuring clarity for both visual and non-visual users. #WebDesign #AccessibilityMatters&lt;/p&gt;

&lt;h4&gt;
  
  
  5/ ⚙️ Dynamic Content Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dynamicContent"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Live update: "&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When content updates dynamically, &lt;code&gt;aria-label&lt;/code&gt; keeps screen reader users informed about the changes. Dynamically set the label as content updates. #DynamicContent #WebDevelopment&lt;/p&gt;

&lt;h4&gt;
  
  
  6/ 🚀 Best Practices:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Be Descriptive:&lt;/strong&gt; Craft labels that convey the purpose of the element.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid Redundancy:&lt;/strong&gt; Use &lt;code&gt;aria-label&lt;/code&gt; sparingly, especially if visible text already conveys the same information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testing:&lt;/strong&gt; Validate your implementation with screen reader tools for a comprehensive check. #A11yTesting #BestPractices&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  7/ 🌐 When to Use &lt;code&gt;aria-label&lt;/code&gt;:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Icons:&lt;/strong&gt; When using icon-only buttons or links.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive Elements:&lt;/strong&gt; Enhance labels for interactive elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Content:&lt;/strong&gt; Keep users informed with dynamic content. #WebDevTips #AriaLabelBestPractices&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  8/ 🌟 Real-world Impact:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Better User Experience:&lt;/strong&gt; Improved accessibility benefits all users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Legal Compliance:&lt;/strong&gt; Many regions require websites to meet certain accessibility standards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Increased User Base:&lt;/strong&gt; Attract a wider audience by making your site accessible. #WebAccessibility #InclusiveWeb&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  9/ 🚦 Conclusion:
&lt;/h4&gt;

&lt;p&gt;Implementing &lt;code&gt;aria-label&lt;/code&gt; is a small step with a big impact. Let's make the web more inclusive, one &lt;code&gt;aria-label&lt;/code&gt; at a time! 💙🌐 #AriaLabel #AccessibilityChampion&lt;/p&gt;

&lt;p&gt;Share your thoughts, experiences, and examples of &lt;code&gt;aria-label&lt;/code&gt; below! Let's learn and grow together! 🌐💬 #WebDevCommunity #AccessibilityAwareness&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Follow me on X ( Twitter ) - &lt;a href="https://twitter.com/punitsonime" rel="noopener noreferrer"&gt;https://twitter.com/punitsonime&lt;/a&gt;&lt;br&gt;
Let's connect on linked in - &lt;a href="https://www.linkedin.com/in/punitsonime/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/punitsonime/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Unleashing the Power of JavaScript Speech Synthesis! 🚀🔊</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Thu, 14 Dec 2023 05:57:09 +0000</pubDate>
      <link>https://forem.com/punitsonime/unleashing-the-power-of-javascript-speech-synthesis-516m</link>
      <guid>https://forem.com/punitsonime/unleashing-the-power-of-javascript-speech-synthesis-516m</guid>
      <description>&lt;p&gt;Hey Dev.to community! 👋 In this post, we're diving into the exciting world of JavaScript Speech Synthesis, exploring its capabilities and how you can leverage it to enhance user experiences on the web.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Speech Synthesis in JavaScript?
&lt;/h3&gt;

&lt;p&gt;JavaScript's SpeechSynthesis API allows you to convert text into spoken words, opening up a myriad of possibilities for interactive and engaging web applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;Before diving in, ensure that the Speech Synthesis API is supported in the browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;speechSynthesis&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Speech Synthesis is supported&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Handle unsupported case&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Basic Example
&lt;/h3&gt;

&lt;p&gt;Let's start with a simple function to make your web app talk:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;utterance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SpeechSynthesisUtterance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;speechSynthesis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Usage&lt;/span&gt;
&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, World!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Customizing Utterances
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;SpeechSynthesisUtterance&lt;/code&gt; object allows you to customize speech:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;utterance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SpeechSynthesisUtterance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Customizing Utterances!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Speed&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pitch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Pitch&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;volume&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Volume&lt;/span&gt;
&lt;span class="nx"&gt;speechSynthesis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Events and Callbacks
&lt;/h3&gt;

&lt;p&gt;Hook into various stages of the speech synthesis process with events:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onstart&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Speech started&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Speech ended&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Speech error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Voices and Languages
&lt;/h3&gt;

&lt;p&gt;Explore available voices and set language preferences:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;voices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;speechSynthesis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getVoices&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;utterance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;voice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;voices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;voice&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;voice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Real-World Applications
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Accessibility features&lt;/strong&gt; for visually impaired users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive chatbots&lt;/strong&gt; with spoken responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Educational platforms&lt;/strong&gt; enhancing learning experiences.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Voice-guided navigation&lt;/strong&gt; in web applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;JavaScript Speech Synthesis is a versatile tool for creating engaging and accessible web experiences. Experiment with different voices, speeds, and pitches to craft unique interactions!&lt;/p&gt;

&lt;h3&gt;
  
  
  Further Reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MDN Web Docs: SpeechSynthesis&lt;/li&gt;
&lt;li&gt;"HTML5 Web Speech API" by Tony Lea&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Share your thoughts and experiences with Speech Synthesis in JavaScript below! 🔊💬 #JavaScript #WebDev #SpeechSynthesis&lt;/p&gt;

&lt;h4&gt;
  
  
  X ( Twitter ) - &lt;a href="https://twitter.com/PunitSoniME" rel="noopener noreferrer"&gt;https://twitter.com/PunitSoniME&lt;/a&gt;
&lt;/h4&gt;




</description>
      <category>javascript</category>
      <category>speechsynthesis</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Demystifying JavaScript Property Descriptors: A Deep Dive</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Thu, 17 Aug 2023 08:37:37 +0000</pubDate>
      <link>https://forem.com/punitsonime/demystifying-javascript-property-descriptors-a-deep-dive-1ncc</link>
      <guid>https://forem.com/punitsonime/demystifying-javascript-property-descriptors-a-deep-dive-1ncc</guid>
      <description>&lt;p&gt;Hello, fellow developers! 🚀 Have you ever encountered the term "property descriptor" in JavaScript and wondered what it actually means and how it impacts your code? In this post, we're going to take a deep dive into the world of JavaScript property descriptors, demystifying their significance and shedding light on how they can be leveraged to wield greater control over your objects' properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Property Descriptors:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In JavaScript, every object property is associated with a set of attributes that define its behavior. These attributes collectively form what is known as a &lt;strong&gt;property descriptor&lt;/strong&gt;. A property descriptor comprises the following attributes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Value:&lt;/strong&gt; The actual value of the property.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Writable:&lt;/strong&gt; A boolean indicating whether the property's value can be changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enumerable:&lt;/strong&gt; A boolean indicating whether the property can be iterated over in a loop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configurable:&lt;/strong&gt; A boolean indicating whether the property's attributes can be modified and the property can be deleted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Creating Property Descriptors:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Property descriptors can be created using the &lt;code&gt;Object.defineProperty()&lt;/code&gt; method or the &lt;code&gt;Object.defineProperties()&lt;/code&gt; method for defining multiple properties at once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;

&lt;span class="c1"&gt;// Using Object.defineProperty()&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Punit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;enumerable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;configurable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use Cases and Advantages:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Controlled Immutability:&lt;/strong&gt; By setting the &lt;code&gt;writable&lt;/code&gt; attribute to &lt;code&gt;false&lt;/code&gt;, you can create properties that cannot be reassigned, effectively enforcing immutability for certain parts of your objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hidden Properties:&lt;/strong&gt; Properties with the &lt;code&gt;enumerable&lt;/code&gt; attribute set to &lt;code&gt;false&lt;/code&gt; won't show up when using methods like &lt;code&gt;Object.keys()&lt;/code&gt; or &lt;code&gt;for...in&lt;/code&gt; loops, providing a way to hide internal implementation details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Protection Against Modification:&lt;/strong&gt; The &lt;code&gt;configurable&lt;/code&gt; attribute can be set to &lt;code&gt;false&lt;/code&gt; to prevent accidental modification or deletion of properties, adding an extra layer of security to your objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Getters and Setters:&lt;/strong&gt; Property descriptors are essential when creating properties with custom getters and setters, enabling you to add custom logic whenever a property is accessed or modified.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Object Sealing and Freezing:&lt;/strong&gt; You can use property descriptors along with &lt;code&gt;Object.seal()&lt;/code&gt; and &lt;code&gt;Object.freeze()&lt;/code&gt; to control the level of modification allowed for an object and its properties.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Example Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider a scenario where you're building a class to manage user data. You want to ensure that the user's ID remains unchangeable, their password is hidden, and the data can't be tampered with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;writable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;enumerable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;configurable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;secretpassword&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: 123&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JavaScript property descriptors provide a powerful mechanism for fine-tuning the behavior of object properties. By manipulating attributes like &lt;code&gt;writable&lt;/code&gt;, &lt;code&gt;enumerable&lt;/code&gt;, and &lt;code&gt;configurable&lt;/code&gt;, you can tailor the properties to your exact needs. Whether you're aiming for controlled immutability, data hiding, or enhanced security, property descriptors offer a way to achieve these goals while maintaining flexibility and control in your code.&lt;/p&gt;

&lt;p&gt;Give property descriptors a try in your next JavaScript project, and unlock a whole new level of control over your objects' properties! If you have questions or insights to share, feel free to drop them in the comments below. Happy coding! 💻🔑&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stay curious and keep exploring the fascinating world of JavaScript!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Custom React Hook: useIsAppOffline</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Sun, 13 Aug 2023 10:31:05 +0000</pubDate>
      <link>https://forem.com/punitsonime/building-a-custom-react-hook-useisappoffline-1i5d</link>
      <guid>https://forem.com/punitsonime/building-a-custom-react-hook-useisappoffline-1i5d</guid>
      <description>&lt;p&gt;Hey fellow developers! 👋 Let's dive into creating a handy custom React hook that can help you easily determine whether your app is offline or online. We'll call it useIsAppOffline. Whether you're building a progressive web app, a mobile application using React Native, or a traditional web app, this custom hook can be a lifesaver when it comes to handling different network states.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;useIsAppOffline&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isAppOffline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsAppOffline&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onLine&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setIsAppOffline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;offline&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setIsAppOffline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;isAppOffline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How It Works:
&lt;/h3&gt;

&lt;p&gt;This custom hook, &lt;code&gt;useIsAppOffline&lt;/code&gt;, leverages the &lt;code&gt;useState&lt;/code&gt; hook from React to manage the state of whether your app is offline or online. It starts by setting the initial state based on the value of &lt;code&gt;navigator.onLine&lt;/code&gt;, which indicates if the user's device is currently connected to the internet.&lt;/p&gt;

&lt;p&gt;The hook then adds event listeners to the window object for the online and offline events. These events are triggered whenever the network status changes. When the app transitions from an offline to an online state, the online event is fired, and we update the state to reflect that the app is online. Similarly, when the app goes from online to offline, the offline event is triggered, and we update the state to indicate that the app is offline.&lt;/p&gt;

&lt;p&gt;By using this custom hook in your components, you can easily react to changes in the app's network status and provide appropriate user feedback or take specific actions based on the network state.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useIsAppOffline&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./useIsAppOffline&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isOffline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useIsAppOffline&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isOffline&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Your app is currently offline.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Your app is online and ready to go!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Benefits:
&lt;/h2&gt;

&lt;p&gt;Simplicity: The &lt;code&gt;useIsAppOffline&lt;/code&gt; hook abstracts away the complexities of monitoring the network status, making it easy to integrate into your application.&lt;/p&gt;

&lt;p&gt;Reactivity: Your UI will instantly respond to changes in network connectivity, enhancing the user experience.&lt;/p&gt;

&lt;p&gt;Customization: You can easily extend the hook to implement additional functionality, such as triggering actions on network state changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;In this post, we've explored the creation of a custom React hook, &lt;code&gt;useIsAppOffline&lt;/code&gt;, which helps you keep track of your app's network status. By encapsulating this functionality into a hook, you can effortlessly handle different network states and provide a more seamless experience for your users. Feel free to integrate this hook into your projects and enhance the way your apps respond to changing network conditions!&lt;/p&gt;

&lt;h2&gt;
  
  
  Use cases
&lt;/h2&gt;

&lt;p&gt;The useIsAppOffline hook can be incredibly useful in a variety of scenarios where you need to respond to changes in network connectivity. Here are some use cases where this custom hook could come in handy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Offline Indicator:&lt;br&gt;
Display a visual indicator to users when your application goes offline, helping them understand that their device has lost connectivity. This can prevent confusion and frustration, as users will know that the lack of data is due to network issues rather than a problem with your app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Data Syncing:&lt;br&gt;
If your app involves data synchronization with a server, you can use the &lt;code&gt;useIsAppOffline&lt;/code&gt; hook to pause or delay data syncing when the app goes offline. This prevents unnecessary attempts to sync data when the network is unavailable, reducing potential conflicts or errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Form Handling:&lt;br&gt;
When users are filling out forms, you can disable certain functionality or provide warnings when the app is offline. For example, you might prevent users from submitting forms until connectivity is restored or display a message explaining that their form data will be submitted once the app is online again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Caching Strategies:&lt;br&gt;
If your app relies on caching data for offline access, you can use the hook to determine whether to use cached data or fetch fresh data from the network. This can help improve the user experience by providing some level of functionality even when the app is offline.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Real-time Collaboration:&lt;br&gt;
In collaborative applications, you can temporarily disable certain real-time features (like live chat or collaborative editing) when the app goes offline. This prevents data inconsistencies and ensures a smooth experience once connectivity is restored.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Background Tasks:&lt;br&gt;
Some apps perform background tasks, such as fetching notifications or updates while in the background. You can utilize the hook to manage when these tasks should be paused or resumed based on network availability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Progressive Web Apps (PWAs):&lt;br&gt;
For Progressive Web Apps, the &lt;code&gt;useIsAppOffline&lt;/code&gt; hook can help manage the transition from offline to online mode. You might want to display a message indicating that the app is ready for offline use when the user goes offline, and then update the UI when the app reconnects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error Handling:&lt;br&gt;
When network requests fail due to lack of connectivity, you can handle those errors gracefully by showing a user-friendly message and providing options for retrying the request once the app is back online.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few examples of how the &lt;code&gt;useIsAppOffline&lt;/code&gt; hook can be applied in different scenarios. By encapsulating network status monitoring into a custom hook, you can easily adapt your app to various network conditions, enhancing user experience and preventing potential issues caused by connectivity fluctuations.&lt;/p&gt;

&lt;p&gt;Give it a try and let me know how it works for you. Happy coding! 💻🚀&lt;/p&gt;

&lt;p&gt;Have questions or suggestions? Drop them in the comments below!&lt;/p&gt;

</description>
      <category>react</category>
      <category>hook</category>
      <category>javascript</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Enhancing Accessibility of HTML Text Input Elements with ARIA Attributes</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Thu, 04 May 2023 10:36:26 +0000</pubDate>
      <link>https://forem.com/punitsonime/enhancing-accessibility-of-html-text-input-elements-with-aria-attributes-1d1a</link>
      <guid>https://forem.com/punitsonime/enhancing-accessibility-of-html-text-input-elements-with-aria-attributes-1d1a</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Learn how to improve the accessibility of text input elements in HTML by using ARIA attributes. This article covers various ARIA attributes that can be used to make text input elements more accessible, including aria-label, aria-labelledby, aria-describedby, aria-required, and more. By implementing these attributes, you can make your web forms and applications more inclusive and accessible to users with disabilities.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  1. aria-label:
&lt;/h3&gt;

&lt;p&gt;This property can be used to provide a label for the input element, which can be read by screen readers. It should be used when a visible label cannot be provided.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-label=&lt;/span&gt;&lt;span class="s"&gt;"Enter your name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2. aria-labelledby:
&lt;/h3&gt;

&lt;p&gt;This property can be used to associate the input element with a label in the page, which can be read by screen readers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter your name:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;aria-labelledby=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. aria-describedby:
&lt;/h3&gt;

&lt;p&gt;This property can be used to associate the input element with additional descriptive text, such as a hint or a help message.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-describedby=&lt;/span&gt;&lt;span class="s"&gt;"name-help"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"name-help"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Enter your full name, including your last name.&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  4. aria-invalid:
&lt;/h3&gt;

&lt;p&gt;This property can be used to indicate whether the input value is invalid.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;required&lt;/span&gt; &lt;span class="na"&gt;aria-invalid=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="na"&gt;aria-describedby=&lt;/span&gt;&lt;span class="s"&gt;"error-message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"validation-message"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This field is required&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  5. aria-autocomplete:
&lt;/h3&gt;

&lt;p&gt;This property can be used to specify whether the input should provide suggestions, and what type of suggestions should be provided.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-autocomplete=&lt;/span&gt;&lt;span class="s"&gt;"list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  6. aria-expanded:
&lt;/h3&gt;

&lt;p&gt;This property can be used to indicate whether the input's associated dropdown or list is expanded or collapsed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-controls=&lt;/span&gt;&lt;span class="s"&gt;"dropdownList"&lt;/span&gt; &lt;span class="na"&gt;aria-expanded=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"dropdownList"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Option 1&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Option 2&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Option 3&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  7. aria-required:
&lt;/h3&gt;

&lt;p&gt;This attribute can be used to indicate that the input is required, and that a value must be provided by the user.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-required=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  8. aria-placeholder:
&lt;/h3&gt;

&lt;p&gt;This attribute can be used to provide a hint or an example value for the input element.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-placeholder=&lt;/span&gt;&lt;span class="s"&gt;"Enter your email address"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  9. aria-controls:
&lt;/h3&gt;

&lt;p&gt;This attribute can be used to associate the input element with a related element, such as a dropdown or a list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-controls=&lt;/span&gt;&lt;span class="s"&gt;"emailSuggestions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"emailSuggestions"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;example1@example.com&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;example2@example.com&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;example3@example.com&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  10. aria-selected:
&lt;/h3&gt;

&lt;p&gt;This attribute can be used to indicate whether an option in a list or a dropdown is currently selected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-controls=&lt;/span&gt;&lt;span class="s"&gt;"colorList"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"colorList"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;aria-selected=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Red&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Green&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Blue&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  11. aria-disabled:
&lt;/h3&gt;

&lt;p&gt;This attribute can be used to indicate that the input element is disabled and cannot be interacted with.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;aria-disabled=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;These ARIA attributes can help improve the accessibility of input elements by providing additional information to assistive technologies such as screen readers and also help improve the accessibility of text input elements, making it easier for users with disabilities to understand and interact with them.&lt;/p&gt;




&lt;h3&gt;
  
  
  Follow me on
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://twitter.com/PunitSoniME" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/PunitSoniME" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/PunitSoniME" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>html</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Make Your Website More Accessible with prefers-reduced-motion</title>
      <dc:creator>Punit Soni</dc:creator>
      <pubDate>Tue, 02 May 2023 09:54:52 +0000</pubDate>
      <link>https://forem.com/punitsonime/how-to-make-your-website-more-accessible-with-prefers-reduced-motion-do3</link>
      <guid>https://forem.com/punitsonime/how-to-make-your-website-more-accessible-with-prefers-reduced-motion-do3</guid>
      <description>&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;If you're building websites or web applications, it's important to make sure that everyone can use them, regardless of any accessibility challenges they may face. One accessibility issue that can affect some users is motion sickness or discomfort caused by animations and other motion effects on the page. That's where &lt;code&gt;prefers-reduced-motion&lt;/code&gt; comes in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding &lt;code&gt;prefers-reduced-motion&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;prefers-reduced-motion&lt;/code&gt; is a media query that can be used in CSS to detect whether the user has requested reduced motion on their device or browser. The possible values for &lt;code&gt;prefers-reduced-motion&lt;/code&gt; are no-preference and reduce. If the user has requested reduced motion, any animations or other motion effects on the page should be disabled or scaled back.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use &lt;code&gt;prefers-reduced-motion&lt;/code&gt; in CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-reduced-motion&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Disable or scale back animations and motion effects */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Examples of &lt;code&gt;prefers-reduced-motion&lt;/code&gt; in action
&lt;/h3&gt;

&lt;p&gt;Here are some examples of how you can use &lt;code&gt;prefers-reduced-motion&lt;/code&gt; to create a more accessible user experience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you have a slideshow or carousel on your page, you can disable automatic animation when &lt;code&gt;prefers-reduced-motion&lt;/code&gt; is set to reduce, so that the user can manually advance the slides without being bombarded with automatic motion effects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have a navigation menu that slides in and out of view, you can disable the sliding animation when &lt;code&gt;prefers-reduced-motion&lt;/code&gt; is set to reduce, so that the menu appears instantly without any motion effects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you have a hover effect on your links or buttons, you can disable the effect or change it to a more subtle effect when &lt;code&gt;prefers-reduced-motion&lt;/code&gt; is set to reduce, so that the user doesn't experience any sudden or distracting motion.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://codepen.io/PunitSoniME/pen/BaqwYQj" rel="noopener noreferrer"&gt;prefers-reduced-motion demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see the smooth scroll animation if you operating system's Animation is enabled.&lt;br&gt;
If you disable the operating system's Animation, smooth scrolling will no longer visible&lt;/p&gt;

&lt;p&gt;&lt;a href="https://support.microsoft.com/en-us/office/turn-off-office-animations-9ee5c4d2-d144-4fd2-b670-22cef9fa025a" rel="noopener noreferrer"&gt;Enable Disable Animation in Windows&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;By using &lt;code&gt;prefers-reduced-motion&lt;/code&gt; in your CSS, you can make your website or web application more inclusive and accessible to users who may experience discomfort or motion sickness from animations and other motion effects. It's a simple but powerful tool that can help you create a more welcoming and inclusive online experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Follow me on
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://twitter.com/PunitSoniME" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/PunitSoniME" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/PunitSoniME" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>programming</category>
      <category>webdev</category>
      <category>css</category>
    </item>
  </channel>
</rss>
