in web/wp-content/themes/mozilla-builders/static/js/plugins/accordion.js [146:236]
function handleTrigger(el, Alpine) {
Alpine.bind(el, {
'x-init'() {
if (!this.__item) {
console.error('x-accordion:trigger must be placed inside an x-accordion:item', el);
}
if (!isElementTag(el, 'button')) {
console.error('x-accordion:trigger must be a <button> element', el);
}
this.triggers.push(el);
},
':id'() {
return this.$id('tb-accordion-trigger');
},
':aria-controls'() {
return this.$id('tb-accordion-content');
},
':aria-expanded'() {
return this.open;
},
':data-state'() {
return this.open ? 'open' : 'closed';
},
'@click'() {
this.toggleItem(this.__item);
},
'@keydown.up.prevent.stop'() {
if (this.orientation === 'vertical') {
const index = this.triggers.indexOf(el);
if (index >= 0) {
const next = this.loop ? index - 1 : Math.max(index - 1, 0);
this.triggers.at(next)?.focus();
}
}
},
'@keydown.down.prevent.stop'() {
if (this.orientation === 'vertical') {
const index = this.triggers.indexOf(el);
if (index >= 0) {
const previous = this.loop
? (index + 1) % this.triggers.length
: Math.min(index + 1, this.triggers.length - 1);
this.triggers.at(previous)?.focus();
}
}
},
'@keydown.left.prevent.stop'() {
if (this.orientation === 'horizontal') {
const index = this.triggers.indexOf(el);
if (index >= 0) {
const next = this.loop ? index - 1 : Math.max(index - 1, 0);
this.triggers.at(next)?.focus();
}
}
},
'@keydown.right.prevent.stop'() {
if (this.orientation === 'horizontal') {
const index = this.triggers.indexOf(el);
if (index >= 0) {
const previous = this.loop
? (index + 1) % this.triggers.length
: Math.min(index + 1, this.triggers.length - 1);
this.triggers.at(previous)?.focus();
}
}
},
'x-effect'() {
dispatch(el, 'accordion:change', {
open: this.open,
});
},
});
}