Skip to content

Conversation

hakanduranC
Copy link

@hakanduranC hakanduranC commented Oct 13, 2025

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the principle of data economy for all client-server REST calls.
  • I strictly followed the client coding and design guidelines.
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

Fixes #9641 - Issue where pressing Enter key in form input fields or Apollon Editor unexpectedly opens the help modal instead of providing normal field navigation behavior.

Root Cause: HTML forms without explicit submit buttons automatically trigger the first <button> element when Enter is pressed. The modeling exercise form's first button was the help button, causing unwanted modal activation.

Description

Implemented hidden submit button solution that intercepts Enter key events and provides appropriate navigation behavior:

  • Form inputs: Enter key moves focus to next input field (Tab-like behavior)
  • Apollon Editor: Enter key works normally, respecting component boundaries
  • Help modal: Only opens when explicitly clicked by user

Technical Implementation:

  • Added hidden submit button to modeling-exercise-update.component.html
  • Added handleEnterKeyNavigation() method with smart component boundary detection
  • Preserves all existing functionality (form validation, Angular directives, etc.)

Files Changed:

  • modeling-exercise-update.component.html: Added hidden submit button
  • modeling-exercise-update.component.ts: Added Enter key navigation logic

Steps for Testing

Prerequisites:

  • 1 Instructor account
  • 1 Course with modeling exercise capability
  1. Login to Artemis
  2. Navigate to Course Management > Exercises > Create New Modeling Exercise
  3. Form Input Test:
    • Press Enter in various input fields (exercise title, points, description, dates)
    • Expected: Focus moves to next field smoothly, no help modal appears
    • Before fix: Help modal would open unexpectedly
  4. Apollon Editor Test:
    • Click inside the UML diagram editor area
    • Press Enter key while focused in Apollon
    • Expected: Apollon handles Enter normally for its internal functionality
    • Before fix: Help modal would open, disrupting UML editing workflow
  5. Help Button Test:
    • Click the help button (?) manually with mouse
    • Expected: Help modal opens normally as intended
  6. Form Validation Test:
    • Leave required fields empty and try to save
    • Expected: Validation errors appear normally
  7. Save Functionality Test:
    • Complete the form properly and click Save
    • Expected: Exercise saves successfully

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Screenshots

2025-08-27.10-55-07.mp4

Summary by CodeRabbit

  • New Features

    • Improved keyboard navigation in the Modeling Exercise update form: pressing Enter advances to the next relevant field, skipping textareas and non-interactive elements for smoother data entry.
  • Bug Fixes

    • Prevented accidental form submission from the Help button by ensuring it does not act as a submit control.
    • Reduced unintended submissions when using Enter during form navigation, improving form stability.
  • Tests

    • Added tests covering Enter-key navigation scenarios and edge cases.

@hakanduranC hakanduranC self-assigned this Oct 13, 2025
@hakanduranC hakanduranC requested a review from a team as a code owner October 13, 2025 16:40
@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Oct 13, 2025
@github-actions github-actions bot added client Pull requests that update TypeScript code. (Added Automatically!) modeling Pull requests that affect the corresponding module labels Oct 13, 2025
Copy link
Contributor

coderabbitai bot commented Oct 13, 2025

Walkthrough

Adds Enter-key navigation handling to the modeling exercise update form via a hidden submit button and a new handler that advances focus while skipping textareas, contenteditable regions, Apollon editor container, and disabled/hidden fields. Also sets the modeling editor help button to type="button" to prevent accidental form submit.

Changes

Cohort / File(s) Summary
Modeling Exercise Update: form submit + navigation
src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.html, src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.ts, src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.spec.ts
HTML: adds a hidden submit button bound to handleEnterKeyNavigation($event). TS: imports ElementRef; adds @ViewChild('editForm', { read: ElementRef }) editFormEl?; implements handleEnterKeyNavigation(event) to prevent default submit, skip TEXTAREA, contentEditable, Apollon container, disabled/hidden elements, and move focus to the next focusable element. Spec: adds tests covering key prevention, skip cases, Apollon container, next-focus behavior, and early-return when form ref missing.
Modeling Editor: help button semantics
src/main/webapp/app/modeling/shared/modeling-editor/modeling-editor.component.html
Sets the help button element to type="button" to ensure it does not act as a form submit control.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Form as Update Form
  participant Comp as ModelingExerciseUpdateComponent
  participant DOM as Focusable Elements

  User->>Form: Press Enter
  Note over Form,Comp: Hidden submit button receives Enter
  Form->>Comp: handleEnterKeyNavigation(event)
  alt Focus in TEXTAREA / contentEditable / Apollon
    Comp-->>Form: Prevent default, stop propagation, do nothing
  else Focus in standard input/select/button
    Comp->>DOM: Find next enabled, visible, focusable element
    DOM-->>Comp: Next element or none
    alt Next element found
      Comp->>DOM: Focus next element (prevent form submit)
    else No next element
      Comp-->>Form: Allow default behavior or stay (no focus change)
    end
  end
