some common web patterns
see:
html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
html {
font-family: Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console",
"Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono",
"Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier,
monospace;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
html {
-webkit-text-size-adjust: 100%;
}
mobile – prevent zooming on double-tap
button {
touch-action: manipulation;
}
button,
input,
textarea,
select {
font: inherit;
color: currentColor;
text-align: inherit;
}
.font-smoothing {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.module {
overflow-y: scroll; /* has to be scroll, not auto */
-webkit-overflow-scrolling: touch;
}
hidden and accessible
.hidden-accessible {
border: 0 !important;
clip: rect(0 0 0 0) !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
}
accessible focus ring (enabled by tabbing with a keyboard)
body:not(.user-is-tabbing) {
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
outline: none;
}
}
function handleFirstTab(e) {
if (e.keyCode === 9) {
// the "I am a keyboard user" key
document.body.classList.add(`user-is-tabbing`);
window.removeEventListener(`keydown`, handleFirstTab, { passive: true });
}
}
window.addEventListener(`keydown`, handleFirstTab);
[...new Set(myArray)];
function defer() {
var res, rej;
var promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
promise.resolve = res;
promise.reject = rej;
return promise;
}