Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!--
  Note: ARIA requires that a grid have an accessible name.
-->
<h2 id="caption">
  Introduce the data
</h2>
<div class="scrollable" tabindex="-1">
  <div role="grid" aria-labelledby="caption">
    <div role="row" data-thead-row>
     
      <div role="columnheader" class="visually-hidden">
							<!-- the exact name for this columnheader / if this column header could not be exposed as an empty gridcell is open to discussion.  if a component like this were to allow multiple rows to be selected, a case would be made that this entire column be visible and a mixed state checkbox could be shown / interacted with in this cell -->
      	row selection
      </div>
      <div role="columnheader" class="sticky">
        Name
      </div>
      <div role="columnheader">
        Information
      </div>
    </div> <!-- /row -->


    <div role="row" data-tbody-row>
      <div role="gridcell" class="visually-hidden">
        <label>
          <input type="checkbox">
          asset 1 row
        </label>
      </div>
      <div role="rowheader" data-click>
        <a href="#">Asset 1</a>
      </div>
      <div role="gridcell" tabindex="-1" data-click>
        This asset is great. So very great.
      </div>
    </div> <!-- /row -->
    <div role="row" data-tbody-row>
      <div role="gridcell" class="visually-hidden">
        <label>
          <input type="checkbox">
          asset 2 row
        </label>
      </div>
      <div role="rowheader" data-click>
        <a href="#">Asset 2</a>
      </div>
      <div role="gridcell" tabindex="-1" data-click>
        This particular asset wants to be great. But it's just sort of ok.
      </div>
    </div> <!-- /row -->
    <div role="row" data-tbody-row>
      <div role="gridcell" class="visually-hidden">
        <label>
          <input type="checkbox">
          asset 3 row
        </label>
      </div>
      <div role="rowheader" data-click>
        <a href="#">Asset 3</a>
      </div>
      <div role="gridcell" tabindex="-1" data-click>
        This asset is horrible. Absolutely awful and you definitely do not want to learn anything more about it.
      </div>
    </div> <!-- /row -->

  </div> <!-- /grid -->
</div> <!-- scrollable -->
              
            
!

CSS

              
                body {
	font-family: arial;
	padding: 1em;
}

.scrollable {
	overflow: auto;
	max-width: 100%;
}

[role="grid"] {
	min-width: 40em;
	border-top: 1px solid;
}

[role="columnheader"],
[role="rowheader"] {
	background: #fff;
	font-weight: bold;
}

[role="columnheader"].sticky,
[role="rowheader"] {
	border-left: 1px solid;
	left: 0;
	max-width: 8em;
	position: sticky;
}


[role="row"] {
	display: flex;
	position: relative;
}

[role="row"] > div {
	flex: 1 0 0;
	padding: .5em;
	border-bottom: 1px solid;
	border-right: 1px solid;
}

.visually-hidden {
	height: 1px;
	margin-left: -4px;
	opacity: 0;
	overflow: hidden;
	padding: 0 !important;
	position: absolute;
	width: 1px;
}

*:focus {
	outline: 1px solid;
	outline-offset: 2px;
}

[role="gridcell"]:focus {
	outline-offset: -1px;
}

.scrollable[tabindex="-1"]:focus {
	outline: none;
}

a[href] {
	color: #0000DB;
}

a[href]:focus {
	text-decoration: none;
}

.is-focused,
.is-focused [role="rowheader"] {
	background: #efe;
}

.is-focused:before {
	content: '';
	height: 100%;
	left: 0;
	outline-offset: -2px;
	outline: 2px solid;
	pointer-events: none;
	position: absolute;
	top: 0;
	width: 100%;
	z-index: 3;
}

.is-checked.is-focused:before {
	outline-color: #6666FF;
}

.is-checked,
.is-checked [role="rowheader"] {
	background: #2a2a2a;
	color: #eee;
}

.is-checked a[href] {
	color:  #fff;
}
              
            
!

JS

              
                (function ( doc ) {
  const chks = doc.querySelectorAll('input[type="checkbox"]');
  const rows = doc.querySelectorAll('[data-tbody-row]');
  const cells = doc.querySelectorAll('[data-click]');
  let i;

  for ( i = 0; i < chks.length; i++ ) {
    // demo reset checks
    chks[i].checked = false;

    let thisRow = rows[i];
    chks[i].addEventListener('focus', function () {
      thisRow.classList.add('is-focused');
    });

    chks[i].addEventListener('blur', function () {
      thisRow.classList.remove('is-focused');
    });

    chks[i].addEventListener('change', function () {
      if ( this.checked === true ) {
        thisRow.classList.add('is-checked');
      }
      else {
        thisRow.classList.remove('is-checked');
      }
    });
  }

		/* 
		  add click event to a row's visible cells to allow for mouse click to check/uncheck the row's visually hidden checkbox.  ideally this would be coded in a way so as to not produce a "clickable" announcement with some screen readers - but for the purposes of this demo / overall impact, this would not be too big of a deal to have this announcement made so long as the checkbox itself remains keyboard and screen reader accessible.
		*/
  for ( i = 0; i < cells.length; i++ ) {
    const pRow = cells[i].parentElement;
    const thisCheck = pRow.querySelector('input[type="checkbox"]');

    cells[i].addEventListener('click', function () {
      thisCheck.click();
    });
  }

})(document);
              
            
!
999px

Console