You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
919 B

  1. import { forwardRef, useEffect, useImperativeHandle, useRef, InputHTMLAttributes } from 'react';
  2. export default forwardRef(function TextInput(
  3. { type = 'text', className = '', isFocused = false, ...props }: InputHTMLAttributes<HTMLInputElement> & { isFocused?: boolean },
  4. ref
  5. ) {
  6. const localRef = useRef<HTMLInputElement>(null);
  7. useImperativeHandle(ref, () => ({
  8. focus: () => localRef.current?.focus(),
  9. }));
  10. useEffect(() => {
  11. if (isFocused) {
  12. localRef.current?.focus();
  13. }
  14. }, []);
  15. return (
  16. <input
  17. {...props}
  18. type={type}
  19. className={
  20. 'px-2 flex-grow w-full h-[30px] bg-primary-background border border-primary-hover focus:outline-none focus:bg-neutral-10 focus:border-2 focus:border-primary-hover ' +
  21. className
  22. }
  23. ref={localRef}
  24. />
  25. );
  26. });