UNPKG

@stratakit/structures

Version:

Medium-sized component structures for the Strata design system

27 lines (26 loc) 683 B
import * as React from "react"; const INTERACTIVE_CONTENT_SELECTOR = [ "button", ":any-link", "[tabindex='0']" ].join(","); function useWarnOnInteractiveDescendants(ref, message) { const hasWarnedRef = React.useRef(false); React.useEffect(() => { const container = ref.current; if (hasWarnedRef.current) return; if (!container) return; const interactiveDescendant = container.querySelector( INTERACTIVE_CONTENT_SELECTOR ); if (!interactiveDescendant) return; hasWarnedRef.current = true; console.warn(message, { container, interactiveDescendant }); }, [message, ref]); } export { useWarnOnInteractiveDescendants };