Taggor

All components · Category: Visual

FAQ accordion

Questions that open and close, built the accessible way.

A list of questions and answers as props, with the keyboard pattern an accordion needs and an option to keep several open.

01

Try it

<faq-accordion>
View

Props

Accent
faq-accordion: Questions that open and close, built the accessible way. A picture of the real component, drawn from its own code. The controls change the picture and the code beside it; nothing here is sent or stored.

Generated from the component's manifest and the values above.

Code for

index.html

<faq-accordion
  headline="Questions"
  locale="en"
  items="[{&quot;question&quot;:&quot;Does it slow my page down?&quot;,&quot;answer&quot;:&quot;The loader is async and tiny; nothing blocks your own load.&quot;},{&quot;question&quot;:&quot;Can I go back to an older version?&quot;,&quot;answer&quot;:&quot;Yes. Every version is immutable and a rollback is instant.&quot;},{&quot;question&quot;:&quot;Who owns the data?&quot;,&quot;answer&quot;:&quot;You do, and you can export it as CSV or NDJSON.&quot;}]"
></faq-accordion>

<script>
  const element = document.querySelector("faq-accordion");
  element.addEventListener("faq-accordion:toggle", (event) => {
    console.log(event.detail);
  });
</script>
  • Add the site's Taggor script once; the component appears when it loads.

taggor-component.js

const element = document.createElement("faq-accordion");
element.setAttribute("headline", "Questions");
element.setAttribute("locale", "en");
element.items = [
  {
    "question": "Does it slow my page down?",
    "answer": "The loader is async and tiny; nothing blocks your own load."
  },
  {
    "question": "Can I go back to an older version?",
    "answer": "Yes. Every version is immutable and a rollback is instant."
  },
  {
    "question": "Who owns the data?",
    "answer": "You do, and you can export it as CSV or NDJSON."
  }
];
element.addEventListener("faq-accordion:toggle", (event) => {
  console.log(event.detail);
});
document.body.append(element);
  • Add the site's Taggor script once; the component appears when it loads.
  • Lists and objects go in as a property of the element, not an attribute.

FaqAccordion.tsx

import { useEffect, useRef } from "react";

export function FaqAccordion() {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    Object.assign(element, {
      items: [
        {
          "question": "Does it slow my page down?",
          "answer": "The loader is async and tiny; nothing blocks your own load."
        },
        {
          "question": "Can I go back to an older version?",
          "answer": "Yes. Every version is immutable and a rollback is instant."
        },
        {
          "question": "Who owns the data?",
          "answer": "You do, and you can export it as CSV or NDJSON."
        }
      ],
    });
    const onToggle = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("faq-accordion:toggle", onToggle);
    return () => {
      element.removeEventListener("faq-accordion:toggle", onToggle);
    };
  }, []);

  return <faq-accordion ref={ref} headline="Questions" locale="en" />;
}
  • Add the site's Taggor script once; the component appears when it loads.
  • React 18 sends every prop of a custom element as a text attribute.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

FaqAccordion.tsx

import { useEffect, useRef } from "react";

export function FaqAccordion() {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const element = ref.current;
    if (!element) return;
    Object.assign(element, {
      items: [
        {
          "question": "Does it slow my page down?",
          "answer": "The loader is async and tiny; nothing blocks your own load."
        },
        {
          "question": "Can I go back to an older version?",
          "answer": "Yes. Every version is immutable and a rollback is instant."
        },
        {
          "question": "Who owns the data?",
          "answer": "You do, and you can export it as CSV or NDJSON."
        }
      ],
    });
    const onToggle = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    element.addEventListener("faq-accordion:toggle", onToggle);
    return () => {
      element.removeEventListener("faq-accordion:toggle", onToggle);
    };
  }, []);

  return <faq-accordion ref={ref} headline="Questions" locale="en" />;
}
  • Add the site's Taggor script once; the component appears when it loads.
  • React 19 sets a property when the element already has it, an attribute otherwise.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

src/FaqAccordion.vue

<script setup lang="ts">
function onToggle(event: Event) {
  console.log((event as CustomEvent).detail);
}
</script>

<template>
  <faq-accordion
    headline="Questions"
    locale="en"
    :items.prop="[{&quot;question&quot;:&quot;Does it slow my page down?&quot;,&quot;answer&quot;:&quot;The loader is async and tiny; nothing blocks your own load.&quot;},{&quot;question&quot;:&quot;Can I go back to an older version?&quot;,&quot;answer&quot;:&quot;Yes. Every version is immutable and a rollback is instant.&quot;},{&quot;question&quot;:&quot;Who owns the data?&quot;,&quot;answer&quot;:&quot;You do, and you can export it as CSV or NDJSON.&quot;}]"
    @faq-accordion:toggle="onToggle"
  />
</template>

vite.config.ts

import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag === "faq-accordion",
        },
      },
    }),
  ],
});
  • Add the site's Taggor script once; the component appears when it loads.
  • vite.config.ts tells Vue that this tag is not a Vue component.
  • Lists and objects go in as a property of the element, not an attribute.

src/app/faq-accordion.component.ts

import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";

@Component({
  selector: "app-faq-accordion",
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <faq-accordion headline="Questions" locale="en" [items]="values.items"></faq-accordion>
  `,
})
export class FaqAccordionComponent {
  readonly values = {
    items: [
      {
        "question": "Does it slow my page down?",
        "answer": "The loader is async and tiny; nothing blocks your own load."
      },
      {
        "question": "Can I go back to an older version?",
        "answer": "Yes. Every version is immutable and a rollback is instant."
      },
      {
        "question": "Who owns the data?",
        "answer": "You do, and you can export it as CSV or NDJSON."
      }
    ],
  };

  constructor() {
    const host = inject<ElementRef<HTMLElement>>(ElementRef);
    const element = () => host.nativeElement.querySelector("faq-accordion");
    const onToggle = (event: Event) => {
      console.log((event as CustomEvent).detail);
    };
    afterNextRender(() => element()?.addEventListener("faq-accordion:toggle", onToggle));
    inject(DestroyRef).onDestroy(() => element()?.removeEventListener("faq-accordion:toggle", onToggle));
  }
}
  • Add the site's Taggor script once; the component appears when it loads.
  • The component declares CUSTOM_ELEMENTS_SCHEMA.
  • Lists and objects go in as a property of the element, not an attribute.
  • The event is heard with addEventListener, inside an effect.

src/TaggorComponent.svelte

<script>
  function onToggle(event) {
    console.log(event.detail);
  }
</script>

<faq-accordion
  headline="Questions"
  locale="en"
  items={[
    {
      "question": "Does it slow my page down?",
      "answer": "The loader is async and tiny; nothing blocks your own load."
    },
    {
      "question": "Can I go back to an older version?",
      "answer": "Yes. Every version is immutable and a rollback is instant."
    },
    {
      "question": "Who owns the data?",
      "answer": "You do, and you can export it as CSV or NDJSON."
    }
  ]}
  onfaq-accordion:toggle={onToggle}
></faq-accordion>
  • Add the site's Taggor script once; the component appears when it loads.

How an agent gets a component like this onto a site:

taggor checktaggor publish

The CSS variables the component exposes, set the way a customer's page would.

styles.css

/* faq-accordion: no CSS variable set */

02

Props

Props of the component, read from its manifest
PropTypeDefaultWhat it does
headlinestringnoneReplaces the default heading.
itemslist[{"question":"Como funciona a entrega?","answer…The questions and answers, in the site's language.
multiplebooleanfalseLets several answers stay open at once.
localept-BR | enpt-BR–

Prop names and descriptions are the component's own, in English, as its author wrote them.

03

Events

Events of the component, read from its manifest
EventWhen it fires
toggleThe visitor opened or closed an answer.

04

Build one with your agent

Paste this into your agent. It asks you before it signs in, pays or goes further than checking and publishing.

Build me a Taggor component like "FAQ accordion" (faq-accordion): Questions that open and close, built the accessible way. Fetch https://taggor.dev/agent-setup/prompt.md and follow its instructions to set me up for Taggor. Ask me before you sign in, create an account, accept terms, pay for anything or type a secret. Check it with `taggor check` and publish it with `taggor publish`, and stop there. Do not promote it to production, attach it to a site, roll back anything or use --yes, --force or --force-drop-invalid unless I ask for exactly that in this conversation.

05

Related components