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

Textarea doesn't update value when it's an empty string #1068

Closed
andesol opened this issue Apr 12, 2024 · 3 comments · Fixed by #1070
Closed

Textarea doesn't update value when it's an empty string #1068

andesol opened this issue Apr 12, 2024 · 3 comments · Fixed by #1070

Comments

@andesol
Copy link
Contributor

andesol commented Apr 12, 2024

Consider this simplified example:

import { useState } from 'react';
import { Button, Textarea } from "@canonical/react-components";

function App() {
  const [data, setData] = useState("Default text");

  return (
      <div>
        <Button onClick={() => setData("")}>
          Show nothing
        </Button>
        <p>Current data is: {data}</p>
        <Textarea
          value={data}
          onChange={(e) => setData(e.target.value)}
        />
      </div>
    );
}

This is the default scenario:

image

I'd expect clicking the button to clear the value in the Textarea. However, while the state is correctly updated (to an empty string), the Textarea still shows the previous value.

image

@andesol
Copy link
Contributor Author

andesol commented Apr 16, 2024

It looks like this line should be

props.value ?? innerValue

@bartaz
Copy link
Member

bartaz commented Apr 16, 2024

Good catch @andesol. Care to propose a PR? I guess it would be good to have a test case that catches this as well.

@andesol
Copy link
Contributor Author

andesol commented Apr 16, 2024

@bartaz Indeed, here's the PR #1070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants