import React, { useRef, type ElementType, type HTMLAttributes, type ReactNode } from 'react' import classnames from 'classnames' import { useFocusable, type FocusableOptions } from 'react-aria' import styles from './Focusable.module.css' export type FocusableProps = { children: ReactNode /** * The HTML element to render as. Defaults to `div` to avoid an api change * but should be set to 'span' if rendering within something like a 'p' tag to avoid invalid HTML. */ tag?: T } & FocusableOptions & HTMLAttributes export const Focusable = ({ children, className, tag, ...props }: FocusableProps): JSX.Element => { const ref = useRef(null) const { focusableProps } = useFocusable(props, ref) const Element = tag ?? 'div' return ( {children} ) }