Skip to content

Commit

Permalink
fix: tags filters closing on tag selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob committed Oct 3, 2024
1 parent c1b7f2b commit 6ad63c2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions app/javascript/js/controllers/toggle_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export default class extends Controller {
static targets = ['panel']

static values = {
// One may want to have an element that is exempt from triggerring the click outside event
exemptionContainer: String,
// One may want to have elements that are exempt from triggering the click outside event
exemptionContainers: Array,
}

get exemptionContainerTarget() {
return document.querySelector(this.exemptionContainerValue)
get exemptionContainerTargets() {
return this.exemptionContainersValue.map((selector) => document.querySelector(selector)).filter(Boolean)
}

connect() {
Expand All @@ -20,13 +20,9 @@ export default class extends Controller {

clickOutside(e) {
if (this.hasPanelTarget) {
if (this.hasExemptionContainerValue && this.exemptionContainerTarget) {
const inExemptionContainer = this.exemptionContainerTarget.contains(e.target)
const isInExemptionContainer = this.hasExemptionContainersValue && this.exemptionContainerTargets.some((container) => container.contains(e.target))

if (!inExemptionContainer) {
leave(this.panelTarget)
}
} else {
if (!isInExemptionContainer) {
leave(this.panelTarget)
}
}
Expand Down

0 comments on commit 6ad63c2

Please sign in to comment.