Skip to content

Instantly share code, notes, and snippets.

Avatar

EJ Mason mxmason

View GitHub Profile
@fpapado
fpapado / README.md
Last active Jun 22, 2021
:focus-visible progressive enhancement mixin
View README.md

Find the full post on fotis.xyz

:focus-visible is a standard way of only showing focus styles for keyboard and focus-based modalities. When using it, however, you must take care to not remove :focus altogether, where :focus-visible is not supported.

With CSS, we can achieve progressive enhancement of :focus to :focus-visible:

/* Styles where only focus is supported */
button:focus,
@pizzarob
pizzarob / xhr.js
Created Aug 21, 2016
Helper Functions for Making XHR Requests in JavaScript
View xhr.js
function post(url, data) {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.addEventListener('load', () => {
let { response, status } = xhr;
let res = JSON.parse(response);
if(status >= 200 && status < 400){