Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

EbaySwitch: Controlled prop not working #296

Open
maxrchung opened this issue Dec 6, 2023 · 2 comments
Open

EbaySwitch: Controlled prop not working #296

maxrchung opened this issue Dec 6, 2023 · 2 comments

Comments

@maxrchung
Copy link
Contributor

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

Screen.Recording.2023-12-05.at.3.09.14.PM.mov

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.

@darkwebdev
Copy link
Collaborator

darkwebdev commented Dec 6, 2023

@maxrchung thanks for the issue! I've fixed your sandbox example: https://codesandbox.io/p/sandbox/billowing-forest-m55jr6?file=%2Fsrc%2FApp.tsx%3A24%2C20

But I agree, behavior looks inconsistent....

@maxrchung
Copy link
Contributor Author

I've fixed your sandbox example: https://codesandbox.io/p/sandbox/billowing-forest-m55jr6?file=%2Fsrc%2FApp.tsx%3A24%2C20

Thanks, but maybe I am misunderstanding, how does this fix the sandbox? I was trying to show that the controlled property wasn't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants