Skip to content

Documentation is a bit thin #154

Open
@mslinn

Description

I wrote this example to show how to style tabs and programmatically open them.

<html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jsuites/dist/jsuites.min.css" type="text/css" />
    <style>
      body {
        background-color: rgba(242, 215, 158, 0.55);
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        font-size: 16px;
        margin-left: 100px;
        margin-top: 2em;
        width: 800px;
      }

      .jtabs-content {
        background-color: #F7E8B4;
        border: 2px solid rgba(102, 102, 102, 0.226);
        border-radius: 0 8px 8px 8px;
        padding: 10px;
      }

      .jtabs .jtabs-headers {
        div {
          border-color: rgba(102, 102, 102, 0.226);
          border-style: solid;
          border-width: 1px 1px 0 1px;
          border-top-left-radius: 6px;
          border-top-right-radius: 6px;
          margin-left: 6px;
        }

        div:not(.jtabs-selected) {
          background-color: rgba(216, 162, 1, 0.184);
          color: rgba(102, 102, 102, .8);
        }

        div.jtabs-selected {
          background-color: rgba(216, 162, 1, 0.479);
          color: black;
        }
      }
    </style>
  </head>
  <body>
    <h1>Tab Test</h1>
    <div class="jtabs">
      <div id="jtabs-headers">
        <div id="jtabs1">Tab 1</div>
        <div id="jtabs2">Tab 2</div>
        <div id="jtabs3">Tab 3</div>
      </div>
      <div id="jtabs-content">
        <div>
          This is tab 1.
        </div>
        <div>
          This is tab 2.
        </div>
        <div>
          This is tab 3.
        </div>
      </div>
    </div>
  </body>

  <script defer src="https://cdn.jsdelivr.net/npm/jsuites/dist/jsuites.min.js"></script>
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      jtabs = jSuites.tabs(document.getElementsByClassName('jtabs')[0]);

      // The following two statements accomplish the same task: open tab 2
      // jtabs.open(1); // origin 0
      //jtabs.selectIndex(document.getElementById("jtabs2"));

      // The following opens tab2 if the URL ends with #jtabs2
      const desiredTab = window.location.hash.split('#')[1];
      if (typeof desiredTab !== 'undefined')
        jtabs.selectIndex(document.getElementById(desiredTab));
    });
  </script>
</html>

See also:

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions