All components · Category: Navigation
Morphing drawer menu
A menu button that morphs into a close icon while a drawer slides in.
Three bars become an X while a drawer slides over the page. Open, the drawer keeps the keyboard focus inside, Escape closes it and focus goes back to the button. The page behind is made inert.
01
Try it
Props
Generated from the component's manifest and the values above.
index.html
<nav-drawer-morph open locale="en"></nav-drawer-morph>
<script>
const element = document.querySelector("nav-drawer-morph");
element.addEventListener("nav-drawer-morph:toggled", (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("nav-drawer-morph");
element.setAttribute("open", "");
element.setAttribute("locale", "en");
element.addEventListener("nav-drawer-morph:toggled", (event) => {
console.log(event.detail);
});
document.body.append(element);
- Add the site's Taggor script once; the component appears when it loads.
NavDrawerMorph.tsx
import { useEffect, useRef } from "react";
export function NavDrawerMorph() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onToggled = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("nav-drawer-morph:toggled", onToggled);
return () => {
element.removeEventListener("nav-drawer-morph:toggled", onToggled);
};
}, []);
return <nav-drawer-morph ref={ref} open="" 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.
- The event is heard with addEventListener, inside an effect.
NavDrawerMorph.tsx
import { useEffect, useRef } from "react";
export function NavDrawerMorph() {
const ref = useRef<HTMLElement>(null);
useEffect(() => {
const element = ref.current;
if (!element) return;
const onToggled = (event: Event) => {
console.log((event as CustomEvent).detail);
};
element.addEventListener("nav-drawer-morph:toggled", onToggled);
return () => {
element.removeEventListener("nav-drawer-morph:toggled", onToggled);
};
}, []);
return <nav-drawer-morph ref={ref} open 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.
- The event is heard with addEventListener, inside an effect.
src/NavDrawerMorph.vue
<script setup lang="ts">
function onToggled(event: Event) {
console.log((event as CustomEvent).detail);
}
</script>
<template>
<nav-drawer-morph
:open.prop="true"
locale="en"
@nav-drawer-morph:toggled="onToggled"
/>
</template>
vite.config.ts
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === "nav-drawer-morph",
},
},
}),
],
});
- 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.
src/app/nav-drawer-morph.component.ts
import { afterNextRender, Component, CUSTOM_ELEMENTS_SCHEMA, DestroyRef, ElementRef, inject } from "@angular/core";
@Component({
selector: "app-nav-drawer-morph",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<nav-drawer-morph [open]="true" locale="en"></nav-drawer-morph>
`,
})
export class NavDrawerMorphComponent {
constructor() {
const host = inject<ElementRef<HTMLElement>>(ElementRef);
const element = () => host.nativeElement.querySelector("nav-drawer-morph");
const onToggled = (event: Event) => {
console.log((event as CustomEvent).detail);
};
afterNextRender(() => element()?.addEventListener("nav-drawer-morph:toggled", onToggled));
inject(DestroyRef).onDestroy(() => element()?.removeEventListener("nav-drawer-morph:toggled", onToggled));
}
}
- Add the site's Taggor script once; the component appears when it loads.
- The component declares CUSTOM_ELEMENTS_SCHEMA.
- The event is heard with addEventListener, inside an effect.
src/TaggorComponent.svelte
<script>
function onToggled(event) {
console.log(event.detail);
}
</script>
<nav-drawer-morph open locale="en" onnav-drawer-morph:toggled={onToggled}></nav-drawer-morph>
- 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 publishThe CSS variables the component exposes, set the way a customer's page would.
styles.css
nav-drawer-morph {
--nd-radius: 16px;
}02
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| brand | string | Acme Studio | The name in the bar. |
| open | boolean | false | Starts with the drawer open. |
| links | list | none | The drawer's links; the component's own list when empty. |
| locale | pt-BR | en | en | – |
Prop names and descriptions are the component's own, in English, as its author wrote them.
03
Events
| Event | When it fires |
|---|---|
| toggled | The drawer opened or closed. |
04
Build one with your agent
Build me a Taggor component like "Morphing drawer menu" (nav-drawer-morph): A menu button that morphs into a close icon while a drawer slides in.
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
- Mega menu<nav-mega-menu>
- Shrinking header<nav-shrink-header>
- Day and night switch<toggle-day-night>