Skip to content

fix: fixed navigation to the relevant input field#4026

Merged
JamalAlabdullah merged 7 commits intomainfrom
3967-navigasjon-via-feilmedlingslink-feiler-for-inputfelt-med-markdown-lister
Apr 17, 2026
Merged

fix: fixed navigation to the relevant input field#4026
JamalAlabdullah merged 7 commits intomainfrom
3967-navigasjon-via-feilmedlingslink-feiler-for-inputfelt-med-markdown-lister

Conversation

@JamalAlabdullah
Copy link
Copy Markdown
Contributor

@JamalAlabdullah JamalAlabdullah commented Feb 27, 2026

Description

Related Issue(s)

Screen.Recording.2026-02-27.at.12.40.44.mov

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard focus behavior: broader detection of focusable elements (buttons, tabindex, contenteditable), returns no focus for empty containers, honors an optional binding preference, and applies a clear fallback order (preferred binding → first input-like → first available).
  • Tests
    • Added comprehensive tests covering focus selection scenarios and fallback paths.

@JamalAlabdullah JamalAlabdullah added kind/bug Something isn't working backport This PR should be cherry-picked onto older release branches labels Feb 27, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 386455b5-307b-4e80-9e39-04949593652f

📥 Commits

Reviewing files that changed from the base of the PR and between bbfabfd and 01288a3.

📒 Files selected for processing (1)
  • src/layout/GenericComponent.tsx

📝 Walkthrough

Walkthrough

Exports new function findElementToFocus from src/layout/GenericComponent.tsx. It returns undefined for null container or when no focusable targets exist, expands candidate selectors (adds button, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]), and alters binding-prioritization and fallback ordering.

Changes

Cohort / File(s) Summary
Core logic & export
src/layout/GenericComponent.tsx
Added and exported `findElementToFocus(div: HTMLElement, bindingKey: string
Tests
src/layout/GenericComponent.test.tsx
Added tests exercising findElementToFocus: no-focusable elements, preference for `input

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing navigation to input fields, which directly addresses the linked issue about error message link navigation failures.
Description check ✅ Passed The PR description follows the template with Related Issue, Verification/QA sections completed. Manual testing, accessibility checks, and label checks are marked as done.
Linked Issues check ✅ Passed The code changes (expanding focusable element selectors, adding binding-aware search, prioritizing input elements) directly address issue #3967's requirement to fix navigation to input fields with Markdown list descriptions.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the focus navigation logic for input fields, staying within the scope of issue #3967. The findElementToFocus export and its new logic directly serve this purpose.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 3967-navigasjon-via-feilmedlingslink-feiler-for-inputfelt-med-markdown-lister

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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.

@JamalAlabdullah JamalAlabdullah added the squad/utforming Issues that belongs to the named squad. label Feb 27, 2026
@JamalAlabdullah JamalAlabdullah moved this to 🔎 In review in Team Altinn Studio Feb 27, 2026
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
src/layout/GenericComponent.tsx (1)

274-289: Consider filtering non-interactive candidates before fallback focus.

If fallback selects a disabled/hidden/inert element, focus can silently fail even though a valid input exists later in the list.

Suggested hardening
   const targetElements = Array.from(
     div.querySelectorAll<HTMLElement>(
       ['input', 'textarea', 'select', 'button', '[tabindex]:not([tabindex="-1"])', '[contenteditable="true"]'].join(
         ',',
       ),
     ),
-  );
+  ).filter(
+    (element) =>
+      !element.matches(':disabled, [hidden], [aria-hidden="true"], [inert], input[type="hidden"]'),
+  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/layout/GenericComponent.tsx` around lines 274 - 289, The current focus
fallback can pick non-interactive elements; update the selection to filter out
disabled/hidden/inert/non-visible candidates before choosing a fallback: after
building targetElements (from querySelectorAll), run a filter that removes
elements with hidden attribute, aria-hidden="true", inert attribute,
style.display === 'none' or style.visibility === 'hidden' or
getClientRects().length === 0 (or offsetParent === null for robustness), and for
form controls check the disabled property; keep the binding lookup
(elementWithBinding) using the same dataset.bindingkey check but apply the same
filter so the returned element (elementWithBinding ?? first) is guaranteed
interactive. Ensure you still return undefined when no interactive candidates
remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/layout/GenericComponent.tsx`:
- Around line 274-289: The current focus fallback can pick non-interactive
elements; update the selection to filter out disabled/hidden/inert/non-visible
candidates before choosing a fallback: after building targetElements (from
querySelectorAll), run a filter that removes elements with hidden attribute,
aria-hidden="true", inert attribute, style.display === 'none' or
style.visibility === 'hidden' or getClientRects().length === 0 (or offsetParent
=== null for robustness), and for form controls check the disabled property;
keep the binding lookup (elementWithBinding) using the same dataset.bindingkey
check but apply the same filter so the returned element (elementWithBinding ??
first) is guaranteed interactive. Ensure you still return undefined when no
interactive candidates remain.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce114bd and fd1fd48.

📒 Files selected for processing (1)
  • src/layout/GenericComponent.tsx

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
src/layout/GenericComponent.test.tsx (1)

78-136: Add one regression test for the real error-link flow (markdown list + intro text).

These helper tests are strong, but they don’t directly cover the bug’s full path (clicking error message link and focusing the target input when description has leading text + markdown list). Please add one component-level regression test for that interaction.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/layout/GenericComponent.test.tsx` around lines 78 - 136, Add a
component-level regression test that renders GenericComponent (or the component
that uses findElementToFocus) with an error message containing leading intro
text plus a markdown list (e.g., "Intro text\n\n- item") and an error link that
targets a field by data-bindingkey; use the existing test helpers
(createContainer or test renderer) to render the DOM, simulate a user click on
the error link (fireEvent.click or userEvent.click), then assert that the
input/textarea with the matching data-bindingkey receives focus
(expect(document.activeElement).toBe(targetElement) or
expect(targetElement).toHaveFocus()). Ensure the test exercises the same code
path as findElementToFocus so it verifies focusing works when the description
contains both intro text and a markdown list.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/layout/GenericComponent.test.tsx`:
- Around line 78-136: Add a component-level regression test that renders
GenericComponent (or the component that uses findElementToFocus) with an error
message containing leading intro text plus a markdown list (e.g., "Intro
text\n\n- item") and an error link that targets a field by data-bindingkey; use
the existing test helpers (createContainer or test renderer) to render the DOM,
simulate a user click on the error link (fireEvent.click or userEvent.click),
then assert that the input/textarea with the matching data-bindingkey receives
focus (expect(document.activeElement).toBe(targetElement) or
expect(targetElement).toHaveFocus()). Ensure the test exercises the same code
path as findElementToFocus so it verifies focusing works when the description
contains both intro text and a markdown list.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b32282f and bbfabfd.

📒 Files selected for processing (2)
  • src/layout/GenericComponent.test.tsx
  • src/layout/GenericComponent.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/layout/GenericComponent.tsx

…eilmedlingslink-feiler-for-inputfelt-med-markdown-lister
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

@walldenfilippa walldenfilippa left a comment

Choose a reason for hiding this comment

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

Nice job! I left a minor nitpick :)

Comment thread src/layout/GenericComponent.tsx Outdated
@sonarqubecloud
Copy link
Copy Markdown

@JamalAlabdullah JamalAlabdullah merged commit 84ff8ff into main Apr 17, 2026
16 checks passed
@JamalAlabdullah JamalAlabdullah deleted the 3967-navigasjon-via-feilmedlingslink-feiler-for-inputfelt-med-markdown-lister branch April 17, 2026 13:33
@github-project-automation github-project-automation bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Apr 17, 2026
github-actions bot pushed a commit that referenced this pull request Apr 17, 2026
* fix: fixed navigation to the relevant input field

* refactor

* refactor

* added tests

* refactor
@github-actions
Copy link
Copy Markdown
Contributor

Automatic backport successful!

A backport PR has been automatically created for the release/v4.27 release branch.

The release branch release/v4.27 already existed and was updated.

The cherry-pick was clean with no conflicts. Please review the backport PR when it appears.

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

Labels

backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working squad/utforming Issues that belongs to the named squad.

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Navigasjon via feilmedlingslink feiler for inputfelt med markdown-lister

2 participants