Loading
sequenceDiagram
  participant User
  participant Editor as Modeling Editor Template
  participant HelpBtn as Help Button (type="button")

  User->>HelpBtn: Click / Enter
  HelpBtn-->>Editor: Trigger help action only (no form submit)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The changes directly address the linked issue by intercepting Enter key events to move focus between form inputs without opening the help modal and by explicitly ignoring contenteditable and Apollon Editor fields so that Enter still commits input locally, and the new tests verify all specified navigation scenarios required by issue #9641.
Out of Scope Changes Check ✅ Passed All changes are directly related to fixing Enter key behavior by adding the hidden submit button, navigation handler, updated tests, and ensuring the help button has an explicit non-submit type, and there are no unrelated modifications outside the scope of issue #9641.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change—fixing Enter key navigation in modeling exercise forms—using language that directly reflects the issue and context described in the PR without introducing unnecessary detail or noise.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/modeling/fix-enter-form-navigation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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 (1)
src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.ts (1)

298-327: LGTM! Navigation logic correctly implements Enter-as-Tab behavior.

The method properly:

  • Prevents form submission via preventDefault() and stopPropagation()
  • Preserves default Enter behavior in textareas and contentEditable regions
  • Respects Apollon editor's internal input handling
  • Advances focus to the next form control for standard inputs/selects

Optional: Consider a template literal for improved readability.

The focusable elements selector could use a template literal instead of string concatenation:

-        const focusableElements = Array.from(
-            formRoot.querySelectorAll(
-                'input:not([disabled]):not([readonly]):not([tabindex="-1"]):not([hidden]):not([type="hidden"]), ' + 'select:not([disabled]):not([tabindex="-1"]):not([hidden])',
-            ),
-        ) as HTMLElement[];
+        const focusableElements = Array.from(
+            formRoot.querySelectorAll(
+                `input:not([disabled]):not([readonly]):not([tabindex="-1"]):not([hidden]):not([type="hidden"]),
+                 select:not([disabled]):not([tabindex="-1"]):not([hidden])`,
+            ),
+        ) as HTMLElement[];

As per coding guidelines: Single quotes are preferred for strings, but template literals improve readability for multi-line selectors.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between abd58e5 and 1cba8d0.

📒 Files selected for processing (3)
  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.html (1 hunks)
  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.ts (3 hunks)
  • src/main/webapp/app/modeling/shared/modeling-editor/modeling-editor.component.html (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/**/*.html

⚙️ CodeRabbit configuration file

@if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

Files:

  • src/main/webapp/app/modeling/shared/modeling-editor/modeling-editor.component.html
  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.html
src/main/webapp/**/*.ts

⚙️ CodeRabbit configuration file

angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

Files:

  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.ts
⏰ 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). (9)
  • GitHub Check: Build and Push Docker Image / Build linux/arm64 Docker Image for ls1intum/artemis
  • GitHub Check: Build and Push Docker Image / Build linux/amd64 Docker Image for ls1intum/artemis
  • GitHub Check: client-style
  • GitHub Check: Build .war artifact
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (4)
src/main/webapp/app/modeling/shared/modeling-editor/modeling-editor.component.html (1)

72-72: LGTM! Correct fix to prevent unintended form submission.

Adding type="button" ensures this help button won't be triggered when Enter is pressed in form inputs. This directly addresses the root cause described in the PR objectives where the first <button> without an explicit type was being activated on Enter.

src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.ts (2)

1-1: LGTM! Necessary import for form element access.

The ElementRef import is correctly added to support the new editFormEl ViewChild that enables keyboard navigation logic.


98-98: LGTM! ViewChild correctly configured for form element access.

The ViewChild declaration properly uses read: ElementRef to obtain a reference to the native form element, which is necessary for querying focusable elements within the form.

