Skip to content

Instantly share code, notes, and snippets.

@danedavid
Created March 23, 2019 18:08
Show Gist options
  • Save danedavid/18e4415eaaed2369940abd204424191a to your computer and use it in GitHub Desktop.
Save danedavid/18e4415eaaed2369940abd204424191a to your computer and use it in GitHub Desktop.
import React, { useRef } from 'react';
import { useActiveOnIntersect } from './hooks/useActiveOnIntersect';
import { useFocusOnActive } from './hooks/useFocusOnActive';
export const TextInputFormElement = ({ char, active, setActiveElement }) => {
const containerEl = useRef();
const inputRef = useRef();
useActiveOnIntersect(() => setActiveElement(char), containerEl);
useFocusOnActive(active, inputRef);
return (
<div
id={`elem${char}`}
className={'element-container' + (active?' active':'')}
ref={containerEl}
>
<div>{`Form - textfield-${char}: `}</div>
<div>
<input
type='text'
ref={inputRef}
/>
</div>
</div>
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment