Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TextField (textarea): characterCount is not updated after it is manually updated from the form's method #1577

@yodchahan

Description

@yodchahan

RMWC Version: 14.3.5

Description:

  • When I use TextField (textarea)
  • And pass there {...register('message')} from react-hook-form
  • And I also have characterCount and by default it shows 0/20
    image
<TextField
       textarea
       label="textarea..."
       maxLength={20}
       characterCount
       {...register('message')}
     />
  • Then I enter some value and the counter shows 3/20 which is correct
    image
  • Also I have a button send for sending a message.
    image
  • And when I click on the button I need to reset the value and I call setValue('message', '') for this.

Actual: The value is cleared, but the characterCount is still 3/20.
image

Expected: The value is cleared, but the characterCount is 0/20.
image

Full code for reproducing:

import { Controller, useFormContext } from 'react-hook-form';

const Bug = () => {
  const { register, setValue } = useFormContext<{
    message: string;
  }>();

  return (
    <>
      <TextField
        textarea
        label="textarea..."
        maxLength={20}
        characterCount
        {...register('message')}
      />
      <button
        onClick={() => {
          setValue('message', '');
        }}
      >
        Send
      </button>
    </>
  );
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions