Skip to content
New issue

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

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

Already on GitHub? # to your account

[button] Add spinner/loading theme variant #842

Open
jouni opened this issue Sep 27, 2018 · 6 comments
Open

[button] Add spinner/loading theme variant #842

jouni opened this issue Sep 27, 2018 · 6 comments
Labels

Comments

@jouni
Copy link
Member

jouni commented Sep 27, 2018

Add a theme variant for a disabled button, to give users an indication that the action the button triggered is being performed.

screen shot 2018-09-27 at 14 44 45

Should be added for both Lumo and Material themes.

@jouni
Copy link
Member Author

jouni commented Sep 27, 2018

After vaadin/vaadin-button#112 is fixed, the spinner/loading variant should look like close to this:
screen shot 2018-09-27 at 14 58 32

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-button May 19, 2021
@web-padawan web-padawan changed the title Spinner/loading theme variant [button] Add spinner/loading theme variant May 28, 2021
@knoobie
Copy link
Contributor

knoobie commented Aug 30, 2021

In our v8 apps we have used this quite heavily for long running operations in combination with setDisableOnClick

To customize the icon and e.g. loading Text I would propose to add additional APIs for:

setDisableOnClickIcon and setDisableOnClickCaption to have dedicated icon and text for this.

This could also be done with a new method setDisableOnClick(true, VaadinIcon.LOADING, "Loading..") as overloaded method, where the old method setDisableOnClick just calls the second and third parameter with null.

@knoobie
Copy link
Contributor

knoobie commented Jan 7, 2022

Probably not the best looking solution, but if somebody needs it:

v22+

The style is automatically applied if the button is configured with setDisableOnClick(true) and the user clicked the button.

:host([disableonclick][disabled]) {
  color: transparent;
}

:host([disableonclick][disabled]) [part='label']::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  border: 4px solid transparent;
  border-top-color: red;
  border-radius: 50%;
  animation: button-loading-spinner 1s ease infinite;
}

@keyframes button-loading-spinner {
  from {
    transform: rotate(0turn);
  }

  to {
    transform: rotate(1turn);
  }
}

@rolfsmeds
Copy link
Contributor

Relevant article for technical design and a11y: https://adrianroselli.com/2021/01/multi-function-button.html

@vaithu
Copy link

vaithu commented Nov 24, 2022

Nice feature to have in Vaadin

@mrts
Copy link

mrts commented Dec 15, 2022

The framework usually automatically displays a loading indicator from the start of a server request and hides it after the response processing has ended.

However, in case the backend handles the action asynchronously, the loading indicator is not shown and in this case the UI remains otherwise active while the action is still in progress.

Tatu Lund has created an asynchronous button click handler example here:
https://github.com/TatuLund/cdi-demo/blob/master/src/main/java/org/vaadin/cdidemo/views/admin/AdminPresenter.java#L41-L56

Here's how it looks:
Async-spinner

As you can see, even though there is a spinner in the middle of the screen, the button state does not change and it does not contain the spinner, so the user can continue clicking on it, which is not ideal.

Adding a spinner button theme variant would be really great for this case.

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

No branches or pull requests

6 participants