Skip to content

Instantly share code, notes, and snippets.

View rushkeldon's full-sized avatar

Keldon Rush rushkeldon

View GitHub Profile
@rushkeldon
rushkeldon / _useA11yKeysClick.ts
Last active May 6, 2025 21:43
A hook to enable keyboard handling on non-interactive elements that are made interactive.
import { useCallback } from 'react';
function isElementDisabled(el: HTMLElement): boolean {
return (
el.hasAttribute('disabled') ||
el.getAttribute('aria-disabled') === 'true' ||
el.getAttribute('data-disabled') === 'true'
);
}
/**
* Ephemeral Element Capture & Injection
*
* Usage:
* ephemera.startObserving();
* ephemera.trace(); // to see the captured HTML in the console
* ephemera.injectElement();
*/
const ephemera = {
@rushkeldon
rushkeldon / propMapper.js
Last active June 4, 2025 21:38
When prop spreading has left you with doubt as to the shape of the props...
const propMapper = {
typeMap: {},
trueTypeOf(obj) {
const match = {}.toString.call(obj).match(/\s([a-zA-Z]+)/);
const trueType = match?.[1]?.toLowerCase?.() ?? 'unknown';
return trueType === 'asyncgeneratorfunction' ? 'function' : trueType;
},
inferType(value) {
const type = propMapper.trueTypeOf(value);
switch (type) {