Skip to content

Commit

Permalink
Add ability to disable button without loader (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillplatonov authored Oct 10, 2023
1 parent fa1949a commit 45a8f9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/assets/javascripts/polaris_view_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ class Button extends Controller {
this.buttonContent.insertAdjacentHTML("afterbegin", this.spinnerHTML);
}
}
disableWithoutLoader(event) {
if (this.button.disabled) {
event.preventDefault();
} else {
this.button.disabled = true;
this.button.classList.add("Polaris-Button--disabled");
}
}
enable() {
if (this.button.disabled) {
this.button.disabled = false;
Expand Down Expand Up @@ -873,6 +881,9 @@ class Polaris extends Controller {
disableButton() {
this.findElement("button").disable();
}
disableButtonWithoutLoader() {
this.findElement("button").disableWithoutLoader();
}
enableButton() {
this.findElement("button").enable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ export default class extends Controller {
}
}

disableWithoutLoader(event) {
if (this.button.disabled) {
event.preventDefault()
} else {
this.button.disabled = true
this.button.classList.add("Polaris-Button--disabled")
}
}

enable() {
if (this.button.disabled) {
this.button.disabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export default class extends Controller {
this.findElement("button").disable()
}

disableButtonWithoutLoader() {
this.findElement("button").disableWithoutLoader()
}

enableButton() {
this.findElement("button").enable()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
action: "polaris#disableButton"
}
) { "Disable" } %> |
<%= polaris_button(
plain: true,
data: {
controller: "polaris",
target: "#demo-button",
action: "polaris#disableButtonWithoutLoader"
}
) { "Disable without loader" } %> |
<%= polaris_button(
plain: true,
data: {
Expand Down

0 comments on commit 45a8f9d

Please sign in to comment.