src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.html (1)

2-2: LGTM! Hidden submit button correctly enables Enter-key navigation.

The hidden submit button with type="submit" ensures the browser triggers this button (and its click handler) when Enter is pressed in form inputs, rather than the first visible button. The implementation correctly integrates with the handleEnterKeyNavigation method to provide Tab-like navigation behavior.

The use of style="display: none" is appropriate here as it's more robust than alternatives like [hidden] which can be overridden by CSS.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 13, 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 (1)
src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.spec.ts (1)

353-502: Solid test coverage for Enter key navigation, with minor improvements suggested.

The new test suite comprehensively covers the key scenarios for handleEnterKeyNavigation. The structure and mocking approach are sound.

Consider these optional refinements:

  1. Protect DOM cleanup with try-finally blocks (lines 372-386, 388-403):
 it('should not navigate when focused on TEXTAREA', () => {
     const textarea = document.createElement('textarea');
-    document.body.appendChild(textarea);
-    textarea.focus();
-
-    const mockEvent = {
-        preventDefault: jest.fn(),
-        stopPropagation: jest.fn(),
-    } as any as Event;
-
-    comp.handleEnterKeyNavigation(mockEvent);
-
-    expect(mockEvent.preventDefault).toHaveBeenCalledOnce();
-    document.body.removeChild(textarea);
+    try {
+        document.body.appendChild(textarea);
+        textarea.focus();
+
+        const mockEvent = {
+            preventDefault: jest.fn(),
+            stopPropagation: jest.fn(),
+        } as any as Event;
+
+        comp.handleEnterKeyNavigation(mockEvent);
+
+        expect(mockEvent.preventDefault).toHaveBeenCalledOnce();
+    } finally {
+        document.body.removeChild(textarea);
+    }
 });

Apply similar pattern to the contentEditable test (lines 388-403).

  1. Strengthen assertions for skip scenarios (lines 372-445):

    • Currently, tests only verify preventDefault was called
    • Add assertions to confirm focus did not change, e.g., expect(document.activeElement).toBe(textarea);
  2. Verify focus remains on last element (lines 476-502):

    • Add expect(document.activeElement).toBe(input2); to confirm no unintended focus change occurred
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cba8d0 and b0c4724.

📒 Files selected for processing (1)
  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/**/*.ts

⚙️ CodeRabbit configuration file

angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

Files:

  • src/main/webapp/app/modeling/manage/update/modeling-exercise-update.component.spec.ts
⏰ 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). (8)
  • GitHub Check: Build and Push Docker Image / Build linux/arm64 Docker Image for ls1intum/artemis
  • GitHub Check: Build and Push Docker Image / Build linux/amd64 Docker Image for ls1intum/artemis
  • GitHub Check: Build .war artifact
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: client-style
  • GitHub Check: client-tests
  • GitHub Check: Analyse

@hakanduranC hakanduranC moved this from Work In Progress to Ready For Review in Artemis Development Oct 13, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 641ms
TestResultTime ⏱
No test annotations available

@hakanduranC

This comment was marked as off-topic.

@hakanduranC
Copy link
Author

hakanduranC commented Oct 13, 2025

Closed by mistake

@hakanduranC hakanduranC reopened this Oct 13, 2025
@github-project-automation github-project-automation bot moved this from Ready For Review to Work In Progress in Artemis Development Oct 13, 2025
@hakanduranC hakanduranC changed the title Modeling exercises: Fix Enter key navigation in exercise forms Modeling exercises: Fix Enter key navigation in exercise forms Oct 13, 2025
@hakanduranC hakanduranC moved this from Work In Progress to Ready For Review in Artemis Development Oct 13, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 547ms
TestResultTime ⏱
No test annotations available

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 544ms
TestResultTime ⏱
No test annotations available

@hakanduranC hakanduranC requested a review from Anishyou October 14, 2025 15:22
Copy link

@toukhi toukhi left a comment

Choose a reason for hiding this comment

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

Code looks good to me. Tested locally and works as described.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client Pull requests that update TypeScript code. (Added Automatically!) modeling Pull requests that affect the corresponding module ready for review

Projects

Status: Ready For Review

Development

Successfully merging this pull request may close these issues.

Pressing Enter in Apollon Editor Input Fields Opens Help Modal Instead of Submitting Changes

2 participants