oui icon indicating copy to clipboard operation
oui copied to clipboard

[BUG] OuiCheckableCard onChange fire twice after checkbox clicked

Open wanglam opened this issue 9 months ago • 1 comments

Describe the bug The onChange property of OuiCheckableCard will be triggered twice after checkbox clicked. The onChange callback should only be fired once for single checkbox click. It seems the duplicated onChange was be fired by [this line].(https://github.com/opensearch-project/oui/blob/main/src/components/card/checkable_card/checkable_card.tsx#L113)

To Reproduce

Here is the sample code:

import React, { useState } from 'react';

import { OuiCheckableCard } from '@opensearch-project/oui';

import { htmlIdGenerator } from '@opensearch-project/oui/lib/services';

export default () => {
  return (
    <OuiCheckableCard
      id={htmlIdGenerator()()}
      label="I am a checkbox"
      checkableType="checkbox"
      value="checkbox1"
      checked={checkbox}
      onChange={() => {
        console.log("on change called.");
      }}
    />
  );
};

The on change called will output twice after checkbox clicked.

Expected behavior

It should only fired once for single checkbox click.

Screenshots

image

Host/Environment (please complete the following information):

  • OUI Version: [e.g. 1.0]
  • OSD Version (if applicable): [e.g. 2.7.0]
  • OS: [e.g. iOS]
  • Browser and version [e.g. Chrome 90]

Additional context N/A

wanglam avatar May 11 '24 03:05 wanglam