Skip to content

Instantly share code, notes, and snippets.

@ericwbailey
Last active March 30, 2023 19:10
Show Gist options
  • Save ericwbailey/e1009c1ad6ca9b4851bb49609824094e to your computer and use it in GitHub Desktop.
Save ericwbailey/e1009c1ad6ca9b4851bb49609824094e to your computer and use it in GitHub Desktop.
Transcription of ChatGPT output for two prompts.

ChatGPT: Hi there! How can I help you? (try the Inspire Me button for ideas!)

User: Write the code for a tabbed user interface that uses HTML, JavaScript, and CSS.

ChatGPT: I'll provide you with a template that you can use to create a tabbed user interface utilizing HTML, JavaScript and CSS.

<html>
  <head>
    <style>
      /* CSS styles for the tabbed interface */
    </style>
  </head>
  <body>
    <div id="tabbed-interface">
      <ul>
        <li class="tab active-tab" onclick="activateTab(1)">Tab 1</li>
        <li class="tab" onclick="activateTab(2)">Tab 2</li>
        <li class="tab" onclick="activateTab(3)">Tab 3</li>
      </ul>
      <div id="tab-content-1" class="tab-content active-tab-content">
        <!-- tab 1 content -->
      </div>
      <div id="tab-content-2" class="tab-content">
        <!-- tab 2 content -->
      </div>
      <div id="tab-content-3" class="tab-content">
        <!-- tab 3 content -->
      </div>
    </div>
    <script>
      function activateTab(tabNumber) {
        var tabLinks = document.querySelectorAll(".tab");
        tabLinks.forEach(function(tabLink){
          tabLink.classList.remove("active-tab");
        });
        var tabContent = document.querySelectorAll(".tab-content");
        tabContent.forEach(function(tabDiv){
          tabDiv.classList.remove("active-tab-content");
        });

        var activeTabLink = document.querySelector("li.tab:nth-of-type(" + tabNumber + ")");
        activeTabLink.classList.add("active-tab");
        var activeTabContent = document.querySelector("div#tab-content-" + tabNumber);
        activeTabContent.classList.add("active-tab-content");
      }
    </script>
  </body>
</html>

This is a basic template that vou can build upon. You will need to add the appropriate content in the

Notification banner: Only returning partial result, type "continue" to receive the rest of response message

User: continue

ChatGPT: tab content sections and adjust the styles to suit your needs. Keep in mind that this is just a starting point and there are many ways to customize and enhance a tabbed user interface. Let me know if vou have any questions or need any help.

ChatGPT: Hi there! How can I help you? (try the Inspire Me button for ideas!)

User: Write the code for an accessible tabbed user interface that uses HTML, JavaScript, and CSS.

ChatGPT: I would be happy to help you with that! Here's some sample code to get you started:

<div class="tabbed-interface">
  <div class="tabs">
    <button class="tab" data-tab-target="tab-1">Tab 1</button>
    <button class="tab" data-tab-target="tab-2">Tab 2</button>
    <button class="tab" data-tab-target="tab-3">Tab 3</button>
  </div>
  <div class="tabbed-content">
    <div class="tab-content" id="tab-1">
      <!-- Content for Tab 1 -->
    </div>
    <div class="tab-content" id="tab-2">
      <!-- Content for Tab 2 -->
    </div>
    <div class="tab-content" id="tab-3">
      <!-- Content for Tab 3 -->
    </div>
  </div>
</div>
const tabLinks = document.querySelectorAll('.tab-link');
const tabContents = document.querySelectorAll('.tab-content');

function switchTab(e) {
  // Remove active class from all tab links
  tabLinks.forEach(link => link.classList.remove('active'));
  // Add active class to the clicked tab link
  e.target.classList.add('active');
  
  // Remove active class from all tab contents
  tabContents.forEach(content => content.classList.remove('active'));
  // Add active class to the corresponding tab content
  document.querySelector(`#${e.target.data-tab}`).classList.add('active');
}
tabs {
  display: flex;
  flex-wrap: wrap;
}

.tab-link {
  padding: 8px;
  border: 1px solid #ccc;
  background-color: #f1f1f1;
  margin-right: 10px;
  text-align: center;
  cursor: pointer;
}

.tab-link.active {
  border-bottom: none;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}





body {
  margin: 3rem;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

You'll notice that the HTML structure is pretty simple: there is a div with a class of "tabbed-interface" that wraps everything, then within that there are two divs: one for the tabs and one for the tab content. Each tab button has a "data-tab-target" attribute that corresponds to the id of the tab content div.

In the CSS, you can style both the tabs and tabbed content as needed.

In the JavaScript, you will want to add an event listener to each tab button so that when the button is clicked, it activates the corresponding tab content and deactivates the other tabs. To make the tabs keyboard accessible, you will also want to ensure that Tab and Shift+Tab keys can be used to cycle through the tabs, and the Enter key is used to activate the active tab. For a more detailed explanation and assistance with the JavaScript, you may want

Notification banner: Only returning partial result, type "continue" to receive the rest of response message

User: continue

ChatGPT: to consult with a developer or look up tutorials on accessible tab interfaces using JavaScript. Keep in mind that you can use different techniques to improve accessibility and make sure the tabbed interface is understandable for assistive technology users. For example, you can use the 'aria-role" and 'aria-label' attributes to provide additional information to assistive technologies.

Additionally, you can also use CSS to hide the tab content by default and then show it only when the corresponding tab button is active. This will ensure that the tab content is not visible to screen readers or other assistive technologies until the user interacts with the interface.

I hope this helps! Let me know if there's anything else I can assist you with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment