Skip to content

Fix label for attribute when not scoped to model#3696

Merged
jonrohan merged 3 commits into
primer:mainfrom
opf:fix/label-for-not-scoped-to-model
Jun 25, 2026
Merged

Fix label for attribute when not scoped to model#3696
jonrohan merged 3 commits into
primer:mainfrom
opf:fix/label-for-not-scoped-to-model

Conversation

@myabc

@myabc myabc commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

What are you trying to accomplish?

Defers assigning label for value to later in initialize method, ensuring the scope_id_false: false option is respected.

Integration

It may require updating calling code that relies on the incorrect behavior.

List the issues that this change affects.

Closes #3695

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Copilot AI review requested due to automatic review settings September 24, 2025 18:14
@myabc myabc requested a review from a team as a code owner September 24, 2025 18:14
@myabc myabc requested a review from siddharthkp September 24, 2025 18:14
@changeset-bot

changeset-bot Bot commented Sep 24, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a06e61

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the label for attribute assignment when the scope_id_false: false option is used. The fix ensures that the label's for attribute is properly set to match the input's ID after the ID has been finalized during initialization.

Key changes:

  • Moved label for attribute assignment to later in the initialization process
  • Added test coverage for the fixed behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/lib/primer/forms/dsl/input.rb Moves the @label_arguments[:for] = id assignment from early initialization to after ID processing is complete
test/lib/primer/forms/input_test.rb Adds test assertions to verify label for attributes are correctly set in existing test cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread app/lib/primer/forms/dsl/input.rb Outdated
@myabc myabc force-pushed the fix/label-for-not-scoped-to-model branch from 9130190 to 7b26e33 Compare September 24, 2025 18:18
myabc added a commit to opf/openproject that referenced this pull request Sep 24, 2025
This requires an upstream fix. However, given the potential to cause
accessibility problems and broken UX (e.g. focus), we should track the
current and desired/fixed behavior downstream.

See primer/view_components#3696
See primer/view_components#3695
@myabc myabc requested a review from Copilot September 24, 2025 19:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@siddharthkp siddharthkp requested review from jonrohan and removed request for siddharthkp September 24, 2025 21:30
@siddharthkp

Copy link
Copy Markdown
Member

Passing over to @jonrohan who would know more about this than me

@myabc

myabc commented Sep 24, 2025

Copy link
Copy Markdown
Contributor Author

Just a quick note: I've kept this PR narrow in scope (forgive the pun) and tried to solve this in the "least invasive" way possible. However, there are other issues (such as namespacing - see #3698) for which I'm trying to find a more robust solution.

myabc added a commit to opf/openproject that referenced this pull request Sep 25, 2025
This requires an upstream fix. However, given the potential to cause
accessibility problems and broken UX (e.g. focus), we should track the
current and desired/fixed behavior downstream.

See primer/view_components#3696
See primer/view_components#3695
@github-actions

Copy link
Copy Markdown
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions Bot added the Stale Automatically marked as stale. label Nov 23, 2025
@input_arguments = system_arguments
@input_arguments.delete(:id) unless @input_arguments[:id].present?
@label_arguments = @input_arguments.delete(:label_arguments) || {}
@label_arguments[:for] = id if id.present?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was calling def id below which is the same as @input_arguments[:id] curious how this is different than what was already in place

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jonrohan sorry for only just getting back to you. The order here is important. We should defer setting @label_arguments[:for] until after these lines, which can mutate @input_arguments[:id]:

          unless @input_arguments.delete(:scope_id_to_model) { true }
            @input_arguments[:id] = @input_arguments.delete(:id) { name }
          end

@github-actions

Copy link
Copy Markdown
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions Bot added the Stale Automatically marked as stale. label Apr 13, 2026
@github-actions github-actions Bot closed this Apr 20, 2026
@jonrohan jonrohan reopened this Jun 16, 2026
@github-actions github-actions Bot removed the Stale Automatically marked as stale. label Jun 16, 2026
Defers assigning label `for` value to later in `initialize` method,
ensuring the `scope_id_false: false` option is respected.

Closes primer#3695
@myabc myabc force-pushed the fix/label-for-not-scoped-to-model branch from b6b4909 to e843dd2 Compare June 20, 2026 18:39
@myabc myabc requested a review from jonrohan June 20, 2026 18:47
myabc added 2 commits June 20, 2026 20:49
Setting `for: nil` made Rails skip generating the scoped id, dropping
the label association on the default model-scoped path. Sets `for` only
when the input id is present, restoring Rails autogeneration otherwise.
Adds a default-scope regression test and corrects the changeset to name
the real `scope_id_to_model` option.
@myabc myabc force-pushed the fix/label-for-not-scoped-to-model branch from 571d5dc to 4a06e61 Compare June 20, 2026 18:49
@myabc

myabc commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

@jonrohan took a moment to revisit this. Unfortunately my solution was missing a if @input_arguments[:id].present? guard (which could have caused another regression). Fixed in 4a06e61

@jonrohan jonrohan merged commit 8b8d542 into primer:main Jun 25, 2026
24 of 26 checks passed
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.

Label for attribute incorrect when scope_id_false: false

4 participants