Skip to content

Conversation

@ndelangen
Copy link
Member

@ndelangen ndelangen commented Sep 18, 2025

What I did

Fix the form component for template for sandboxes

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • Native browser form validation is now enabled, providing instant feedback and preventing invalid submissions.
    • The completion message updates in real time based on form state.
  • Refactor

    • Modernized the form component to a more responsive, standalone design for improved stability and maintainability.

…Update form validation and success handling logic.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 18, 2025

Walkthrough

Migrates an Angular form component to signals-based outputs and state, marks it standalone with FormsModule, updates template for ngModel and native validation, and adjusts conditional rendering to use signal reads.

Changes

Cohort / File(s) Summary
Angular FormComponent signals migration
code/frameworks/angular/template/components/form.component.ts
Replaced EventEmitter/@output with output<string>(); converted complete: boolean to complete = signal(false); set @Component({ standalone: true, imports: [FormsModule] }); added ngNativeValidate, name="value", and template uses complete() with @if for conditional message.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant T as Template (Form)
  participant C as FormComponent
  participant P as Parent Component

  U->>T: Enter input + submit
  T->>C: ngSubmit (validated via ngNativeValidate)
  C->>C: complete.set(true)
  C-->>P: onSuccess.emit(value) via output<string>()
  Note over T,C: Template reads complete() to render "Completed!!"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitched my nose at signals’ gleam,
Hopped past outputs’ classic stream—
A standalone burrow, Forms in tow,
Native checks say “ready, go!”
With a flick of ears, success takes flight,
complete() glows—carrot-bright.
Ship it swift into the night!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely describes the primary changes in the PR — migrating FormComponent to Angular signals and converting it to a standalone component while updating form validation and success handling — and directly matches the summarized file changes (signal-based output, writable complete signal, standalone: true with FormsModule, and template updates).
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch norbert/fix-angular-form-component

Comment @coderabbitai help to get the list of available commands and usage tips.

@ndelangen ndelangen added build Internal-facing build tooling & test updates ci:daily Run the CI jobs that normally run in the daily job. labels Sep 18, 2025
@nx-cloud
Copy link

nx-cloud bot commented Sep 18, 2025

View your CI Pipeline Execution ↗ for commit a530612

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 51s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-18 16:27:47 UTC

@ndelangen ndelangen changed the title Refactor FormComponent to use Angular signals and standalone module. Update form validation and success handling logic. Sandbox: Angular template fix form component Sep 18, 2025
@ndelangen ndelangen self-assigned this Sep 18, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
code/frameworks/angular/template/components/form.component.ts (4)

5-6: Standalone conversion looks good; add OnPush for perf and consistency.

Signals work well with OnPush and reduce accidental change detection.

Apply:

 @Component({
   standalone: true,
   imports: [FormsModule],
+  changeDetection: ChangeDetectionStrategy.OnPush,

And add import (outside this hunk):

import { ChangeDetectionStrategy } from '@angular/core';

Also ensure stories use moduleMetadata({ imports: [FormComponent] }) (not declarations) after the standalone switch.


9-9: Prefer (ngSubmit) over (submit) with template‑driven forms.

It integrates with ngForm validity and mirrors Angular conventions.

-    <form id="interaction-test-form" ngNativeValidate (submit)="handleSubmit($event)">
+    <form id="interaction-test-form" ngNativeValidate (ngSubmit)="handleSubmit($event)">

15-17: A11y: announce completion to assistive tech.

Expose the status change for screen readers.

-    <p>Completed!!</p>
+    <p role="status" aria-live="polite">Completed!!</p>

29-38: Avoid race/flicker on rapid submits; clear timers and clean up on destroy.

Multiple quick submits schedule overlapping timeouts, causing inconsistent complete state and minor leaks.

Apply within this method:

   handleSubmit(event: SubmitEvent) {
     event.preventDefault();
     this.onSuccess.emit(this.value);
-    setTimeout(() => {
-      this.complete.set(true);
-    }, 500);
-    setTimeout(() => {
-      this.complete.set(false);
-    }, 1500);
+    this.clearTimers();
+    this.complete.set(false);
+    this.showTimer = setTimeout(() => {
+      this.complete.set(true);
+    }, 500);
+    this.hideTimer = setTimeout(() => {
+      this.complete.set(false);
+    }, 1500);
   }

Add supporting members (outside this hunk):

// import { OnDestroy } from '@angular/core';
export default class FormComponent implements OnDestroy {
  private showTimer?: ReturnType<typeof setTimeout>;
  private hideTimer?: ReturnType<typeof setTimeout>;

  private clearTimers() {
    if (this.showTimer) clearTimeout(this.showTimer);
    if (this.hideTimer) clearTimeout(this.hideTimer);
    this.showTimer = this.hideTimer = undefined;
  }

  ngOnDestroy() {
    this.clearTimers();
  }
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8e4d83 and a530612.

📒 Files selected for processing (1)
  • code/frameworks/angular/template/components/form.component.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: daily
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (4)
code/frameworks/angular/template/components/form.component.ts (4)

12-12: LGTM: Added name for ngModel.

This unblocks [(ngModel)] binding.


27-27: LGTM: signal(false) with template read via complete() is correct.


23-23: Public API shift: EventEmitter → output() may break .subscribe call-sites

Ran the suggested search (rg -nP '\bonSuccess\s*.\s*subscribe\b|fixture.componentInstance.onSuccess\b' -C2) — no matches in the repo; absence of matches isn't proof. Confirm tests, other packages, and external consumers don't call component.onSuccess.subscribe. If they do, restore an EventEmitter or add an adapter (e.g., expose an Observable/subscribe wrapper or provide a test helper).


1-2: Versions verified — Angular 19 present; features supported.

code/frameworks/angular/package.json pins @angular/core, @angular/common, @angular/forms to ^19.1.1 (peer range >=18 <21) and @storybook/angular is workspace:* (local); Angular 19 includes signals, the new control‑flow syntax (@if/@for), and the output() API — no CI break expected. (angular.dev)

@ndelangen ndelangen merged commit 4c52fbf into next Sep 18, 2025
100 of 103 checks passed
@ndelangen ndelangen deleted the norbert/fix-angular-form-component branch September 18, 2025 16:38
@github-actions github-actions bot mentioned this pull request Sep 19, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:daily Run the CI jobs that normally run in the daily job.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants