Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToggleSwitch and forwardRef #1078

Closed
2 tasks done
leonyoung1 opened this issue Oct 19, 2023 · 1 comment · Fixed by #1198 or #1325
Closed
2 tasks done

ToggleSwitch and forwardRef #1078

leonyoung1 opened this issue Oct 19, 2023 · 1 comment · Fixed by #1198 or #1325
Labels
🐛 bug Something isn't working confirmed This bug was confirmed good first issue Good for newcomers

Comments

@leonyoung1
Copy link

leonyoung1 commented Oct 19, 2023

  • I have searched the Issues to see if this bug has already been reported
  • I have tested the latest version

Steps to reproduce

Using "flowbite-react": "^0.6.4" and "react-hook-form": "7.47.0"

import { useForm } from 'react-hook-form';
import { Button, ToggleSwitch} from 'flowbite-react'

export default function App() {
  const { register, handleSubmit} = useForm();

  return (
    <div>
      <form onSubmit={handleSubmit(fd => console.log(fd))}>
        <ToggleSwitch  {...register("toggle")} />
        <Button type='submit'>Submit</Button>
      </form>
    </div>
  );
}

Current behavior

ToggleSwitch can't receive a forwarded ref from the useForm hook from React Hook Form.

Expected behavior

I expect ToggleSwitch to be able to receive a forwarded ref, like the other Flowbite form components.

Context

What are you trying to accomplish? Does this only happen on a specific browser, screen size, or operating system?

I'm trying out all the Flowbite form components with React Hook Form.

Most of the components seem to work well, except for ToggleSwitch.

When using React Hook Form with ToggleSwitch I got an error Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

When I looked at the code for all the other form components, I saw they all used forwardRef:

export const Radio = forwardRef<HTMLInputElement, RadioProps>(
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
export const Select = forwardRef<HTMLSelectElement, SelectProps>(
export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(
export const RangeSlider = forwardRef<HTMLInputElement, RangeSliderProps>(
export const FileInput = forwardRef<HTMLInputElement, FileInputProps>(

EXCEPT for ToggleSwitch:

export const ToggleSwitch: FC<ToggleSwitchProps> = ({

@rluders rluders added 🐛 bug Something isn't working good first issue Good for newcomers confirmed This bug was confirmed labels Oct 19, 2023
@andersonba
Copy link

up

nikitadubyk pushed a commit to nikitadubyk/flowbite-react that referenced this issue Dec 23, 2023
rluders pushed a commit that referenced this issue Dec 23, 2023
ddiasfront pushed a commit to ddiasfront/flowbite-react that referenced this issue Dec 29, 2023
ddiasfront pushed a commit to ddiasfront/flowbite-react that referenced this issue Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working confirmed This bug was confirmed good first issue Good for newcomers
Projects
None yet
3 participants