Skip to content

Commit

Permalink
Merge pull request #435 from remy727/feature/modal
Browse files Browse the repository at this point in the history
Close modal when clicking outside
  • Loading branch information
kirillplatonov authored Jul 30, 2024
2 parents b115343 + 4d4aba6 commit 4ecbb10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/polaris_view_components.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ class Modal extends Controller {
}
open() {
this.element.classList.remove(this.hiddenClass);
this.element.insertAdjacentHTML("afterend", `<div class="${this.backdropClass}"></div>`);
const dropElement = `<div class="${this.backdropClass}" data-controller="polaris" data-target="#${this.element.id}" data-action="click->polaris#closeModal"></div>`;
this.element.insertAdjacentHTML("afterend", dropElement);
this.backdrop = this.element.nextElementSibling;
}
close() {
Expand Down Expand Up @@ -878,6 +879,9 @@ class Polaris extends Controller {
openModal() {
this.findElement("modal").open();
}
closeModal() {
this.findElement("modal").close();
}
disableButton() {
this.findElement("button").disable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default class extends Controller {

open() {
this.element.classList.remove(this.hiddenClass)
this.element.insertAdjacentHTML('afterend', `<div class="${this.backdropClass}"></div>`)
const dropElement = `<div class="${this.backdropClass}" data-controller="polaris" data-target="#${this.element.id}" data-action="click->polaris#closeModal"></div>`
this.element.insertAdjacentHTML('afterend', dropElement)
this.backdrop = this.element.nextElementSibling
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default class extends Controller {
this.findElement("modal").open()
}

closeModal() {
this.findElement("modal").close()
}

disableButton() {
this.findElement("button").disable()
}
Expand Down

0 comments on commit 4ecbb10

Please sign in to comment.