ebayui-core-react icon indicating copy to clipboard operation
ebayui-core-react copied to clipboard

EbaySwitch: Controlled prop not working

Open maxrchung opened this issue 1 year ago • 2 comments

The EbaySwitch component allows a checked prop to control its value, but on change this prop does not get enforced properly. Other controlled components like EbayCheckbox don't have this issue. I have a small sandbox and demo video to demonstrate issue: https://codesandbox.io/p/sandbox/dreamy-wozniak-xqlpqc?file=%2Fsrc%2FApp.tsx%3A10%2C32

https://github.com/eBay/ebayui-core-react/assets/3955187/63db2a94-dd9d-4cf3-be2a-b03debb1709d

I need this component to be controlled so I can set its state as a part of making an API call. Here is my flow:

  1. Toggle switch on.
  2. Make API call.
  3. Disable switch while call is in progress.
  4. Enable switch when call finishes.
  5. Toggle switch on/off depending on API result.

With the current component I can't do step 5 as the component will always change the switch's states. I could do something kind of funny like throw an exception in my change handler but I that's probably not advised.

I will try and open a corresponding PR to fix this change.

maxrchung avatar Dec 06 '23 01:12 maxrchung