Skip to content

feat(angular): support separate Button/Modal components#2

Merged
antuuanyf merged 1 commit into
mainfrom
feat/angular-separate-components
May 30, 2026
Merged

feat(angular): support separate Button/Modal components#2
antuuanyf merged 1 commit into
mainfrom
feat/angular-separate-components

Conversation

@antuuanyf

Copy link
Copy Markdown
Owner

Qué

Confirma y documenta que el wrapper de Angular funciona cuando el botón (trigger) y el <dialog> (modal) viven en componentes standalone separados usados por un padre — no solo en un único componente como hacía la demo.

No hizo falta tocar el código de la librería: el desacople es por diseño.

Por qué funciona

  1. PrettyModalService es providedIn: 'root' → singleton compartido por toda la app.
  2. El trigger referencia el dialog por string id, que el core resuelve con document.getElementById — búsqueda global en el DOM, no atada al árbol de componentes.
  3. El registro de anchor/eventos (opened)/(closed) está indexado por ese id en el singleton.

Cambios

  • Demo refactorizada en componentes separados: app-modal-trigger-button y app-modal, enlazados solo por el id, usados desde AppComponent.
  • README del wrapper: nueva sección "Trigger and dialog in separate components" con ejemplos y caveats.
  • Test de integración en wrapper.spec.ts: monta trigger y dialog en componentes distintos y verifica que se enlazan vía el servicio raíz.

Bugfix incluido

Renombrado el input del modal de idmodalId. Un @Input() id se refleja también como atributo en el host <app-modal>, duplicando el id; document.getElementById devolvía el host (sin showModal()) en vez del <dialog>, causando TypeError: e.showModal is not a function.

Verificación

  • ng build de la demo: OK
  • vitest run del wrapper: 13/13 en verde (incluye el nuevo test cross-component)

🤖 Generated with Claude Code

The trigger and the <dialog> don't need to share a component: they're
linked only by the dialog id via the root PrettyModalService and the
core's document.getElementById lookup. Refactor the Angular demo into
standalone app-modal-trigger-button and app-modal components used by a
parent, document the pattern in the wrapper README, and add a wrapper
integration test that mounts the trigger and dialog in different
components and asserts they link through the shared service.

Avoid naming the modal wrapper input `id`: Angular reflects it onto the
host element too, duplicating the id and breaking getElementById (which
returned the host instead of the <dialog>, causing
"showModal is not a function"). Use `modalId` instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@antuuanyf antuuanyf merged commit 32a603d into main May 30, 2026
1 check passed
@antuuanyf antuuanyf deleted the feat/angular-separate-components branch May 30, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant