tailwindlabs / tailwindui-issues

Bug fixes and feature request tracking for Tailwind UI.
233 stars 4 forks source link

Catalyst <Input /> component `onChange` handler is passed full event, not just the value as the docs show #1600

Closed torra closed 2 months ago

torra commented 2 months ago

What component (if applicable) Catalyst Input component

Describe the bug When using the Catalyst component, if I copy the the example from the documentation, the rendered input component does not correctly update with the value the user types. Instead, it updates with [Object object], as it is casting a javascript Event object to a string.

To Reproduce Steps to reproduce the behavior:

  1. Copy and paste the example usage of an component from: https://catalyst.tailwindui.com/docs/input#controlled-component
  2. Start typing in the input box
  3. Note that the component renders [object Object] rather than the string value you entered
  4. Update the onChange handler to a function for debugging, like:
    const handleChange = (e) => {
    console.log(e);
    };
  5. Set a breakpoint in the new handleChange function, and note that the value passed into the event handler is an Event object, not the string value as expected based on the documentation.

Expected behavior As the documentation shows, the expected behavior would be for the event handler to be passed the string value of event.target.value.

Screenshots Visual example of the problem:

Screenshot 2024-06-17 at 12 46 44 PM

Browser/Device (if applicable)

Additional context I also have the same problem with the Textarea component (https://catalyst.tailwindui.com/docs/textarea#controlled-component), but other components, like Listbox and Switch, seem to work as expected from the docs.

thecrypticace commented 2 months ago

Ah whoops. Good catch. The Input, Select, and Textarea components use the event in their onChange handler rather than just the value so it's the docs that are incorrect here. I've corrected the examples in the docs.

Thanks for pointing this out! ✨

torra commented 2 months ago

Thanks! Appreciate the quick turnaround.