Skip to content
New issue

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

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

Already on GitHub? # to your account

Select - when you pass the default value it doesn't allow to change on select #572

Closed
daniele-zurico opened this issue Nov 14, 2023 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@daniele-zurico
Copy link
Contributor

daniele-zurico commented Nov 14, 2023

If I pass the default value when I change the value from the drop-down list it stays on the default value:

function FormSelectDemo() {
  const [value, setValue] = React.useState('')
  const handleChange = event => {
    setValue(event.currentTarget.value);
  }
  return (
    <FormSelect
      id="select"
      disabled={false}
      value={value}
      defaultValue="option3"
      onChange={handleChange}
      options={['option1','option2', 'option3']}
    />
  );
}

Write the following test to check if your change is correct:

  it('should allow to change the default value on select', async () => {
    const user = userEvent.setup();
    render(
      <FormSelect options={['first', 'second', 'third']} defaultValue="third" />
    );
    await user.selectOptions(screen.getByRole('combobox'), 'first');
    const option: any = screen.getByRole('option', { name: 'first' });
    expect(option.selected).toBe(true);
  });

Follow this to create the new branch:

git checkout release/1.0.0
git pull
git checkout -b 'fix/select-default'
@daniele-zurico daniele-zurico added the bug Something isn't working label Nov 14, 2023
@daniele-zurico daniele-zurico added this to the 1.0.0 milestone Nov 14, 2023
@AlaaEddine20 AlaaEddine20 self-assigned this Nov 15, 2023
@daniele-zurico
Copy link
Contributor Author

closed by #573

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants