Skip to content

[EuiButtonGroup] multiple events being fired per click #4961

Closed

Description

@PhaedrusTheGreek

The following (copied from the sandbox demo for EuiButtonGroup) fires 2 onChange events for each click.

const [toggleIdSelected, setToggleIdSelected] = useState(`${idPrefix}1`);
  const onChange = (optionId) => {
    setToggleIdSelected(optionId);
    console.log(optionId);
  };

  return (
    <Fragment>
      <EuiButtonGroup
        legend="This is a basic group"
        options={toggleButtons}
        idSelected={toggleIdSelected}
        onChange={(id) => onChange(id)}
      />
    </Fragment>
  );

Possibly related, if the setToggleIdSelected(optionId) line is removed, 3 events will fire per click.

Activity

  1. added
    ⚠️ needs validation
    on Jul 22, 2021
  2. PhaedrusTheGreek commented on Jul 26, 2021

    @PhaedrusTheGreek
    ContributorAuthor

    I noticed that the onChange event is being fired when calling setToggleIdSelected. A few days later I was playing with the EUISearchBar component and found that it does not fire an event when its query property changes, instead the user is responsible for calling change manually.

  3. self-assigned this
    on Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issue⚠️ needs validation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions