GithubHelp home page GithubHelp logo

Loader states about heart-switch HOT 6 CLOSED

anatoliygatt avatar anatoliygatt commented on May 18, 2024
Loader states

from heart-switch.

Comments (6)

TheGooner93 avatar TheGooner93 commented on May 18, 2024 1

Ah I see what you mean. Lets close this issue then

from heart-switch.

anatoliygatt avatar anatoliygatt commented on May 18, 2024

Hi @TheGooner93. Thank you, glad you liked it!

I'm not sure what it's actually for, nor have I ever seen this pattern being used in any of the libraries that are implementing form inputs (including toggle switch).

I can see two possible use cases where isLoading might be useful, but we can easily overcome it with the already existing attributes and best practices:

  1. If you want to make a toggle switch's state immutable while submitting a form, you can use a disabled or an aria-disabled attribute for this very purpose.
  2. If you want to load a form's state from an API, you shouldn't display a form in an unknown state in the first place. Use some sort of a loading spinner and then render the whole form whenever its state will become available.

Let me know what you think!

from heart-switch.

TheGooner93 avatar TheGooner93 commented on May 18, 2024

Yeah what I'm thinking of is your point regarding integration with an API. Suppose toggling this switch is not being used as part of a form, but as a standalone input to perform an action ( for eg. adding a product to a wishlist in an ecommerce website) then a loading state would be sensible.

The loading state within the input(as opposed to an entire page loading) would be definitely optional and nice to have. Feels like better UX too imo

from heart-switch.

anatoliygatt avatar anatoliygatt commented on May 18, 2024

I see. In this case, I would use another best practice, optimistic UI. Think of a "Like" button on Twitter, when you click on it, it will animate immediately and then if something goes wrong, it will just restore itself to the original state and show some sort of toast with an error message.

from heart-switch.

TheGooner93 avatar TheGooner93 commented on May 18, 2024

Yes exactly. I do have a PR ready for this. I will update once I fix the snapshot tests.

from heart-switch.

anatoliygatt avatar anatoliygatt commented on May 18, 2024

Well, PR is unnecessary here. When implementing optimistic UI you can, for example, set checked to true immediately and then set it back to false if an error is returned from an API.

from heart-switch.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.